PEP 8 whitespace cleanup. (#20783)

* PEP 8 E271 whitespace cleanup.
* PEP 8 W293 whitespace cleanup.
* Fix whitespace issue from recent PR.
This commit is contained in:
Matt Clay 2017-01-27 15:45:23 -08:00 committed by GitHub
commit 95789f3949
132 changed files with 287 additions and 313 deletions

View file

@ -644,7 +644,7 @@ def replace(connection, module):
instances = props['instances']
if replace_instances:
instances = replace_instances
#check if min_size/max_size/desired capacity have been specified and if not use ASG values
if min_size is None:
min_size = as_group.min_size
@ -674,7 +674,7 @@ def replace(connection, module):
if not old_instances:
changed = False
return(changed, props)
# set temporary settings and wait for them to be reached
# This should get overwritten if the number of instances left is less than the batch size.
@ -827,7 +827,7 @@ def wait_for_term_inst(connection, module, term_instances):
lifecycle = instance_facts[i]['lifecycle_state']
health = instance_facts[i]['health_status']
log.debug("Instance {0} has state of {1},{2}".format(i,lifecycle,health ))
if lifecycle == 'Terminating' or health == 'Unhealthy':
if lifecycle == 'Terminating' or health == 'Unhealthy':
count += 1
time.sleep(10)

View file

@ -148,7 +148,7 @@ class Ec2CustomerGatewayManager:
CustomerGatewayId=gw_id
)
return response
def ensure_cgw_present(self, bgp_asn, ip_address):
response = self.ec2.create_customer_gateway(
DryRun=False,

View file

@ -215,7 +215,7 @@ class ElbInformation(object):
elb_array.append(existing_lb)
else:
elb_array = all_elbs
return list(map(self._get_elb_info, elb_array))
def main():

View file

@ -143,14 +143,14 @@ def main():
resource = module.params.get('resource')
tags = module.params.get('tags')
state = module.params.get('state')
ec2 = ec2_connect(module)
# We need a comparison here so that we can accurately report back changed status.
# Need to expand the gettags return format and compare with "tags" and then tag or detag as appropriate.
filters = {'resource-id' : resource}
gettags = ec2.get_all_tags(filters=filters)
dictadd = {}
dictremove = {}
baddict = {}
@ -170,7 +170,7 @@ def main():
tagger = ec2.create_tags(resource, dictadd)
gettags = ec2.get_all_tags(filters=filters)
module.exit_json(msg="Tags %s created for resource %s." % (dictadd,resource), changed=True)
if state == 'absent':
if not tags:
module.fail_json(msg="tags argument is required when state is absent")

View file

@ -97,7 +97,7 @@ def get_volume_info(volume):
},
'tags': volume.tags
}
return volume_info
def list_ec2_volumes(connection, module):

View file

@ -289,7 +289,7 @@ def main():
changed = False
new_options = collections.defaultdict(lambda: None)
region, ec2_url, boto_params = get_aws_connection_info(module)
connection = connect_to_aws(boto.vpc, region, **boto_params)
@ -378,9 +378,9 @@ def main():
# and remove old ones if that was requested
if params['delete_old'] and existing_options:
remove_dhcp_options_by_id(connection, existing_options.id)
module.exit_json(changed=changed, new_options=new_options, dhcp_options_id=dhcp_option.id)
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *

View file

@ -72,7 +72,7 @@ def get_vpc_info(vpc):
classic_link = vpc.classic_link_enabled
except AttributeError:
classic_link = False
vpc_info = { 'id': vpc.id,
'instance_tenancy': vpc.instance_tenancy,
'classic_link_enabled': classic_link,

View file

@ -133,7 +133,7 @@ def list_virtual_gateways(client, module):
snaked_vgws = [camel_dict_to_snake_dict(get_virtual_gateway_info(vgw))
for vgw in all_virtual_gateways['VpnGateways']]
module.exit_json(virtual_gateways=snaked_vgws)

View file

@ -457,7 +457,7 @@ def delete_group(module=None, iam=None, name=None):
iam.delete_group_policy(name, policy)
try:
iam.delete_group(name)
except boto.exception.BotoServerError as err:
except boto.exception.BotoServerError as err:
error_msg = boto_exception(err)
if ('must detach all policies first') in error_msg:
module.fail_json(changed=changed, msg="All inline polices have been removed. Though it appears"

View file

@ -280,7 +280,7 @@ EXAMPLES = '''
command: reboot
instance_name: database
wait: yes
# Restore a Postgres db instance from a snapshot, wait for it to become available again, and
# then modify it to add your security group. Also, display the new endpoint.
# Note that the "publicly_accessible" option is allowed here just as it is in the AWS CLI
@ -298,7 +298,7 @@ EXAMPLES = '''
tags:
Name: pg1_test_name_tag
register: rds
- local_action:
module: rds
command: modify
@ -844,7 +844,7 @@ def promote_db_instance(module, conn):
valid_vars = ['backup_retention', 'backup_window']
params = validate_parameters(required_vars, valid_vars, module)
instance_name = module.params.get('instance_name')
result = conn.get_db_instance(instance_name)
if not result:
module.fail_json(msg="DB Instance %s does not exist" % instance_name)

View file

@ -130,7 +130,7 @@ def main():
except BotoServerError as e:
if e.error_code != 'DBSubnetGroupNotFoundFault':
module.fail_json(msg = e.error_message)
if state == 'absent':
if exists:
conn.delete_db_subnet_group(group_name)

View file

@ -470,7 +470,7 @@ def main():
if command_in == 'create':
if ( weight_in!=None or region_in!=None or failover_in!=None ) and identifier_in==None:
module.fail_json(msg= "If you specify failover, region or weight you must also specify identifier")
elif ( weight_in==None and region_in==None and failover_in==None ) and identifier_in!=None:
elif ( weight_in==None and region_in==None and failover_in==None ) and identifier_in!=None:
module.fail_json(msg= "You have specified identifier which makes sense only if you specify one of: weight, region or failover.")

View file

@ -57,7 +57,7 @@ options:
- "Suffix that is appended to a request that is for a directory on the website endpoint (e.g. if the suffix is index.html and you make a request to samplebucket/images/ the data that is returned will be for the object with the key name images/index.html). The suffix must not include a slash character."
required: false
default: index.html
extends_documentation_fragment:
- aws
- ec2
@ -76,14 +76,14 @@ EXAMPLES = '''
- s3_website:
name: mybucket.com
state: absent
# Configure an s3 bucket as a website with index and error pages
- s3_website:
name: mybucket.com
suffix: home.htm
error_key: errors/404.htm
state: present
'''
RETURN = '''
@ -170,7 +170,7 @@ def _create_website_configuration(suffix, error_key, redirect_all_requests):
def enable_or_update_bucket_as_website(client_connection, resource_connection, module):
bucket_name = module.params.get("name")
redirect_all_requests = module.params.get("redirect_all_requests")
# If redirect_all_requests is set then don't use the default suffix that has been set
@ -263,7 +263,7 @@ def main():
redirect_all_requests=dict(type='str', required=False)
)
)
module = AnsibleModule(
argument_spec=argument_spec,
mutually_exclusive = [
@ -273,7 +273,7 @@ def main():
if not HAS_BOTO3:
module.fail_json(msg='boto3 required for this module')
region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True)
if region:
@ -288,7 +288,7 @@ def main():
enable_or_update_bucket_as_website(client_connection, resource_connection, module)
elif state == 'absent':
disable_bucket_as_website(client_connection, module)
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *

View file

@ -187,7 +187,7 @@ def create_or_update_sqs_queue(connection, module):
queue = connection.create_queue(queue_name)
update_sqs_queue(queue, **queue_attributes)
result['changed'] = True
if not module.check_mode:
result['queue_arn'] = queue.get_attributes('QueueArn')['QueueArn']
result['default_visibility_timeout'] = queue.get_attributes('VisibilityTimeout')['VisibilityTimeout']
@ -195,7 +195,7 @@ def create_or_update_sqs_queue(connection, module):
result['maximum_message_size'] = queue.get_attributes('MaximumMessageSize')['MaximumMessageSize']
result['delivery_delay'] = queue.get_attributes('DelaySeconds')['DelaySeconds']
result['receive_message_wait_time'] = queue.get_attributes('ReceiveMessageWaitTimeSeconds')['ReceiveMessageWaitTimeSeconds']
except BotoServerError:
result['msg'] = 'Failed to create/update sqs queue due to error: ' + traceback.format_exc()
module.fail_json(**result)

View file

@ -365,7 +365,7 @@ def create_virtual_machine(module, azure):
azure.get_role(name, name, name)
except AzureMissingException:
# vm does not exist; create it
if os_type == 'linux':
# Create linux configuration
disable_ssh_password_authentication = not password
@ -563,7 +563,7 @@ def main():
cloud_service_raw = None
if module.params.get('state') == 'absent':
(changed, public_dns_name, deployment) = terminate_virtual_machine(module, azure)
elif module.params.get('state') == 'present':
# Changed is always set to true when provisioning new instances
if not module.params.get('name'):

View file

@ -372,7 +372,7 @@ class AzureRMStorageBlob(AzureRMModuleBase):
self.log('Create container %s' % self.container)
tags = None
if not self.blob and self.tags:
if not self.blob and self.tags:
# when a blob is present, then tags are assigned at the blob level
tags = self.tags

View file

@ -918,7 +918,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
interface_dict['properties'] = nic_dict['properties']
# Expand public IPs to include config properties
for interface in result['properties']['networkProfile']['networkInterfaces']:
for interface in result['properties']['networkProfile']['networkInterfaces']:
for config in interface['properties']['ipConfigurations']:
if config['properties'].get('publicIPAddress'):
pipid_dict = azure_id_to_dict(config['properties']['publicIPAddress']['id'])

View file

@ -347,7 +347,7 @@ class AzureRMVirtualNetwork(AzureRMModuleBase):
try:
poller = self.network_client.virtual_networks.create_or_update(self.resource_group, self.name, vnet)
new_vnet = self.get_poller_result(poller)
except Exception as exc:
except Exception as exc:
self.fail("Error creating or updating virtual network {0} - {1}".format(self.name, str(exc)))
return virtual_network_to_dict(new_vnet)

View file

@ -232,7 +232,7 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack):
if not instance:
self.module.fail_json(msg="Instance not found: %s" % self.module.params.get('name'))
self.facts['cloudstack_instance'] = self.get_result(instance)
return self.facts
return self.facts
def get_result(self, instance):

View file

@ -293,7 +293,7 @@ class ImageManager(DockerBaseClass):
if repo_tag:
self.name = repo
self.tag = repo_tag
if self.state in ['present', 'build']:
self.present()
elif self.state == 'absent':

View file

@ -639,7 +639,7 @@ class ContainerManager(DockerBaseClass):
return options
def cmd_up(self):
start_deps = self.dependencies
service_names = self.services
detached = True
@ -943,7 +943,7 @@ class ContainerManager(DockerBaseClass):
short_id=container.short_id
))
result['actions'].append(service_res)
if not self.check_mode and result['changed']:
_, fd_name = tempfile.mkstemp(prefix="ansible")
try:

View file

@ -165,7 +165,7 @@ def grant_check(module, gs, obj):
module.fail_json(msg= str(e))
return True
def key_check(module, gs, bucket, obj):
try:
@ -228,7 +228,7 @@ def delete_key(module, gs, bucket, obj):
module.exit_json(msg="Object deleted from bucket ", changed=True)
except gs.provider.storage_response_error as e:
module.fail_json(msg= str(e))
def create_dirkey(module, gs, bucket, obj):
try:
bucket = gs.lookup(bucket)
@ -325,7 +325,7 @@ def handle_put(module, gs, bucket, obj, overwrite, src, expiration):
module.exit_json(msg="WARNING: Checksums do not match. Use overwrite parameter to force upload.", failed=True)
else:
upload_gsfile(module, gs, bucket, obj, src, expiration)
if not bucket_rc:
create_bucket(module, gs, bucket)
upload_gsfile(module, gs, bucket, obj, src, expiration)
@ -333,7 +333,7 @@ def handle_put(module, gs, bucket, obj, overwrite, src, expiration):
# If bucket exists but key doesn't, just upload.
if bucket_rc and not key_rc:
upload_gsfile(module, gs, bucket, obj, src, expiration)
def handle_delete(module, gs, bucket, obj):
if bucket and not obj:
if bucket_check(module, gs, bucket):
@ -350,7 +350,7 @@ def handle_delete(module, gs, bucket, obj):
module.exit_json(msg="Bucket does not exist.", changed=False)
else:
module.fail_json(msg="Bucket or Bucket & object parameter is required.", failed=True)
def handle_create(module, gs, bucket, obj):
if bucket and not obj:
if bucket_check(module, gs, bucket):
@ -417,7 +417,7 @@ def main():
gs = boto.connect_gs(gs_access_key, gs_secret_key)
except boto.exception.NoAuthHandlerFound as e:
module.fail_json(msg = str(e))
if mode == 'get':
if not bucket_check(module, gs, bucket) or not key_check(module, gs, bucket, obj):
module.fail_json(msg="Target bucket/key cannot be found", failed=True)
@ -425,7 +425,7 @@ def main():
download_gsfile(module, gs, bucket, obj, dest)
else:
handle_get(module, gs, bucket, obj, overwrite, dest)
if mode == 'put':
if not path_check(src):
module.fail_json(msg="Local object for PUT does not exist", failed=True)
@ -434,10 +434,10 @@ def main():
# Support for deleting an object if we have both params.
if mode == 'delete':
handle_delete(module, gs, bucket, obj)
if mode == 'create':
handle_create(module, gs, bucket, obj)
if mode == 'get_url':
if bucket and obj:
if bucket_check(module, gs, bucket) and key_check(module, gs, bucket, obj):

View file

@ -93,7 +93,7 @@ EXAMPLES = '''
# Basic zone creation example.
- name: Create a basic zone with the minimum number of parameters.
gcdns_zone: zone=example.com
# Zone removal example.
- name: Remove a zone.
gcdns_zone: zone=example.com state=absent

View file

@ -103,7 +103,7 @@ EXAMPLES = '''
- gce_img:
name: test-image
source: https://storage.googleapis.com/bucket/path/to/image.tgz
# Alternatively use the gs scheme
- gce_img:
name: test-image

View file

@ -194,7 +194,7 @@ def publish_messages(message_list, topic):
attrs = message['attributes']
batch.publish(bytes(msg), **attrs)
return True
def pull_messages(pull_params, sub):
"""
:rtype: tuple (output, changed)
@ -203,7 +203,7 @@ def pull_messages(pull_params, sub):
max_messages=pull_params.get('max_messages', None)
message_ack = pull_params.get('message_ack', 'no')
return_immediately = pull_params.get('return_immediately', False)
output= []
pulled = sub.pull(return_immediately=return_immediately,
max_messages=max_messages)
@ -237,7 +237,7 @@ def main():
if not HAS_PYTHON26:
module.fail_json(
msg="GCE module requires python's 'ast' module, python v2.6+")
if not HAS_GOOGLE_CLOUD_PUBSUB:
module.fail_json(msg="Please install google-cloud-pubsub library.")

View file

@ -98,7 +98,7 @@ except ImportError as e:
def list_func(data, member='name'):
"""Used for state=list."""
return [getattr(x, member) for x in data]
def main():
module = AnsibleModule(argument_spec=dict(
@ -112,7 +112,7 @@ def main():
if not HAS_PYTHON26:
module.fail_json(
msg="GCE module requires python's 'ast' module, python v2.6+")
if not HAS_GOOGLE_CLOUD_PUBSUB:
module.fail_json(msg="Please install google-cloud-pubsub library.")

View file

@ -247,7 +247,7 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino
# - need linode_id (entity)
# - need disk_id for linode_id - create disk from distrib
# - need config_id for linode_id - create config (need kernel)
# Any create step triggers a job that need to be waited for.
if not servers:
for arg in (name, plan, distribution, datacenter):
@ -424,7 +424,7 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino
instance['status'] = 'Restarting'
changed = True
instances.append(instance)
elif state in ('absent', 'deleted'):
for server in servers:
instance = getInstanceDetails(api, server)

View file

@ -306,7 +306,7 @@ def create_vm(conn, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork,
# define network parameters
network_net = params.Network(name=vmnetwork)
nic_net1 = params.NIC(name=vmnic, network=network_net, interface='virtio')
try:
conn.vms.add(vmparams)
except:
@ -502,7 +502,7 @@ def main():
else:
vm_stop(c, vmname)
module.exit_json(changed=True, msg="VM %s is shutting down" % vmname)
if state == 'restart':
if vm_status(c, vmname) == 'up':
vm_restart(c, vmname)

View file

@ -1038,7 +1038,7 @@ def main():
time.sleep(1)
except Exception as e:
module.fail_json(msg="deletion of VM %s failed with exception: %s" % ( vmid, e ))
elif state == 'current':
status = {}
try:

View file

@ -421,7 +421,7 @@ class VirtNetwork(object):
def create(self, entryid):
return self.conn.create(entryid)
def modify(self, entryid, xml):
return self.conn.modify(entryid, xml)

View file

@ -180,7 +180,7 @@ def _add_gateway_router(neutron, module, router_id, network_id):
module.fail_json(msg = "Error in adding gateway to router: %s" % e.message)
return True
def _remove_gateway_router(neutron, module, router_id):
def _remove_gateway_router(neutron, module, router_id):
try:
neutron.remove_gateway_router(router_id)
except Exception as e:

View file

@ -193,7 +193,7 @@ def _get_port_id(neutron, module, router_id, subnet_id):
module.fail_json( msg = "Error in listing ports: %s" % e.message)
if not ports['ports']:
return None
for port in ports['ports']:
for port in ports['ports']:
for subnet in port['fixed_ips']:
if subnet['subnet_id'] == subnet_id:
return port['id']
@ -209,7 +209,7 @@ def _add_interface_router(neutron, module, router_id, subnet_id):
module.fail_json(msg = "Error in adding interface to router: %s" % e.message)
return True
def _remove_interface_router(neutron, module, router_id, subnet_id):
def _remove_interface_router(neutron, module, router_id, subnet_id):
kwargs = {
'subnet_id': subnet_id
}

View file

@ -205,7 +205,7 @@ def main():
else:
if masters is None:
masters = []
pre_update_zone = zone
changed = _system_state_change(state, email,
description, ttl,

View file

@ -346,7 +346,7 @@ def get_hostname_list(module):
_msg = ("If you set count>1, you should only specify one hostname "
"with the %d formatter, not a list of hostnames.")
raise Exception(_msg)
if (len(hostnames) == 1) and (count > 0):
hostname_spec = hostnames[0]
count_range = range(count_offset, count_offset + count)
@ -382,7 +382,7 @@ def get_device_id_list(module):
raise Exception("You specified too many devices, max is %d" %
MAX_DEVICES)
return device_ids
def create_single_device(module, packet_conn, hostname):
@ -430,7 +430,7 @@ def wait_for_ips(module, packet_conn, created_devices):
if all_have_public_ip(refreshed):
return refreshed
time.sleep(5)
raise Exception("Waiting for IP assignment timed out. Hostnames: %s"
% [d.hostname for d in created_devices])

View file

@ -204,7 +204,7 @@ def act_on_sshkeys(target_state, module, packet_conn):
new_key_response = packet_conn.create_ssh_key(
newkey['label'], newkey['key'])
changed = True
matching_sshkeys.append(new_key_response)
else:
# state is 'absent' => delete mathcing keys

View file

@ -101,9 +101,9 @@ def rax_facts(module, address, name, server_id):
servers.append(cs.servers.get(server_id))
except Exception as e:
pass
servers[:] = [server for server in servers if server.status != "DELETED"]
if len(servers) > 1:
module.fail_json(msg='Multiple servers found matching provided '
'search parameters')

View file

@ -93,7 +93,7 @@ def find_vswitch_by_name(host, vswitch_name):
class VMwareHostVirtualSwitch(object):
def __init__(self, module):
self.host_system = None
self.content = None
@ -132,7 +132,7 @@ class VMwareHostVirtualSwitch(object):
# Source from
# https://github.com/rreubenur/pyvmomi-community-samples/blob/patch-1/samples/create_vswitch.py
def state_create_vswitch(self):
vss_spec = vim.host.VirtualSwitch.Specification()
vss_spec.numPorts = self.number_of_ports
@ -146,7 +146,7 @@ class VMwareHostVirtualSwitch(object):
def state_destroy_vswitch(self):
config = vim.host.NetworkConfig()
for portgroup in self.host_system.configManager.networkSystem.networkInfo.portgroup:
if portgroup.spec.vswitchName == self.vss.name:
portgroup_config = vim.host.PortGroup.Config()
@ -158,7 +158,7 @@ class VMwareHostVirtualSwitch(object):
portgroup_config.spec.vswitchName = portgroup.spec.vswitchName
portgroup_config.spec.policy = vim.host.NetworkPolicy()
config.portgroup.append(portgroup_config)
self.host_system.configManager.networkSystem.UpdateNetworkConfig(config, "modify")
self.host_system.configManager.networkSystem.RemoveVirtualSwitch(self.vss.name)
self.module.exit_json(changed=True)
@ -170,15 +170,15 @@ class VMwareHostVirtualSwitch(object):
host = get_all_objs(self.content, [vim.HostSystem])
if not host:
self.module.fail_json(msg="Unable to find host")
self.host_system = host.keys()[0]
self.vss = find_vswitch_by_name(self.host_system, self.switch_name)
if self.vss is None:
return 'absent'
else:
return 'present'
def main():
argument_spec = vmware_argument_spec()

View file

@ -999,7 +999,7 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name
except (KeyError, ValueError):
vsphere_client.disconnect()
module.fail_json(msg="Error in '%s' definition. Size needs to be specified as an integer." % disk)
# Make sure the new disk size is higher than the current value
dev = dev_list[disk_num]
if disksize < int(dev.capacityInKB):

View file

@ -148,7 +148,7 @@ def main():
existing_app = app_map.get(app_name)
result = {}
# Here's where the real stuff happens
if app_state == 'present':

View file

@ -84,7 +84,7 @@ options:
EXAMPLES = '''
# This will also create a default DB user with the same
# name as the database, and the specified password.
- name: Create a database
webfaction_db:
name: "{{webfaction_user}}_db1"
@ -145,7 +145,7 @@ def main():
existing_user = user_map.get(db_name)
result = {}
# Here's where the real stuff happens
if db_state == 'present':
@ -175,16 +175,16 @@ def main():
# If this isn't a dry run...
if not module.check_mode:
if not (existing_db or existing_user):
module.exit_json(changed = False,)
if existing_db:
# Delete the db if it exists
result.update(
webfaction.delete_db(session_id, db_name, db_type)
)
if existing_user:
# Delete the default db user if it exists
result.update(

View file

@ -121,7 +121,7 @@ def main():
existing_domain = domain_map.get(domain_name)
result = {}
# Here's where the real stuff happens
if domain_state == 'present':

View file

@ -107,7 +107,7 @@ def main():
existing_mailbox = mailbox_name in mailbox_list
result = {}
# Here's where the real stuff happens
if site_state == 'present':

View file

@ -53,7 +53,7 @@ options:
required: false
choices: ['present', 'absent']
default: "present"
host:
description:
- The webfaction host on which the site should be created.
@ -141,7 +141,7 @@ def main():
existing_site = site_map.get(site_name)
result = {}
# Here's where the real stuff happens
if site_state == 'present':