Update module based on upstream feedback
- Remove deleted state - Use dict() instead of raw hash - Wrap or statements in parens instead of backslash line continuations - Change instances to networks in module return result
This commit is contained in:
parent
88083891bb
commit
f214b9870a
1 changed files with 12 additions and 12 deletions
|
@ -25,7 +25,7 @@ options:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Indicate desired state of the resource
|
- Indicate desired state of the resource
|
||||||
choices: ['present', 'absent', 'deleted']
|
choices: ['present', 'absent']
|
||||||
default: present
|
default: present
|
||||||
credentials:
|
credentials:
|
||||||
description:
|
description:
|
||||||
|
@ -93,9 +93,9 @@ def cloud_network(module, state, label, cidr):
|
||||||
if not arg:
|
if not arg:
|
||||||
module.fail_json(msg='%s is required for cloud_networks' % arg)
|
module.fail_json(msg='%s is required for cloud_networks' % arg)
|
||||||
|
|
||||||
instances = []
|
|
||||||
changed = False
|
changed = False
|
||||||
network = None
|
network = None
|
||||||
|
networks = []
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
try:
|
try:
|
||||||
|
@ -109,7 +109,7 @@ def cloud_network(module, state, label, cidr):
|
||||||
except Exception:
|
except Exception:
|
||||||
module.fail_json(msg='%s' % e.message)
|
module.fail_json(msg='%s' % e.message)
|
||||||
|
|
||||||
elif state in ('absent', 'deleted'):
|
elif state == 'absent':
|
||||||
try:
|
try:
|
||||||
network = pyrax.cloud_networks.find_network_by_label(label)
|
network = pyrax.cloud_networks.find_network_by_label(label)
|
||||||
network.delete()
|
network.delete()
|
||||||
|
@ -120,19 +120,19 @@ def cloud_network(module, state, label, cidr):
|
||||||
module.fail_json(msg='%s' % e.message)
|
module.fail_json(msg='%s' % e.message)
|
||||||
|
|
||||||
if network:
|
if network:
|
||||||
instance = {'id': network.id,
|
instance = dict(id=network.id,
|
||||||
'label': network.label,
|
label=network.label,
|
||||||
'cidr': network.cidr}
|
cidr=network.cidr)
|
||||||
instances.append(instance)
|
networks.append(instance)
|
||||||
|
|
||||||
module.exit_json(changed=changed, instances=instances)
|
module.exit_json(changed=changed, networks=networks)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
state=dict(default='present',
|
state=dict(default='present',
|
||||||
choices=['present', 'deleted', 'absent']),
|
choices=['present', 'absent']),
|
||||||
credentials=dict(aliases=['creds_file']),
|
credentials=dict(aliases=['creds_file']),
|
||||||
api_key=dict(),
|
api_key=dict(),
|
||||||
username=dict(),
|
username=dict(),
|
||||||
|
@ -153,9 +153,9 @@ def main():
|
||||||
try:
|
try:
|
||||||
username = username or os.environ.get('RAX_USERNAME')
|
username = username or os.environ.get('RAX_USERNAME')
|
||||||
api_key = api_key or os.environ.get('RAX_API_KEY')
|
api_key = api_key or os.environ.get('RAX_API_KEY')
|
||||||
credentials = credentials or \
|
credentials = (credentials or
|
||||||
os.environ.get('RAX_CREDENTIALS') or \
|
os.environ.get('RAX_CREDENTIALS') or
|
||||||
os.environ.get('RAX_CREDS_FILE')
|
os.environ.get('RAX_CREDS_FILE'))
|
||||||
region = region or os.environ.get('RAX_REGION')
|
region = region or os.environ.get('RAX_REGION')
|
||||||
|
|
||||||
except KeyError, e:
|
except KeyError, e:
|
||||||
|
|
Loading…
Reference in a new issue