From 7278e7c02502eb2069617b856dcbc19bfe613b6f Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Mon, 27 Jul 2020 10:46:42 -0400 Subject: [PATCH] remove group_by from inventory source * Does not remove group_by testing --- awx/api/metadata.py | 6 --- awx/api/serializers.py | 2 +- .../migrations/0118_v380_inventory_plugins.py | 8 ++++ awx/main/models/inventory.py | 45 ------------------- .../plugins/modules/tower_inventory_source.py | 7 +-- .../test/awx/test_inventory_source.py | 1 - awxkit/awxkit/api/pages/inventory.py | 1 - 7 files changed, 10 insertions(+), 60 deletions(-) diff --git a/awx/api/metadata.py b/awx/api/metadata.py index 8bbfb906ef..0820902cd9 100644 --- a/awx/api/metadata.py +++ b/awx/api/metadata.py @@ -122,12 +122,6 @@ class Metadata(metadata.SimpleMetadata): get_regions = getattr(InventorySource, 'get_%s_region_choices' % cp) field_info['%s_region_choices' % cp] = get_regions() - # Special handling of group_by choices for EC2. - if field.field_name == 'group_by': - for cp in ('ec2',): - get_group_by_choices = getattr(InventorySource, 'get_%s_group_by_choices' % cp) - field_info['%s_group_by_choices' % cp] = get_group_by_choices() - # Special handling of notification configuration where the required properties # are conditional on the type selected. if field.field_name == 'notification_configuration': diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 6ce32b3f51..cdd03a4e93 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1937,7 +1937,7 @@ class InventorySourceOptionsSerializer(BaseSerializer): class Meta: fields = ('*', 'source', 'source_path', 'source_script', 'source_vars', 'credential', - 'source_regions', 'instance_filters', 'group_by', 'overwrite', 'overwrite_vars', + 'source_regions', 'instance_filters', 'overwrite', 'overwrite_vars', 'custom_virtualenv', 'timeout', 'verbosity') def get_related(self, obj): diff --git a/awx/main/migrations/0118_v380_inventory_plugins.py b/awx/main/migrations/0118_v380_inventory_plugins.py index e2c8cd2d82..939922b206 100644 --- a/awx/main/migrations/0118_v380_inventory_plugins.py +++ b/awx/main/migrations/0118_v380_inventory_plugins.py @@ -56,4 +56,12 @@ class Migration(migrations.Migration): operations = [ migrations.RunPython(inventory_source_vars_forward, inventory_source_vars_backward,), + migrations.RemoveField( + model_name='inventorysource', + name='group_by', + ), + migrations.RemoveField( + model_name='inventoryupdate', + name='group_by', + ), ] diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index b56f3bd03e..59e3b2d644 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -958,12 +958,6 @@ class InventorySourceOptions(BaseModel): default='', help_text=_('Comma-separated list of filter expressions (EC2 only). Hosts are imported when ANY of the filters match.'), ) - group_by = models.CharField( - max_length=1024, - blank=True, - default='', - help_text=_('Limit groups automatically created from inventory source (EC2 only).'), - ) overwrite = models.BooleanField( default=False, help_text=_('Overwrite local groups and hosts from remote inventory source.'), @@ -983,24 +977,6 @@ class InventorySourceOptions(BaseModel): default=1, ) - @classmethod - def get_ec2_group_by_choices(cls): - return [ - ('ami_id', _('Image ID')), - ('availability_zone', _('Availability Zone')), - ('aws_account', _('Account')), - ('instance_id', _('Instance ID')), - ('instance_state', _('Instance State')), - ('platform', _('Platform')), - ('instance_type', _('Instance Type')), - ('key_pair', _('Key Name')), - ('region', _('Region')), - ('security_group', _('Security Group')), - ('tag_keys', _('Tags')), - ('tag_none', _('Tag None')), - ('vpc_id', _('VPC ID')), - ] - @classmethod def get_ec2_region_choices(cls): ec2_region_names = getattr(settings, 'EC2_REGION_NAMES', {}) @@ -1189,27 +1165,6 @@ class InventorySourceOptions(BaseModel): else: return '' - def clean_group_by(self): - group_by = str(self.group_by or '') - if self.source == 'ec2': - get_choices = getattr(self, 'get_%s_group_by_choices' % self.source) - valid_choices = [x[0] for x in get_choices()] - choice_transform = lambda x: x.strip().lower() - valid_choices = [choice_transform(x) for x in valid_choices] - choices = [choice_transform(x) for x in group_by.split(',') if x.strip()] - invalid_choices = [] - for c in choices: - if c not in valid_choices and c not in invalid_choices: - invalid_choices.append(c) - if invalid_choices: - raise ValidationError(_('Invalid group by choice: %(choice)s') % - {'choice': ', '.join(invalid_choices)}) - return ','.join(choices) - elif self.source == 'vmware': - return group_by - else: - return '' - class InventorySource(UnifiedJobTemplate, InventorySourceOptions, CustomVirtualEnvMixin, RelatedJobsMixin): diff --git a/awx_collection/plugins/modules/tower_inventory_source.py b/awx_collection/plugins/modules/tower_inventory_source.py index 5b0e2961df..3110c873a3 100644 --- a/awx_collection/plugins/modules/tower_inventory_source.py +++ b/awx_collection/plugins/modules/tower_inventory_source.py @@ -69,10 +69,6 @@ options: description: - Comma-separated list of filter expressions for matching hosts. type: str - group_by: - description: - - Limit groups automatically created from inventory source. - type: str overwrite: description: - Delete child groups and hosts not found in source. @@ -167,7 +163,6 @@ def main(): credential=dict(), source_regions=dict(), instance_filters=dict(), - group_by=dict(), overwrite=dict(type='bool'), overwrite_vars=dict(type='bool'), custom_virtualenv=dict(), @@ -245,7 +240,7 @@ def main(): OPTIONAL_VARS = ( 'description', 'source', 'source_path', 'source_vars', - 'source_regions', 'instance_filters', 'group_by', + 'source_regions', 'instance_filters', 'overwrite', 'overwrite_vars', 'custom_virtualenv', 'timeout', 'verbosity', 'update_on_launch', 'update_cache_timeout', 'update_on_project_update' diff --git a/awx_collection/test/awx/test_inventory_source.py b/awx_collection/test/awx/test_inventory_source.py index ab0296689b..35267bc4b3 100644 --- a/awx_collection/test/awx/test_inventory_source.py +++ b/awx_collection/test/awx/test_inventory_source.py @@ -192,7 +192,6 @@ def test_falsy_value(run_module, admin_user, base_inventory): # UoPL ? ? o - - - - - - - - - - # source_regions ? ? - o o o - - - - - - - # instance_filters ? ? - o - - o - - - - o - -# group_by ? ? - o - - o - - - - - - # source_vars* ? ? - o - o o o o o - - - # environmet vars* ? ? o - - - - - - - - - o # source_script ? ? - - - - - - - - - - r diff --git a/awxkit/awxkit/api/pages/inventory.py b/awxkit/awxkit/api/pages/inventory.py index e00f0d329a..179082e5a8 100644 --- a/awxkit/awxkit/api/pages/inventory.py +++ b/awxkit/awxkit/api/pages/inventory.py @@ -499,7 +499,6 @@ class InventorySource(HasCreate, HasNotifications, UnifiedJobTemplate): payload.source_project = project.id optional_fields = ( - 'group_by', 'instance_filters', 'source_path', 'source_regions',