From ddeba3c43c20396447509dfc4968bc3f12551f49 Mon Sep 17 00:00:00 2001 From: Paul Pajerski <74076410+ppajersk@users.noreply.github.com> Date: Tue, 23 Feb 2021 17:57:22 -0500 Subject: [PATCH] Renamed variables that shadowed builtins (#95) Fixed SonarCloud findings --- .gitignore | 2 ++ ansible/module_utils/viptela/viptela.py | 19 ++++--------------- .../viptela/vmanage_device_attachment.py | 10 +++++----- vmanage/api/policy_updates.py | 8 +------- vmanage/cli/clean.py | 4 +--- 5 files changed, 13 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 2ee1975..7137d58 100644 --- a/.gitignore +++ b/.gitignore @@ -486,3 +486,5 @@ MigrationBackup/ viptela.egg-info/ venv_python_viptela/ .idea/ + +.DS_Store diff --git a/ansible/module_utils/viptela/viptela.py b/ansible/module_utils/viptela/viptela.py index deb6d60..7fad167 100644 --- a/ansible/module_utils/viptela/viptela.py +++ b/ansible/module_utils/viptela/viptela.py @@ -10,7 +10,6 @@ except ImportError: JSONDecodeError = ValueError - def viptela_argument_spec(): return dict(host=dict(type='str', required=True, fallback=(env_fallback, ['VMANAGE_HOST'])), port=dict(type='str', required=False, fallback=(env_fallback, ['VMANAGE_PORT'])), @@ -96,7 +95,7 @@ def compare_payloads(new_payload, old_payload, compare_values=None): payload_key_diff = [] for key, value in new_payload.items(): if key in compare_values: - if key not in old_payload: + if key not in old_payload or new_payload[key] != old_payload[key]: payload_key_diff.append(key) return payload_key_diff @@ -351,7 +350,6 @@ def set_vmanage_org(self, org): def get_vmanage_vbond(self): response = self.request('/dataservice/settings/configuration/device') - vbond_port = None try: return {'vbond': response.json['data'][0]['domainIp'], 'vbond_port': response.json['data'][0]['port']} except: @@ -359,8 +357,7 @@ def get_vmanage_vbond(self): def set_vmanage_vbond(self, vbond, vbond_port='12346'): payload = {'domainIp': vbond, 'port': vbond_port} - response = self.request('/dataservice/settings/configuration/device', method='POST', payload=payload) - + self.request('/dataservice/settings/configuration/device', method='POST', payload=payload) return def get_vmanage_ca_type(self): @@ -372,7 +369,7 @@ def get_vmanage_ca_type(self): def set_vmanage_ca_type(self, type): payload = {'certificateSigning': type, 'challengeAvailable': 'false'} - response = self.request('/dataservice/settings/configuration/certificate', method='POST', payload=payload) + self.request('/dataservice/settings/configuration/certificate', method='POST', payload=payload) return def get_vmanage_root_cert(self): @@ -384,7 +381,7 @@ def get_vmanage_root_cert(self): def set_vmanage_root_cert(self, cert): payload = {'enterpriseRootCA': cert} - response = self.request('/dataservice/settings/configuration/certificate/enterpriserootca', method='PUT', payload=payload) + self.request('/dataservice/settings/configuration/certificate/enterpriserootca', method='PUT', payload=payload) return def install_device_cert(self, cert): @@ -510,14 +507,6 @@ def get_device_status_dict(self, key_name='host-name', remove_key=False): return self.list_to_dict(device_list, key_name=key_name, remove_key=remove_key) - def get_device_status(self, value, key='system-ip'): - response = self.request('/dataservice/device?{0}={1}'.format(key, value)) - - try: - return response.json['data'][0] - except: - return {} - def get_device_vedges(self, key_name='host-name', remove_key=True): response = self.request('/dataservice/system/device/vedges') diff --git a/ansible/modules/viptela/vmanage_device_attachment.py b/ansible/modules/viptela/vmanage_device_attachment.py index f035f7e..ec483e2 100644 --- a/ansible/modules/viptela/vmanage_device_attachment.py +++ b/ansible/modules/viptela/vmanage_device_attachment.py @@ -133,15 +133,15 @@ def run_module(): # just leave it out since it is not required. for key, value in viptela.params['variables'].items(): if key in template_variables: - property = template_variables[key] - device_template_variables[property] = viptela.params['variables'][key] + property_value = template_variables[key] + device_template_variables[property_value] = viptela.params['variables'][key] # When dealing with optional parameters if we do not have explicitely set a value for it # we must add the optional parameter to the payload with { key: 'TEMPLATE_IGNORE'} for key, value in optional_template_variables.items(): - property = template_variables[key] - if property not in device_template_variables: - device_template_variables[property] = 'TEMPLATE_IGNORE' + property_value = template_variables[key] + if property_value not in device_template_variables: + device_template_variables[property_value] = 'TEMPLATE_IGNORE' attached_uuid_list = viptela.get_template_attachments(template_data['templateId'], key='uuid') diff --git a/vmanage/api/policy_updates.py b/vmanage/api/policy_updates.py index 2b125bc..ecc1deb 100644 --- a/vmanage/api/policy_updates.py +++ b/vmanage/api/policy_updates.py @@ -132,13 +132,7 @@ def update_policy_definition(self, policy_type, name, policy_id, policy_def, new """ #pylint: disable=too-many-nested-blocks for item1 in policy_def["sequences"]: - if item1["sequenceName"] == seq_name: - for item2 in item1["actions"]: - if item2['type'] == 'slaClass': - for item3 in item2['parameter']: - if item3["field"] == 'preferredColor': - item3["value"] = new_color - elif seq_name is None: + if item1["sequenceName"] == seq_name or seq_name is None: for item2 in item1["actions"]: if item2['type'] == 'slaClass': for item3 in item2['parameter']: diff --git a/vmanage/cli/clean.py b/vmanage/cli/clean.py index 0bd0852..ee9be51 100644 --- a/vmanage/cli/clean.py +++ b/vmanage/cli/clean.py @@ -11,7 +11,5 @@ def clean(ctx, verify_clean): """ clean_vmanage = CleanVmanage(ctx.auth, ctx.host, ctx.port) - if verify_clean: - clean_vmanage.clean_all() - elif click.confirm('This will DESTROY EVERYTHING! Do you want to continue?'): + if verify_clean or click.confirm('This will DESTROY EVERYTHING! Do you want to continue?'): clean_vmanage.clean_all()