From f32716a0f14d1c63e9a668ed7bfba59488f5a50f Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Mon, 27 Jul 2020 10:55:36 -0400 Subject: [PATCH] remove instance_filter --- awx/api/serializers.py | 2 +- .../migrations/0118_v380_inventory_plugins.py | 8 ++ awx/main/models/inventory.py | 115 ------------------ awx/main/tests/unit/test_tasks.py | 2 - .../plugins/modules/tower_inventory_source.py | 7 +- .../test/awx/test_inventory_source.py | 1 - awxkit/awxkit/api/pages/inventory.py | 1 - tools/scripts/get_ec2_filter_names.py | 21 ---- 8 files changed, 10 insertions(+), 147 deletions(-) delete mode 100755 tools/scripts/get_ec2_filter_names.py diff --git a/awx/api/serializers.py b/awx/api/serializers.py index cdd03a4e93..3d6adc6a78 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', 'overwrite', 'overwrite_vars', + 'source_regions', '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 939922b206..3fddf729e0 100644 --- a/awx/main/migrations/0118_v380_inventory_plugins.py +++ b/awx/main/migrations/0118_v380_inventory_plugins.py @@ -64,4 +64,12 @@ class Migration(migrations.Migration): model_name='inventoryupdate', name='group_by', ), + migrations.RemoveField( + model_name='inventorysource', + name='instance_filter', + ), + migrations.RemoveField( + model_name='inventoryupdate', + name='instance_filter', + ), ] diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 59e3b2d644..f34ce3d236 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -838,89 +838,6 @@ class InventorySourceOptions(BaseModel): (2, '2 (DEBUG)'), ] - # Use tools/scripts/get_ec2_filter_names.py to build this list. - INSTANCE_FILTER_NAMES = [ - "architecture", - "association.allocation-id", - "association.association-id", - "association.ip-owner-id", - "association.public-ip", - "availability-zone", - "block-device-mapping.attach-time", - "block-device-mapping.delete-on-termination", - "block-device-mapping.device-name", - "block-device-mapping.status", - "block-device-mapping.volume-id", - "client-token", - "dns-name", - "group-id", - "group-name", - "hypervisor", - "iam-instance-profile.arn", - "image-id", - "instance-id", - "instance-lifecycle", - "instance-state-code", - "instance-state-name", - "instance-type", - "instance.group-id", - "instance.group-name", - "ip-address", - "kernel-id", - "key-name", - "launch-index", - "launch-time", - "monitoring-state", - "network-interface-private-dns-name", - "network-interface.addresses.association.ip-owner-id", - "network-interface.addresses.association.public-ip", - "network-interface.addresses.primary", - "network-interface.addresses.private-ip-address", - "network-interface.attachment.attach-time", - "network-interface.attachment.attachment-id", - "network-interface.attachment.delete-on-termination", - "network-interface.attachment.device-index", - "network-interface.attachment.instance-id", - "network-interface.attachment.instance-owner-id", - "network-interface.attachment.status", - "network-interface.availability-zone", - "network-interface.description", - "network-interface.group-id", - "network-interface.group-name", - "network-interface.mac-address", - "network-interface.network-interface.id", - "network-interface.owner-id", - "network-interface.requester-id", - "network-interface.requester-managed", - "network-interface.source-destination-check", - "network-interface.status", - "network-interface.subnet-id", - "network-interface.vpc-id", - "owner-id", - "placement-group-name", - "platform", - "private-dns-name", - "private-ip-address", - "product-code", - "product-code.type", - "ramdisk-id", - "reason", - "requester-id", - "reservation-id", - "root-device-name", - "root-device-type", - "source-dest-check", - "spot-instance-request-id", - "state-reason-code", - "state-reason-message", - "subnet-id", - "tag-key", - "tag-value", - "tenancy", - "virtualization-type", - "vpc-id" - ] - class Meta: abstract = True @@ -952,12 +869,6 @@ class InventorySourceOptions(BaseModel): blank=True, default='', ) - instance_filters = models.CharField( - max_length=1024, - blank=True, - default='', - help_text=_('Comma-separated list of filter expressions (EC2 only). Hosts are imported when ANY of the filters match.'), - ) overwrite = models.BooleanField( default=False, help_text=_('Overwrite local groups and hosts from remote inventory source.'), @@ -1139,32 +1050,6 @@ class InventorySourceOptions(BaseModel): source_vars_dict = VarsDictProperty('source_vars') - def clean_instance_filters(self): - instance_filters = str(self.instance_filters or '') - if self.source == 'ec2': - invalid_filters = [] - instance_filter_re = re.compile(r'^((tag:.+)|([a-z][a-z\.-]*[a-z]))=.*$') - for instance_filter in instance_filters.split(','): - instance_filter = instance_filter.strip() - if not instance_filter: - continue - if not instance_filter_re.match(instance_filter): - invalid_filters.append(instance_filter) - continue - instance_filter_name = instance_filter.split('=', 1)[0] - if instance_filter_name.startswith('tag:'): - continue - if instance_filter_name not in self.INSTANCE_FILTER_NAMES: - invalid_filters.append(instance_filter) - if invalid_filters: - raise ValidationError(_('Invalid filter expression: %(filter)s') % - {'filter': ', '.join(invalid_filters)}) - return instance_filters - elif self.source in ('vmware', 'tower'): - return instance_filters - else: - return '' - class InventorySource(UnifiedJobTemplate, InventorySourceOptions, CustomVirtualEnvMixin, RelatedJobsMixin): diff --git a/awx/main/tests/unit/test_tasks.py b/awx/main/tests/unit/test_tasks.py index 7dcea33ccd..341fcdc82d 100644 --- a/awx/main/tests/unit/test_tasks.py +++ b/awx/main/tests/unit/test_tasks.py @@ -2216,7 +2216,6 @@ class TestInventoryUpdateCredentials(TestJobExecution): task = tasks.RunInventoryUpdate() tower = CredentialType.defaults['tower']() inventory_update.source = 'tower' - inventory_update.instance_filters = '12345' inputs = { 'host': 'https://tower.example.org', 'username': 'bob', @@ -2248,7 +2247,6 @@ class TestInventoryUpdateCredentials(TestJobExecution): task = tasks.RunInventoryUpdate() tower = CredentialType.defaults['tower']() inventory_update.source = 'tower' - inventory_update.instance_filters = '12345' inputs = { 'host': 'https://tower.example.org', 'username': 'bob', diff --git a/awx_collection/plugins/modules/tower_inventory_source.py b/awx_collection/plugins/modules/tower_inventory_source.py index 3110c873a3..3840806f8f 100644 --- a/awx_collection/plugins/modules/tower_inventory_source.py +++ b/awx_collection/plugins/modules/tower_inventory_source.py @@ -65,10 +65,6 @@ options: description: - Regions for cloud provider. type: str - instance_filters: - description: - - Comma-separated list of filter expressions for matching hosts. - type: str overwrite: description: - Delete child groups and hosts not found in source. @@ -162,7 +158,6 @@ def main(): source_vars=dict(type='dict'), credential=dict(), source_regions=dict(), - instance_filters=dict(), overwrite=dict(type='bool'), overwrite_vars=dict(type='bool'), custom_virtualenv=dict(), @@ -240,7 +235,7 @@ def main(): OPTIONAL_VARS = ( 'description', 'source', 'source_path', 'source_vars', - 'source_regions', 'instance_filters', + 'source_regions', '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 35267bc4b3..fff6cdd3c3 100644 --- a/awx_collection/test/awx/test_inventory_source.py +++ b/awx_collection/test/awx/test_inventory_source.py @@ -191,7 +191,6 @@ def test_falsy_value(run_module, admin_user, base_inventory): # update_on_launch ? ? o o o o o o o o o o o # UoPL ? ? o - - - - - - - - - - # source_regions ? ? - o o o - - - - - - - -# instance_filters ? ? - o - - 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 179082e5a8..0976b09afe 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 = ( - 'instance_filters', 'source_path', 'source_regions', 'source_vars', diff --git a/tools/scripts/get_ec2_filter_names.py b/tools/scripts/get_ec2_filter_names.py deleted file mode 100755 index d001b1f8e7..0000000000 --- a/tools/scripts/get_ec2_filter_names.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python - -import json -import sys -import requests -from bs4 import BeautifulSoup - -response = requests.get('http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInstances.html') -soup = BeautifulSoup(response.text) - -section_h3 = soup.find(id='query-DescribeInstances-filters') -section_div = section_h3.find_parent('div', attrs={'class': 'section'}) - -filter_names = [] -for term in section_div.select('div.variablelist dt span.term'): - filter_name = term.get_text() - if not filter_name.startswith('tag:'): - filter_names.append(filter_name) -filter_names.sort() - -json.dump(filter_names, sys.stdout, indent=4)