class Migration(migrations.Migration): dependencies = [ ('main', '0079_v360_rm_implicit_oauth2_apps'), ] operations = [ migrations.RunPython( migrations.RunPython.noop, lambda apps, schema_editor: set_current_apps(apps)), migrations.RemoveField( model_name='joborigin', name='instance', ), migrations.RemoveField( model_name='joborigin', name='unified_job', ), migrations.AddField( model_name='activitystream', name='action_node', field=models.CharField( blank=True, default='', editable=False, help_text='The cluster node the activity took place on.', max_length=512), ), migrations.DeleteModel(name='JobOrigin', ), migrations.RunPython( lambda apps, schema_editor: set_current_apps(apps), migrations.RunPython.noop) ]
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() if ct: ct.credentials.all().delete() ct.delete()
def delete_hg_scm(apps, schema_editor): set_current_apps(apps) Project = apps.get_model('main', 'Project') ProjectUpdate = apps.get_model('main', 'ProjectUpdate') ProjectUpdate.objects.filter(project__scm_type='hg').update(scm_type='') update_ct = Project.objects.filter(scm_type='hg').update(scm_type='') if update_ct: logger.warning( 'Changed {} mercurial projects to manual, deprecation period ended' .format(update_ct))
def delete_hg_scm(apps, schema_editor): set_current_apps(apps) Project = apps.get_model('main', 'Project') ProjectUpdate = apps.get_model('main', 'ProjectUpdate') ProjectUpdate.objects.filter(project__scm_type='hg').delete() deleted_ct, deletion_summary = Project.objects.filter( scm_type='hg').delete() if deleted_ct: logger.warn( 'Removed {} mercurial projects, deprecation period ended'.format( deletion_summary.get('main.Project', '')))
def delete_custom_inv_source(apps, schema_editor): set_current_apps(apps) InventorySource = apps.get_model('main', 'InventorySource') InventoryUpdate = apps.get_model('main', 'InventoryUpdate') ct, deletions = InventoryUpdate.objects.filter(source='custom').delete() if ct: logger.info('deleted {}'.format((ct, deletions))) update_ct = deletions['main.InventoryUpdate'] if update_ct: logger.info('Deleted {} custom inventory script sources.'.format(update_ct)) ct, deletions = InventorySource.objects.filter(source='custom').delete() if ct: logger.info('deleted {}'.format((ct, deletions))) src_ct = deletions['main.InventorySource'] if src_ct: logger.info('Deleted {} custom inventory script updates.'.format(src_ct)) logger.warning('Custom inventory scripts have been removed, see awx-manage export_custom_scripts')
def setup_tower_managed_defaults(apps, schema_editor): set_current_apps(apps) CredentialType.setup_tower_managed_defaults()
def migrate_galaxy_settings(apps, schema_editor): Organization = apps.get_model('main', 'Organization') if Organization.objects.count() == 0: # nothing to migrate return set_current_apps(apps) ModernCredentialType.setup_tower_managed_defaults(apps) CredentialType = apps.get_model('main', 'CredentialType') Credential = apps.get_model('main', 'Credential') Setting = apps.get_model('conf', 'Setting') galaxy_type = CredentialType.objects.get(kind='galaxy') private_galaxy_url = Setting.objects.filter( key='PRIMARY_GALAXY_URL').first() # by default, prior versions of AWX automatically pulled content # from galaxy.ansible.com public_galaxy_enabled = True public_galaxy_setting = Setting.objects.filter( key='PUBLIC_GALAXY_ENABLED').first() if public_galaxy_setting and public_galaxy_setting.value is False: # ...UNLESS this behavior was explicitly disabled via this setting public_galaxy_enabled = False try: # Needed for old migrations public_galaxy_credential = Credential( created=now(), modified=now(), name='Ansible Galaxy', managed_by_tower=True, credential_type=galaxy_type, inputs={'url': 'https://galaxy.ansible.com/'}, ) except: # Needed for new migrations, tests public_galaxy_credential = Credential( created=now(), modified=now(), name='Ansible Galaxy', managed=True, credential_type=galaxy_type, inputs={'url': 'https://galaxy.ansible.com/'}) public_galaxy_credential.save() for org in Organization.objects.all(): if private_galaxy_url and private_galaxy_url.value: # If a setting exists for a private Galaxy URL, make a credential for it username = Setting.objects.filter( key='PRIMARY_GALAXY_USERNAME').first() password = Setting.objects.filter( key='PRIMARY_GALAXY_PASSWORD').first() if (username and username.value) or (password and password.value): logger.error( f'Specifying HTTP basic auth for the Ansible Galaxy API ' f'({private_galaxy_url.value}) is no longer supported. ' 'Please provide an API token instead after your upgrade ' 'has completed', ) inputs = {'url': private_galaxy_url.value} token = Setting.objects.filter(key='PRIMARY_GALAXY_TOKEN').first() if token and token.value: inputs['token'] = decrypt_field(token, 'value') auth_url = Setting.objects.filter( key='PRIMARY_GALAXY_AUTH_URL').first() if auth_url and auth_url.value: inputs['auth_url'] = auth_url.value name = f'Private Galaxy ({private_galaxy_url.value})' if 'cloud.redhat.com' in inputs['url']: name = f'Ansible Automation Hub ({private_galaxy_url.value})' cred = Credential(created=now(), modified=now(), name=name, organization=org, credential_type=galaxy_type, inputs=inputs) cred.save() if token and token.value: # encrypt based on the primary key from the prior save cred.inputs['token'] = encrypt_field(cred, 'token') cred.save() org.galaxy_credentials.add(cred) fallback_servers = getattr(settings, 'FALLBACK_GALAXY_SERVERS', []) for fallback in fallback_servers: url = fallback.get('url', None) auth_url = fallback.get('auth_url', None) username = fallback.get('username', None) password = fallback.get('password', None) token = fallback.get('token', None) if username or password: logger.error( f'Specifying HTTP basic auth for the Ansible Galaxy API ' f'({url}) is no longer supported. ' 'Please provide an API token instead after your upgrade ' 'has completed', ) inputs = {'url': url} if token: inputs['token'] = token if auth_url: inputs['auth_url'] = auth_url cred = Credential(created=now(), modified=now(), name=f'Ansible Galaxy ({url})', organization=org, credential_type=galaxy_type, inputs=inputs) cred.save() if token: # encrypt based on the primary key from the prior save cred.inputs['token'] = encrypt_field(cred, 'token') cred.save() org.galaxy_credentials.add(cred) if public_galaxy_enabled: # If public Galaxy was enabled, associate it to the org org.galaxy_credentials.add(public_galaxy_credential)
def migrate_to_static_inputs(apps, schema_editor): set_current_apps(apps) CredentialType.setup_tower_managed_defaults()
def create_new_credential_types(apps, schema_editor): set_current_apps(apps) CredentialType.setup_tower_managed_defaults()