pep8 fixes for vmware modules (#31537)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2017-10-12 11:20:05 +05:30 committed by René Moser
parent e7145e249f
commit 9d811a34c4
9 changed files with 42 additions and 41 deletions

View file

@ -82,6 +82,7 @@ def protocol_to_tuple(protocol):
protocol.get_Other(), protocol.get_Other(),
protocol.get_Any()) protocol.get_Any())
def protocol_to_string(protocol): def protocol_to_string(protocol):
protocol = protocol_to_tuple(protocol) protocol = protocol_to_tuple(protocol)
if protocol[0] is True: if protocol[0] is True:
@ -95,6 +96,7 @@ def protocol_to_string(protocol):
elif protocol[4] is True: elif protocol[4] is True:
return 'Any' return 'Any'
def protocol_to_type(protocol): def protocol_to_type(protocol):
try: try:
protocols = ProtocolsType() protocols = ProtocolsType()
@ -103,6 +105,7 @@ def protocol_to_type(protocol):
except AttributeError: except AttributeError:
raise VcaError("The value in protocol is not valid") raise VcaError("The value in protocol is not valid")
def validate_fw_rules(fw_rules): def validate_fw_rules(fw_rules):
for rule in fw_rules: for rule in fw_rules:
for k in rule.keys(): for k in rule.keys():
@ -122,6 +125,7 @@ def validate_fw_rules(fw_rules):
return fw_rules return fw_rules
def fw_rules_to_dict(rules): def fw_rules_to_dict(rules):
fw_rules = list() fw_rules = list()
for rule in rules: for rule in rules:
@ -140,6 +144,7 @@ def fw_rules_to_dict(rules):
) )
return fw_rules return fw_rules
def create_fw_rule(is_enable, description, policy, protocol, dest_port, def create_fw_rule(is_enable, description, policy, protocol, dest_port,
dest_ip, source_port, source_ip, enable_logging): dest_ip, source_port, source_ip, enable_logging):
@ -153,13 +158,14 @@ def create_fw_rule(is_enable, description, policy, protocol, dest_port,
SourceIp=source_ip, SourceIp=source_ip,
EnableLogging=enable_logging) EnableLogging=enable_logging)
def main(): def main():
argument_spec = vca_argument_spec() argument_spec = vca_argument_spec()
argument_spec.update( argument_spec.update(
dict( dict(
fw_rules = dict(required=True, type='list'), fw_rules=dict(required=True, type='list'),
gateway_name = dict(default='gateway'), gateway_name=dict(default='gateway'),
state = dict(default='present', choices=['present', 'absent']) state=dict(default='present', choices=['present', 'absent'])
) )
) )

View file

@ -112,20 +112,22 @@ def nat_rules_to_dict(nat_rules):
) )
return result return result
def rule_to_string(rule): def rule_to_string(rule):
strings = list() strings = list()
for key, value in rule.items(): for key, value in rule.items():
strings.append('%s=%s' % (key, value)) strings.append('%s=%s' % (key, value))
return ', '.join(strings) return ', '.join(strings)
def main(): def main():
argument_spec = vca_argument_spec() argument_spec = vca_argument_spec()
argument_spec.update( argument_spec.update(
dict( dict(
nat_rules = dict(type='list', default=[]), nat_rules=dict(type='list', default=[]),
gateway_name = dict(default='gateway'), gateway_name=dict(default='gateway'),
purge_rules = dict(default=False, type='bool'), purge_rules=dict(default=False, type='bool'),
state = dict(default='present', choices=['present', 'absent']) state=dict(default='present', choices=['present', 'absent'])
) )
) )

View file

@ -165,6 +165,7 @@ def get_instance(module):
except VcaError: except VcaError:
return inst return inst
def create(module): def create(module):
vdc_name = module.params['vdc_name'] vdc_name = module.params['vdc_name']
vapp_name = module.params['vapp_name'] vapp_name = module.params['vapp_name']
@ -187,11 +188,13 @@ def create(module):
module.vca.block_until_completed(task) module.vca.block_until_completed(task)
def delete(module): def delete(module):
vdc_name = module.params['vdc_name'] vdc_name = module.params['vdc_name']
vapp_name = module.params['vapp_name'] vapp_name = module.params['vapp_name']
module.vca.delete_vapp(vdc_name, vapp_name) module.vca.delete_vapp(vdc_name, vapp_name)
def do_operation(module): def do_operation(module):
vapp_name = module.params['vapp_name'] vapp_name = module.params['vapp_name']
operation = module.params['operation'] operation = module.params['operation']
@ -209,6 +212,7 @@ def do_operation(module):
cmd = 'power:%s' % operation cmd = 'power:%s' % operation
module.get_vapp(vapp_name).execute(cmd, 'post', targetVM=vm) module.get_vapp(vapp_name).execute(cmd, 'post', targetVM=vm)
def set_state(module): def set_state(module):
state = module.params['state'] state = module.params['state']
vapp = module.get_vapp(module.params['vapp_name']) vapp = module.get_vapp(module.params['vapp_name'])

View file

@ -101,6 +101,7 @@ from ansible.module_utils.vmware import (HAS_PYVMOMI,
class VMwareDVSwitch(object): class VMwareDVSwitch(object):
def __init__(self, module): def __init__(self, module):
self.module = module self.module = module
self.dvs = None self.dvs = None
@ -134,7 +135,6 @@ class VMwareDVSwitch(object):
except Exception as e: except Exception as e:
self.module.fail_json(msg=str(e)) self.module.fail_json(msg=str(e))
def create_dvswitch(self, network_folder): def create_dvswitch(self, network_folder):
result = None result = None
changed = False changed = False
@ -152,7 +152,7 @@ class VMwareDVSwitch(object):
spec.productInfo.name = "DVS" spec.productInfo.name = "DVS"
spec.productInfo.vendor = "VMware" spec.productInfo.vendor = "VMware"
for count in range(1, self.uplink_quantity+1): for count in range(1, self.uplink_quantity + 1):
spec.configSpec.uplinkPortPolicy.uplinkPortName.append("uplink%d" % count) spec.configSpec.uplinkPortPolicy.uplinkPortName.append("uplink%d" % count)
task = network_folder.CreateDVS_Task(spec) task = network_folder.CreateDVS_Task(spec)

View file

@ -74,6 +74,7 @@ from ansible.module_utils.vmware import HAS_PYVMOMI, connect_to_api, vmware_argu
class VMwareLocalUserManager(object): class VMwareLocalUserManager(object):
def __init__(self, module): def __init__(self, module):
self.module = module self.module = module
self.content = connect_to_api(self.module) self.content = connect_to_api(self.module)
@ -103,7 +104,6 @@ class VMwareLocalUserManager(object):
except Exception as e: except Exception as e:
self.module.fail_json(msg=str(e)) self.module.fail_json(msg=str(e))
def check_local_user_manager_state(self): def check_local_user_manager_state(self):
user_account = self.find_user_account() user_account = self.find_user_account()
if not user_account: if not user_account:
@ -111,7 +111,6 @@ class VMwareLocalUserManager(object):
else: else:
return 'present' return 'present'
def find_user_account(self): def find_user_account(self):
searchStr = self.local_user_name searchStr = self.local_user_name
exactMatch = True exactMatch = True
@ -120,7 +119,6 @@ class VMwareLocalUserManager(object):
user_account = self.content.userDirectory.RetrieveUserGroups(None, searchStr, None, None, exactMatch, findUsers, findGroups) user_account = self.content.userDirectory.RetrieveUserGroups(None, searchStr, None, None, exactMatch, findUsers, findGroups)
return user_account return user_account
def create_account_spec(self): def create_account_spec(self):
account_spec = vim.host.LocalAccountManager.AccountSpecification() account_spec = vim.host.LocalAccountManager.AccountSpecification()
account_spec.id = self.local_user_name account_spec.id = self.local_user_name
@ -128,7 +126,6 @@ class VMwareLocalUserManager(object):
account_spec.description = self.local_user_description account_spec.description = self.local_user_description
return account_spec return account_spec
def state_create_user(self): def state_create_user(self):
account_spec = self.create_account_spec() account_spec = self.create_account_spec()
@ -151,7 +148,6 @@ class VMwareLocalUserManager(object):
except vmodl.MethodFault as method_fault: except vmodl.MethodFault as method_fault:
self.module.fail_json(msg=method_fault.msg) self.module.fail_json(msg=method_fault.msg)
def state_remove_user(self): def state_remove_user(self):
try: try:
self.content.accountManager.RemoveUser(self.local_user_name) self.content.accountManager.RemoveUser(self.local_user_name)
@ -161,12 +157,10 @@ class VMwareLocalUserManager(object):
except vmodl.MethodFault as method_fault: except vmodl.MethodFault as method_fault:
self.module.fail_json(msg=method_fault.msg) self.module.fail_json(msg=method_fault.msg)
def state_exit_unchanged(self): def state_exit_unchanged(self):
self.module.exit_json(changed=False) self.module.exit_json(changed=False)
def main(): def main():
argument_spec = vmware_argument_spec() argument_spec = vmware_argument_spec()

View file

@ -82,6 +82,7 @@ from ansible.module_utils.vmware import (vmware_argument_spec, find_dvs_by_name,
class VMwareMigrateVmk(object): class VMwareMigrateVmk(object):
def __init__(self, module): def __init__(self, module):
self.module = module self.module = module
self.host_system = None self.host_system = None
@ -158,7 +159,7 @@ class VMwareMigrateVmk(object):
for vnic in self.host_system.configManager.networkSystem.networkInfo.vnic: for vnic in self.host_system.configManager.networkSystem.networkInfo.vnic:
if vnic.device == self.device: if vnic.device == self.device:
#self.vnic = vnic # self.vnic = vnic
if vnic.spec.distributedVirtualPort is None: if vnic.spec.distributedVirtualPort is None:
if vnic.portgroup == self.current_portgroup_name: if vnic.portgroup == self.current_portgroup_name:
return "migrate_vss_vds" return "migrate_vss_vds"

View file

@ -73,6 +73,7 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.vmware import (connect_to_api, find_hostsystem_by_name, find_vm_by_name, from ansible.module_utils.vmware import (connect_to_api, find_hostsystem_by_name, find_vm_by_name,
vmware_argument_spec, wait_for_task) vmware_argument_spec, wait_for_task)
def migrate_vm(vm_object, host_object): def migrate_vm(vm_object, host_object):
""" """
Migrate virtual machine and return the task. Migrate virtual machine and return the task.
@ -81,6 +82,7 @@ def migrate_vm(vm_object, host_object):
task_object = vm_object.Relocate(relocate_spec) task_object = vm_object.Relocate(relocate_spec)
return task_object return task_object
def main(): def main():
argument_spec = vmware_argument_spec() argument_spec = vmware_argument_spec()

View file

@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2015 Dag Wieers <dag@wieers.com> # Copyright (C): 2015, Dag Wieers <dag@wieers.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
@ -54,7 +54,6 @@ options:
description: description:
- If C(no), SSL certificates will not be validated. This should only be - If C(no), SSL certificates will not be validated. This should only be
set to C(no) when no other option exists. set to C(no) when no other option exists.
required: false
default: 'yes' default: 'yes'
choices: ['yes', 'no'] choices: ['yes', 'no']
@ -74,6 +73,7 @@ EXAMPLES = '''
datastore: datastore1 datastore: datastore1
path: some/remote/file path: some/remote/file
transport: local transport: local
- vsphere_copy: - vsphere_copy:
host: vhost host: vhost
login: vuser login: vuser
@ -105,7 +105,7 @@ def vmware_path(datastore, datacenter, path):
datacenter = datacenter.replace('&', '%26') datacenter = datacenter.replace('&', '%26')
if not path.startswith("/"): if not path.startswith("/"):
path = "/" + path path = "/" + path
params = dict( dsName = datastore ) params = dict(dsName=datastore)
if datacenter: if datacenter:
params["dcPath"] = datacenter params["dcPath"] = datacenter
params = urlencode(params) params = urlencode(params)
@ -115,18 +115,18 @@ def vmware_path(datastore, datacenter, path):
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec=dict(
host = dict(required=True, aliases=[ 'hostname' ]), host=dict(required=True, aliases=['hostname']),
login = dict(required=True, aliases=[ 'username' ]), login=dict(required=True, aliases=['username']),
password = dict(required=True, no_log=True), password=dict(required=True, no_log=True),
src = dict(required=True, aliases=[ 'name' ]), src=dict(required=True, aliases=['name']),
datacenter = dict(required=True), datacenter=dict(required=True),
datastore = dict(required=True), datastore=dict(required=True),
dest = dict(required=True, aliases=[ 'path' ]), dest=dict(required=True, aliases=['path']),
validate_certs = dict(required=False, default=True, type='bool'), validate_certs=dict(default=True, type='bool'),
), ),
# Implementing check-mode using HEAD is impossible, since size/date is not 100% reliable # Implementing check-mode using HEAD is impossible, since size/date is not 100% reliable
supports_check_mode = False, supports_check_mode=False,
) )
host = module.params.get('host') host = module.params.get('host')

View file

@ -130,14 +130,6 @@ lib/ansible/modules/cloud/univention/udm_dns_zone.py
lib/ansible/modules/cloud/univention/udm_group.py lib/ansible/modules/cloud/univention/udm_group.py
lib/ansible/modules/cloud/univention/udm_share.py lib/ansible/modules/cloud/univention/udm_share.py
lib/ansible/modules/cloud/univention/udm_user.py lib/ansible/modules/cloud/univention/udm_user.py
lib/ansible/modules/cloud/vmware/vca_fw.py
lib/ansible/modules/cloud/vmware/vca_nat.py
lib/ansible/modules/cloud/vmware/vca_vapp.py
lib/ansible/modules/cloud/vmware/vmware_dvswitch.py
lib/ansible/modules/cloud/vmware/vmware_local_user_manager.py
lib/ansible/modules/cloud/vmware/vmware_migrate_vmk.py
lib/ansible/modules/cloud/vmware/vmware_vmotion.py
lib/ansible/modules/cloud/vmware/vsphere_copy.py
lib/ansible/modules/cloud/vmware/vsphere_guest.py lib/ansible/modules/cloud/vmware/vsphere_guest.py
lib/ansible/modules/cloud/webfaction/webfaction_app.py lib/ansible/modules/cloud/webfaction/webfaction_app.py
lib/ansible/modules/cloud/webfaction/webfaction_db.py lib/ansible/modules/cloud/webfaction/webfaction_db.py