From 3a46c7945132c520dc613164b280d8c36facadef Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Fri, 16 Jan 2015 15:33:41 -0600 Subject: [PATCH] Clean up some required argument logic --- lib/ansible/modules/cloud/rackspace/rax_keypair.py | 4 ++-- lib/ansible/modules/cloud/rackspace/rax_network.py | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/cloud/rackspace/rax_keypair.py b/lib/ansible/modules/cloud/rackspace/rax_keypair.py index 591ad8c3597..8f38abc12e0 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_keypair.py +++ b/lib/ansible/modules/cloud/rackspace/rax_keypair.py @@ -104,7 +104,7 @@ def rax_keypair(module, name, public_key, state): keypair = {} if state == 'present': - if os.path.isfile(public_key): + if public_key and os.path.isfile(public_key): try: f = open(public_key) public_key = f.read() @@ -143,7 +143,7 @@ def main(): argument_spec = rax_argument_spec() argument_spec.update( dict( - name=dict(), + name=dict(required=True), public_key=dict(), state=dict(default='present', choices=['absent', 'present']), ) diff --git a/lib/ansible/modules/cloud/rackspace/rax_network.py b/lib/ansible/modules/cloud/rackspace/rax_network.py index bc4745a7a84..bd23f5f878d 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_network.py +++ b/lib/ansible/modules/cloud/rackspace/rax_network.py @@ -65,10 +65,6 @@ except ImportError: 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 network = None networks = [] @@ -79,6 +75,9 @@ def cloud_network(module, state, label, cidr): 'incorrectly capitalized region name.') if state == 'present': + if not cidr: + module.fail_json(msg='missing required arguments: cidr') + try: network = pyrax.cloud_networks.find_network_by_label(label) except pyrax.exceptions.NetworkNotFound: @@ -115,7 +114,7 @@ def main(): dict( state=dict(default='present', choices=['present', 'absent']), - label=dict(), + label=dict(required=True), cidr=dict() ) )