Skip to content

Commit

Permalink
entirely remove CloudForms inventory sources instead of converting
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpetrello committed Nov 6, 2020
1 parent b8f1fa1 commit 0b701b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 73 deletions.
16 changes: 12 additions & 4 deletions awx/main/migrations/0117_v400_remove_cloudforms_inventory.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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',
Expand Down
42 changes: 0 additions & 42 deletions awx/main/migrations/_inventory_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

27 changes: 0 additions & 27 deletions awx/main/models/credential/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 0b701b3

Please sign in to comment.