mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 18:37:39 -02:30
correctly create jobs in migrations
* Do not import Project. Instead, use get_model() and ensure the polymorphic ctype is set correctly. * Point migrated job templates at the new fact scan playbook
This commit is contained in:
@@ -1,24 +1,38 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from django.utils.timezone import now
|
||||||
|
from django.utils.text import slugify
|
||||||
|
|
||||||
from awx.main.models.base import PERM_INVENTORY_SCAN, PERM_INVENTORY_DEPLOY
|
from awx.main.models.base import PERM_INVENTORY_SCAN, PERM_INVENTORY_DEPLOY
|
||||||
|
from awx.main import utils
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.migrations')
|
logger = logging.getLogger('awx.main.migrations')
|
||||||
|
|
||||||
|
|
||||||
def _create_fact_scan_project(Project, org):
|
def _create_fact_scan_project(ContentType, Project, org):
|
||||||
|
ct = ContentType.objects.get_for_model(Project)
|
||||||
name = "Tower Fact Scan - {}".format(org.name if org else "No Organization")
|
name = "Tower Fact Scan - {}".format(org.name if org else "No Organization")
|
||||||
proj = Project(name=name,
|
proj = Project(name=name,
|
||||||
scm_url='https://github.com/ansible/tower-fact-modules',
|
scm_url='https://github.com/ansible/tower-fact-modules',
|
||||||
scm_type='git',
|
scm_type='git',
|
||||||
scm_update_on_launch=True,
|
scm_update_on_launch=True,
|
||||||
scm_update_cache_timeout=86400,
|
scm_update_cache_timeout=86400,
|
||||||
organization=org)
|
organization=org,
|
||||||
|
created=now(),
|
||||||
|
modified=now(),
|
||||||
|
polymorphic_ctype=ct)
|
||||||
|
proj.save()
|
||||||
|
|
||||||
|
slug_name = slugify(unicode(name)).replace(u'-', u'_')
|
||||||
|
proj.local_path = u'_%d__%s' % (int(proj.pk), slug_name)
|
||||||
|
|
||||||
proj.save()
|
proj.save()
|
||||||
return proj
|
return proj
|
||||||
|
|
||||||
|
|
||||||
def _create_fact_scan_projects(Project, orgs):
|
def _create_fact_scan_projects(ContentType, Project, orgs):
|
||||||
return {org.id : _create_fact_scan_project(Project, org) for org in orgs}
|
return {org.id : _create_fact_scan_project(ContentType, Project, org) for org in orgs}
|
||||||
|
|
||||||
|
|
||||||
def _get_tower_scan_job_templates(JobTemplate):
|
def _get_tower_scan_job_templates(JobTemplate):
|
||||||
@@ -31,9 +45,10 @@ def _get_orgs(Organization, job_template_ids):
|
|||||||
|
|
||||||
|
|
||||||
def _migrate_scan_job_templates(apps):
|
def _migrate_scan_job_templates(apps):
|
||||||
Organization = apps.get_model('main', 'Organization')
|
|
||||||
Project = apps.get_model('main', 'Project')
|
|
||||||
JobTemplate = apps.get_model('main', 'JobTemplate')
|
JobTemplate = apps.get_model('main', 'JobTemplate')
|
||||||
|
Organization = apps.get_model('main', 'Organization')
|
||||||
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||||
|
Project = apps.get_model('main', 'Project')
|
||||||
|
|
||||||
project_no_org = None
|
project_no_org = None
|
||||||
|
|
||||||
@@ -50,16 +65,17 @@ def _migrate_scan_job_templates(apps):
|
|||||||
if orgs.count() == 0:
|
if orgs.count() == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
org_proj_map = _create_fact_scan_projects(Project, orgs)
|
org_proj_map = _create_fact_scan_projects(ContentType, Project, orgs)
|
||||||
for jt in jts:
|
for jt in jts:
|
||||||
if jt.inventory and jt.inventory.organization:
|
if jt.inventory and jt.inventory.organization:
|
||||||
jt.project = org_proj_map[jt.inventory.organization.id]
|
jt.project_id = org_proj_map[jt.inventory.organization.id].id
|
||||||
# Job Templates without an Organization; through related Inventory
|
# Job Templates without an Organization; through related Inventory
|
||||||
else:
|
else:
|
||||||
if not project_no_org:
|
if not project_no_org:
|
||||||
project_no_org = _create_fact_scan_project(Project, None)
|
project_no_org = _create_fact_scan_project(ContentType, Project, None)
|
||||||
jt.project = project_no_org
|
jt.project_id = project_no_org.id
|
||||||
jt.job_type = PERM_INVENTORY_DEPLOY
|
jt.job_type = PERM_INVENTORY_DEPLOY
|
||||||
|
jt.playbook = "scan_facts.yml"
|
||||||
jt.use_fact_cache = True
|
jt.use_fact_cache = True
|
||||||
jt.save()
|
jt.save()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user