Skip to content

Commit

Permalink
Renamed variables that shadowed builtins (#95)
Browse files Browse the repository at this point in the history
Fixed SonarCloud findings
  • Loading branch information
ppajersk authored Feb 23, 2021
1 parent a16f4f7 commit ddeba3c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,5 @@ MigrationBackup/
viptela.egg-info/
venv_python_viptela/
.idea/

.DS_Store
19 changes: 4 additions & 15 deletions ansible/module_utils/viptela/viptela.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])),
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -351,16 +350,14 @@ 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:
return {'vbond': None, 'vbond_port': None}

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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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')

Expand Down
10 changes: 5 additions & 5 deletions ansible/modules/viptela/vmanage_device_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
8 changes: 1 addition & 7 deletions vmanage/api/policy_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
4 changes: 1 addition & 3 deletions vmanage/cli/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit ddeba3c

Please sign in to comment.