1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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

View file

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

View file

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

View file

@ -97,10 +97,11 @@ from ansible.module_utils.vmware import (HAS_PYVMOMI,
find_dvs_by_name,
vmware_argument_spec,
wait_for_task
)
)
class VMwareDVSwitch(object):
def __init__(self, module):
self.module = module
self.dvs = None
@ -134,7 +135,6 @@ class VMwareDVSwitch(object):
except Exception as e:
self.module.fail_json(msg=str(e))
def create_dvswitch(self, network_folder):
result = None
changed = False
@ -152,7 +152,7 @@ class VMwareDVSwitch(object):
spec.productInfo.name = "DVS"
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)
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):
def __init__(self, module):
self.module = module
self.content = connect_to_api(self.module)
@ -103,7 +104,6 @@ class VMwareLocalUserManager(object):
except Exception as e:
self.module.fail_json(msg=str(e))
def check_local_user_manager_state(self):
user_account = self.find_user_account()
if not user_account:
@ -111,7 +111,6 @@ class VMwareLocalUserManager(object):
else:
return 'present'
def find_user_account(self):
searchStr = self.local_user_name
exactMatch = True
@ -120,7 +119,6 @@ class VMwareLocalUserManager(object):
user_account = self.content.userDirectory.RetrieveUserGroups(None, searchStr, None, None, exactMatch, findUsers, findGroups)
return user_account
def create_account_spec(self):
account_spec = vim.host.LocalAccountManager.AccountSpecification()
account_spec.id = self.local_user_name
@ -128,7 +126,6 @@ class VMwareLocalUserManager(object):
account_spec.description = self.local_user_description
return account_spec
def state_create_user(self):
account_spec = self.create_account_spec()
@ -151,7 +148,6 @@ class VMwareLocalUserManager(object):
except vmodl.MethodFault as method_fault:
self.module.fail_json(msg=method_fault.msg)
def state_remove_user(self):
try:
self.content.accountManager.RemoveUser(self.local_user_name)
@ -161,12 +157,10 @@ class VMwareLocalUserManager(object):
except vmodl.MethodFault as method_fault:
self.module.fail_json(msg=method_fault.msg)
def state_exit_unchanged(self):
self.module.exit_json(changed=False)
def main():
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):
def __init__(self, module):
self.module = module
self.host_system = None
@ -158,7 +159,7 @@ class VMwareMigrateVmk(object):
for vnic in self.host_system.configManager.networkSystem.networkInfo.vnic:
if vnic.device == self.device:
#self.vnic = vnic
# self.vnic = vnic
if vnic.spec.distributedVirtualPort is None:
if vnic.portgroup == self.current_portgroup_name:
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,
vmware_argument_spec, wait_for_task)
def migrate_vm(vm_object, host_object):
"""
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)
return task_object
def main():
argument_spec = vmware_argument_spec()

View file

@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- 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)
from __future__ import absolute_import, division, print_function
@ -54,7 +54,6 @@ options:
description:
- If C(no), SSL certificates will not be validated. This should only be
set to C(no) when no other option exists.
required: false
default: 'yes'
choices: ['yes', 'no']
@ -74,6 +73,7 @@ EXAMPLES = '''
datastore: datastore1
path: some/remote/file
transport: local
- vsphere_copy:
host: vhost
login: vuser
@ -105,7 +105,7 @@ def vmware_path(datastore, datacenter, path):
datacenter = datacenter.replace('&', '%26')
if not path.startswith("/"):
path = "/" + path
params = dict( dsName = datastore )
params = dict(dsName=datastore)
if datacenter:
params["dcPath"] = datacenter
params = urlencode(params)
@ -115,18 +115,18 @@ def vmware_path(datastore, datacenter, path):
def main():
module = AnsibleModule(
argument_spec = dict(
host = dict(required=True, aliases=[ 'hostname' ]),
login = dict(required=True, aliases=[ 'username' ]),
password = dict(required=True, no_log=True),
src = dict(required=True, aliases=[ 'name' ]),
datacenter = dict(required=True),
datastore = dict(required=True),
dest = dict(required=True, aliases=[ 'path' ]),
validate_certs = dict(required=False, default=True, type='bool'),
argument_spec=dict(
host=dict(required=True, aliases=['hostname']),
login=dict(required=True, aliases=['username']),
password=dict(required=True, no_log=True),
src=dict(required=True, aliases=['name']),
datacenter=dict(required=True),
datastore=dict(required=True),
dest=dict(required=True, aliases=['path']),
validate_certs=dict(default=True, type='bool'),
),
# 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')
@ -154,8 +154,8 @@ def main():
try:
r = open_url(url, data=data, headers=headers, method='PUT',
url_username=login, url_password=password, validate_certs=validate_certs,
force_basic_auth=True)
url_username=login, url_password=password, validate_certs=validate_certs,
force_basic_auth=True)
except socket.error as e:
if isinstance(e.args, tuple) and e[0] == errno.ECONNRESET:
# VSphere resets connection if the file is in use and cannot be replaced

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_share.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/webfaction/webfaction_app.py
lib/ansible/modules/cloud/webfaction/webfaction_db.py