From 0b701b3b241d1387de87e037e30c777c39a9f572 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Thu, 5 Nov 2020 07:47:28 -0500 Subject: [PATCH] entirely remove CloudForms inventory sources instead of converting --- .../0117_v400_remove_cloudforms_inventory.py | 16 +++++-- awx/main/migrations/_inventory_source.py | 42 ------------------- awx/main/models/credential/__init__.py | 27 ------------ 3 files changed, 12 insertions(+), 73 deletions(-) diff --git a/awx/main/migrations/0117_v400_remove_cloudforms_inventory.py b/awx/main/migrations/0117_v400_remove_cloudforms_inventory.py index 8c3331875535..fafd85e05b19 100644 --- a/awx/main/migrations/0117_v400_remove_cloudforms_inventory.py +++ b/awx/main/migrations/0117_v400_remove_cloudforms_inventory.py @@ -1,11 +1,19 @@ # Generated by Django 2.2.11 on 2020-05-01 13:25 from django.db import migrations, models -from awx.main.migrations._inventory_source import create_scm_script_substitute +from awx.main.utils.common import set_current_apps -def convert_cloudforms_to_scm(apps, schema_editor): - create_scm_script_substitute(apps, 'cloudforms') +def delete_cloudforms_inv_source(apps, schema_editor): + set_current_apps(apps) + InventorySource = apps.get_model('main', 'InventorySource') + InventoryUpdate = apps.get_model('main', 'InventoryUpdate') + CredentialType = apps.get_model('main', 'CredentialType') + InventoryUpdate.objects.filter(inventory_source__source='cloudforms').delete() + InventorySource.objects.filter(source='cloudforms').delete() + ct = CredentialType.objects.filter(namespace='cloudforms').first() + ct.credentials.all().delete() + ct.delete() class Migration(migrations.Migration): @@ -15,7 +23,7 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(convert_cloudforms_to_scm), + migrations.RunPython(delete_cloudforms_inv_source), migrations.AlterField( model_name='inventorysource', name='source', diff --git a/awx/main/migrations/_inventory_source.py b/awx/main/migrations/_inventory_source.py index ed796065877b..d5107d66b22e 100644 --- a/awx/main/migrations/_inventory_source.py +++ b/awx/main/migrations/_inventory_source.py @@ -89,45 +89,3 @@ def back_out_new_instance_id(apps, source, new_id): logger.info('Reverse migrated instance ID for {} hosts imported by {} source'.format( modified_ct, source )) - - -def create_scm_script_substitute(apps, source): - """Only applies for cloudforms in practice, but written generally. - Given a source type, this will replace all inventory sources of that type - with SCM inventory sources that source the script from Ansible core - """ - # the revision in the Ansible 2.9 stable branch this project will start out as - # it can still be updated manually later (but staying within 2.9 branch), if desired - ansible_rev = '6f83b9aff42331e15c55a171de0a8b001208c18c' - InventorySource = apps.get_model('main', 'InventorySource') - ContentType = apps.get_model('contenttypes', 'ContentType') - Project = apps.get_model('main', 'Project') - if not InventorySource.objects.filter(source=source).exists(): - logger.debug('No sources of type {} to migrate'.format(source)) - return - proj_name = 'Replacement project for {} type sources - {}'.format(source, uuid4()) - right_now = now() - project = Project.objects.create( - name=proj_name, - created=right_now, - modified=right_now, - description='Created by migration', - polymorphic_ctype=ContentType.objects.get(model='project'), - # project-specific fields - scm_type='git', - scm_url='https://github.com/ansible/ansible.git', - scm_branch='stable-2.9', - scm_revision=ansible_rev - ) - ct = 0 - for inv_src in InventorySource.objects.filter(source=source).iterator(): - inv_src.source = 'scm' - inv_src.source_project = project - inv_src.source_path = 'contrib/inventory/{}.py'.format(source) - inv_src.scm_last_revision = ansible_rev - inv_src.save(update_fields=['source', 'source_project', 'source_path', 'scm_last_revision']) - logger.debug('Changed inventory source {} to scm type'.format(inv_src.pk)) - ct += 1 - if ct: - logger.info('Changed total of {} inventory sources from {} type to scm'.format(ct, source)) - diff --git a/awx/main/models/credential/__init__.py b/awx/main/models/credential/__init__.py index df12177aae93..66db962430d9 100644 --- a/awx/main/models/credential/__init__.py +++ b/awx/main/models/credential/__init__.py @@ -881,33 +881,6 @@ def create(self): } ) -ManagedCredentialType( - namespace='cloudforms', - kind='cloud', - name=ugettext_noop('Red Hat CloudForms'), - managed_by_tower=True, - inputs={ - 'fields': [{ - 'id': 'host', - 'label': ugettext_noop('CloudForms URL'), - 'type': 'string', - 'help_text': ugettext_noop('Enter the URL for the virtual machine that ' - 'corresponds to your CloudForms instance. ' - 'For example, https://cloudforms.example.org') - }, { - 'id': 'username', - 'label': ugettext_noop('Username'), - 'type': 'string' - }, { - 'id': 'password', - 'label': ugettext_noop('Password'), - 'type': 'string', - 'secret': True, - }], - 'required': ['host', 'username', 'password'], - } -) - ManagedCredentialType( namespace='gce', kind='cloud',