Clean up some required argument logic

This commit is contained in:
Matt Martz 2015-01-16 15:33:41 -06:00 committed by Matt Clay
parent db5f2bf3df
commit 3a46c79451
2 changed files with 6 additions and 7 deletions

View file

@ -104,7 +104,7 @@ def rax_keypair(module, name, public_key, state):
keypair = {} keypair = {}
if state == 'present': if state == 'present':
if os.path.isfile(public_key): if public_key and os.path.isfile(public_key):
try: try:
f = open(public_key) f = open(public_key)
public_key = f.read() public_key = f.read()
@ -143,7 +143,7 @@ def main():
argument_spec = rax_argument_spec() argument_spec = rax_argument_spec()
argument_spec.update( argument_spec.update(
dict( dict(
name=dict(), name=dict(required=True),
public_key=dict(), public_key=dict(),
state=dict(default='present', choices=['absent', 'present']), state=dict(default='present', choices=['absent', 'present']),
) )

View file

@ -65,10 +65,6 @@ except ImportError:
def cloud_network(module, state, label, cidr): def cloud_network(module, state, label, cidr):
for arg in (state, label, cidr):
if not arg:
module.fail_json(msg='%s is required for cloud_networks' % arg)
changed = False changed = False
network = None network = None
networks = [] networks = []
@ -79,6 +75,9 @@ def cloud_network(module, state, label, cidr):
'incorrectly capitalized region name.') 'incorrectly capitalized region name.')
if state == 'present': if state == 'present':
if not cidr:
module.fail_json(msg='missing required arguments: cidr')
try: try:
network = pyrax.cloud_networks.find_network_by_label(label) network = pyrax.cloud_networks.find_network_by_label(label)
except pyrax.exceptions.NetworkNotFound: except pyrax.exceptions.NetworkNotFound:
@ -115,7 +114,7 @@ def main():
dict( dict(
state=dict(default='present', state=dict(default='present',
choices=['present', 'absent']), choices=['present', 'absent']),
label=dict(), label=dict(required=True),
cidr=dict() cidr=dict()
) )
) )