mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-09 18:04:02 -07:00
PEP 8 W291 whitespace cleanup.
This commit is contained in:
parent
95789f3949
commit
d913f69ba1
166 changed files with 493 additions and 565 deletions
|
@ -179,14 +179,14 @@ def randompass():
|
|||
'''
|
||||
Generate a long random password that comply to Linode requirements
|
||||
'''
|
||||
# Linode API currently requires the following:
|
||||
# It must contain at least two of these four character classes:
|
||||
# Linode API currently requires the following:
|
||||
# It must contain at least two of these four character classes:
|
||||
# lower case letters - upper case letters - numbers - punctuation
|
||||
# we play it safe :)
|
||||
import random
|
||||
import string
|
||||
# as of python 2.4, this reseeds the PRNG from urandom
|
||||
random.seed()
|
||||
random.seed()
|
||||
lower = ''.join(random.choice(string.ascii_lowercase) for x in range(6))
|
||||
upper = ''.join(random.choice(string.ascii_uppercase) for x in range(6))
|
||||
number = ''.join(random.choice(string.digits) for x in range(6))
|
||||
|
@ -218,11 +218,11 @@ def getInstanceDetails(api, server):
|
|||
'ip_id': ip['IPADDRESSID']})
|
||||
return instance
|
||||
|
||||
def linodeServers(module, api, state, name, plan, distribution, datacenter, linode_id,
|
||||
def linodeServers(module, api, state, name, plan, distribution, datacenter, linode_id,
|
||||
payment_term, password, ssh_pub_key, swap, wait, wait_timeout):
|
||||
instances = []
|
||||
changed = False
|
||||
new_server = False
|
||||
new_server = False
|
||||
servers = []
|
||||
disks = []
|
||||
configs = []
|
||||
|
@ -233,7 +233,7 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino
|
|||
# For the moment we only consider linode_id as criteria for match
|
||||
# Later we can use more (size, name, etc.) and update existing
|
||||
servers = api.linode_list(LinodeId=linode_id)
|
||||
# Attempt to fetch details about disks and configs only if servers are
|
||||
# Attempt to fetch details about disks and configs only if servers are
|
||||
# found with linode_id
|
||||
if servers:
|
||||
disks = api.linode_disk_list(LinodeId=linode_id)
|
||||
|
@ -256,7 +256,7 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino
|
|||
# Create linode entity
|
||||
new_server = True
|
||||
try:
|
||||
res = api.linode_create(DatacenterID=datacenter, PlanID=plan,
|
||||
res = api.linode_create(DatacenterID=datacenter, PlanID=plan,
|
||||
PaymentTerm=payment_term)
|
||||
linode_id = res['LinodeID']
|
||||
# Update linode Label to match name
|
||||
|
@ -282,17 +282,17 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino
|
|||
size = servers[0]['TOTALHD'] - swap
|
||||
if ssh_pub_key:
|
||||
res = api.linode_disk_createfromdistribution(
|
||||
LinodeId=linode_id, DistributionID=distribution,
|
||||
LinodeId=linode_id, DistributionID=distribution,
|
||||
rootPass=password, rootSSHKey=ssh_pub_key,
|
||||
Label='%s data disk (lid: %s)' % (name, linode_id), Size=size)
|
||||
else:
|
||||
res = api.linode_disk_createfromdistribution(
|
||||
LinodeId=linode_id, DistributionID=distribution, rootPass=password,
|
||||
LinodeId=linode_id, DistributionID=distribution, rootPass=password,
|
||||
Label='%s data disk (lid: %s)' % (name, linode_id), Size=size)
|
||||
jobs.append(res['JobID'])
|
||||
# Create SWAP disk
|
||||
res = api.linode_disk_create(LinodeId=linode_id, Type='swap',
|
||||
Label='%s swap disk (lid: %s)' % (name, linode_id),
|
||||
res = api.linode_disk_create(LinodeId=linode_id, Type='swap',
|
||||
Label='%s swap disk (lid: %s)' % (name, linode_id),
|
||||
Size=swap)
|
||||
jobs.append(res['JobID'])
|
||||
except Exception as e:
|
||||
|
@ -364,12 +364,12 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino
|
|||
time.sleep(5)
|
||||
if wait and wait_timeout <= time.time():
|
||||
# waiting took too long
|
||||
module.fail_json(msg = 'Timeout waiting on %s (lid: %s)' %
|
||||
module.fail_json(msg = 'Timeout waiting on %s (lid: %s)' %
|
||||
(server['LABEL'], server['LINODEID']))
|
||||
# Get a fresh copy of the server details
|
||||
server = api.linode_list(LinodeId=server['LINODEID'])[0]
|
||||
if server['STATUS'] == -2:
|
||||
module.fail_json(msg = '%s (lid: %s) failed to boot' %
|
||||
module.fail_json(msg = '%s (lid: %s) failed to boot' %
|
||||
(server['LABEL'], server['LINODEID']))
|
||||
# From now on we know the task is a success
|
||||
# Build instance report
|
||||
|
@ -380,7 +380,7 @@ def linodeServers(module, api, state, name, plan, distribution, datacenter, lino
|
|||
else:
|
||||
instance['status'] = 'Starting'
|
||||
|
||||
# Return the root password if this is a new box and no SSH key
|
||||
# Return the root password if this is a new box and no SSH key
|
||||
# has been provided
|
||||
if new_server and not ssh_pub_key:
|
||||
instance['password'] = password
|
||||
|
@ -495,7 +495,7 @@ def main():
|
|||
except Exception as e:
|
||||
module.fail_json(msg = '%s' % e.value[0]['ERRORMESSAGE'])
|
||||
|
||||
linodeServers(module, api, state, name, plan, distribution, datacenter, linode_id,
|
||||
linodeServers(module, api, state, name, plan, distribution, datacenter, linode_id,
|
||||
payment_term, password, ssh_pub_key, swap, wait, wait_timeout)
|
||||
|
||||
# import module snippets
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue