From a134a71187a4c333749a17f3f70d93fc9f33580d Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Tue, 22 Sep 2015 16:28:14 +0200 Subject: [PATCH] cloudstack: implement common argument spec handling --- .../extras/cloud/cloudstack/cs_account.py | 41 ++++----- .../cloud/cloudstack/cs_affinitygroup.py | 31 +++---- .../extras/cloud/cloudstack/cs_domain.py | 27 +++--- .../extras/cloud/cloudstack/cs_firewall.py | 51 ++++++------ .../extras/cloud/cloudstack/cs_instance.py | 83 +++++++++---------- .../cloud/cloudstack/cs_instancegroup.py | 27 +++--- .../extras/cloud/cloudstack/cs_ip_address.py | 33 ++++---- .../modules/extras/cloud/cloudstack/cs_iso.py | 45 +++++----- .../extras/cloud/cloudstack/cs_network.py | 70 ++++++++-------- .../extras/cloud/cloudstack/cs_portforward.py | 47 +++++------ .../extras/cloud/cloudstack/cs_project.py | 29 +++---- .../cloud/cloudstack/cs_securitygroup.py | 25 +++--- .../cloud/cloudstack/cs_securitygroup_rule.py | 46 +++++----- .../extras/cloud/cloudstack/cs_sshkeypair.py | 29 +++---- .../extras/cloud/cloudstack/cs_staticnat.py | 35 ++++---- .../extras/cloud/cloudstack/cs_template.py | 81 +++++++++--------- .../extras/cloud/cloudstack/cs_user.py | 37 ++++----- .../extras/cloud/cloudstack/cs_vmsnapshot.py | 43 +++++----- 18 files changed, 356 insertions(+), 424 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py index 2ffecf06fc..839f6e5328 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py @@ -343,30 +343,25 @@ class AnsibleCloudStackAccount(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name = dict(required=True), + state = dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked'], default='present'), + account_type = dict(choices=['user', 'root_admin', 'domain_admin'], default='user'), + network_domain = dict(default=None), + domain = dict(default='ROOT'), + email = dict(default=None), + first_name = dict(default=None), + last_name = dict(default=None), + username = dict(default=None), + password = dict(default=None), + timezone = dict(default=None), + poll_async = dict(choices=BOOLEANS, default=True), + )) + module = AnsibleModule( - argument_spec = dict( - name = dict(required=True), - state = dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked'], default='present'), - account_type = dict(choices=['user', 'root_admin', 'domain_admin'], default='user'), - network_domain = dict(default=None), - domain = dict(default='ROOT'), - email = dict(default=None), - first_name = dict(default=None), - last_name = dict(default=None), - username = dict(default=None), - password = dict(default=None), - timezone = dict(default=None), - poll_async = dict(choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py index df685d8a98..7181eae607 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py @@ -200,25 +200,20 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name = dict(required=True), + affinty_type = dict(default=None), + description = dict(default=None), + state = dict(choices=['present', 'absent'], default='present'), + domain = dict(default=None), + account = dict(default=None), + poll_async = dict(choices=BOOLEANS, default=True), + )) + module = AnsibleModule( - argument_spec = dict( - name = dict(required=True), - affinty_type = dict(default=None), - description = dict(default=None), - state = dict(choices=['present', 'absent'], default='present'), - domain = dict(default=None), - account = dict(default=None), - poll_async = dict(choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_domain.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_domain.py index 94299d5d6a..0d8b7deaab 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_domain.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_domain.py @@ -239,23 +239,18 @@ class AnsibleCloudStackDomain(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + path = dict(required=True), + state = dict(choices=['present', 'absent'], default='present'), + network_domain = dict(default=None), + clean_up = dict(choices=BOOLEANS, default=False), + poll_async = dict(choices=BOOLEANS, default=True), + )) + module = AnsibleModule( - argument_spec = dict( - path = dict(required=True), - state = dict(choices=['present', 'absent'], default='present'), - network_domain = dict(default=None), - clean_up = dict(choices=BOOLEANS, default=False), - poll_async = dict(choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py index fa27f64ca0..5450254473 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py @@ -391,36 +391,35 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + ip_address = dict(default=None), + network = dict(default=None), + cidr = dict(default='0.0.0.0/0'), + protocol = dict(choices=['tcp', 'udp', 'icmp', 'all'], default='tcp'), + type = dict(choices=['ingress', 'egress'], default='ingress'), + icmp_type = dict(type='int', default=None), + icmp_code = dict(type='int', default=None), + start_port = dict(type='int', aliases=['port'], default=None), + end_port = dict(type='int', default=None), + state = dict(choices=['present', 'absent'], default='present'), + domain = dict(default=None), + account = dict(default=None), + project = dict(default=None), + poll_async = dict(choices=BOOLEANS, default=True), + )) + + required_together = cs_required_together() + required_together.extend([ + ['icmp_type', 'icmp_code'], + ]) + module = AnsibleModule( - argument_spec = dict( - ip_address = dict(default=None), - network = dict(default=None), - cidr = dict(default='0.0.0.0/0'), - protocol = dict(choices=['tcp', 'udp', 'icmp', 'all'], default='tcp'), - type = dict(choices=['ingress', 'egress'], default='ingress'), - icmp_type = dict(type='int', default=None), - icmp_code = dict(type='int', default=None), - start_port = dict(type='int', aliases=['port'], default=None), - end_port = dict(type='int', default=None), - state = dict(choices=['present', 'absent'], default='present'), - domain = dict(default=None), - account = dict(default=None), - project = dict(default=None), - poll_async = dict(choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), + argument_spec=argument_spec, + required_together=required_together, required_one_of = ( ['ip_address', 'network'], ), - required_together = ( - ['icmp_type', 'icmp_code'], - ['api_key', 'api_secret', 'api_url'], - ), mutually_exclusive = ( ['icmp_type', 'start_port'], ['icmp_type', 'end_port'], diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py index c31fb5c903..ed7392ec1d 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py @@ -818,52 +818,51 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): return self.result def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name = dict(required=True), + display_name = dict(default=None), + group = dict(default=None), + state = dict(choices=['present', 'deployed', 'started', 'stopped', 'restarted', 'absent', 'destroyed', 'expunged'], default='present'), + service_offering = dict(default=None), + cpu = dict(default=None, type='int'), + cpu_speed = dict(default=None, type='int'), + memory = dict(default=None, type='int'), + template = dict(default=None), + iso = dict(default=None), + networks = dict(type='list', aliases=[ 'network' ], default=None), + ip_to_networks = dict(type='list', aliases=['ip_to_network'], default=None), + ip_address = dict(defaul=None), + ip6_address = dict(defaul=None), + disk_offering = dict(default=None), + disk_size = dict(type='int', default=None), + root_disk_size = dict(type='int', default=None), + keyboard = dict(choices=['de', 'de-ch', 'es', 'fi', 'fr', 'fr-be', 'fr-ch', 'is', 'it', 'jp', 'nl-be', 'no', 'pt', 'uk', 'us'], default=None), + hypervisor = dict(choices=['KVM', 'VMware', 'BareMetal', 'XenServer', 'LXC', 'HyperV', 'UCS', 'OVM', 'Simulator'], default=None), + security_groups = dict(type='list', aliases=[ 'security_group' ], default=[]), + affinity_groups = dict(type='list', aliases=[ 'affinity_group' ], default=[]), + domain = dict(default=None), + account = dict(default=None), + project = dict(default=None), + user_data = dict(default=None), + zone = dict(default=None), + ssh_key = dict(default=None), + force = dict(choices=BOOLEANS, default=False), + tags = dict(type='list', aliases=[ 'tag' ], default=None), + poll_async = dict(choices=BOOLEANS, default=True), + )) + + required_together = cs_required_together() + required_together.extend([ + ['cpu', 'cpu_speed', 'memory'], + ]) + module = AnsibleModule( - argument_spec = dict( - name = dict(required=True), - display_name = dict(default=None), - group = dict(default=None), - state = dict(choices=['present', 'deployed', 'started', 'stopped', 'restarted', 'absent', 'destroyed', 'expunged'], default='present'), - service_offering = dict(default=None), - cpu = dict(default=None, type='int'), - cpu_speed = dict(default=None, type='int'), - memory = dict(default=None, type='int'), - template = dict(default=None), - iso = dict(default=None), - networks = dict(type='list', aliases=[ 'network' ], default=None), - ip_to_networks = dict(type='list', aliases=['ip_to_network'], default=None), - ip_address = dict(defaul=None), - ip6_address = dict(defaul=None), - disk_offering = dict(default=None), - disk_size = dict(type='int', default=None), - root_disk_size = dict(type='int', default=None), - keyboard = dict(choices=['de', 'de-ch', 'es', 'fi', 'fr', 'fr-be', 'fr-ch', 'is', 'it', 'jp', 'nl-be', 'no', 'pt', 'uk', 'us'], default=None), - hypervisor = dict(choices=['KVM', 'VMware', 'BareMetal', 'XenServer', 'LXC', 'HyperV', 'UCS', 'OVM', 'Simulator'], default=None), - security_groups = dict(type='list', aliases=[ 'security_group' ], default=[]), - affinity_groups = dict(type='list', aliases=[ 'affinity_group' ], default=[]), - domain = dict(default=None), - account = dict(default=None), - project = dict(default=None), - user_data = dict(default=None), - zone = dict(default=None), - ssh_key = dict(default=None), - force = dict(choices=BOOLEANS, default=False), - tags = dict(type='list', aliases=[ 'tag' ], default=None), - poll_async = dict(choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), + argument_spec=argument_spec, + required_together=required_together, mutually_exclusive = ( ['template', 'iso'], ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ['cpu', 'cpu_speed', 'memory'], - ), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_instancegroup.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_instancegroup.py index f3ac8e4caa..4ffda0ede1 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_instancegroup.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_instancegroup.py @@ -170,23 +170,18 @@ class AnsibleCloudStackInstanceGroup(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name = dict(required=True), + state = dict(default='present', choices=['present', 'absent']), + domain = dict(default=None), + account = dict(default=None), + project = dict(default=None), + )) + module = AnsibleModule( - argument_spec = dict( - name = dict(required=True), - state = dict(default='present', choices=['present', 'absent']), - domain = dict(default=None), - account = dict(default=None), - project = dict(default=None), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_ip_address.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_ip_address.py index 7843dc0db0..a5932b42b3 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_ip_address.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_ip_address.py @@ -224,26 +224,21 @@ class AnsibleCloudStackIPAddress(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + ip_address = dict(required=False), + state = dict(choices=['present', 'absent'], default='present'), + zone = dict(default=None), + domain = dict(default=None), + account = dict(default=None), + network = dict(default=None), + project = dict(default=None), + poll_async = dict(choices=BOOLEANS, default=True), + )) + module = AnsibleModule( - argument_spec = dict( - ip_address = dict(required=False), - state = dict(choices=['present', 'absent'], default='present'), - zone = dict(default=None), - domain = dict(default=None), - account = dict(default=None), - network = dict(default=None), - project = dict(default=None), - poll_async = dict(choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_iso.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_iso.py index 4ce1804c76..98a06f6cd9 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_iso.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_iso.py @@ -295,32 +295,27 @@ class AnsibleCloudStackIso(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name = dict(required=True), + url = dict(default=None), + os_type = dict(default=None), + zone = dict(default=None), + iso_filter = dict(default='self', choices=[ 'featured', 'self', 'selfexecutable','sharedexecutable','executable', 'community' ]), + domain = dict(default=None), + account = dict(default=None), + project = dict(default=None), + checksum = dict(default=None), + is_ready = dict(choices=BOOLEANS, default=False), + bootable = dict(choices=BOOLEANS, default=True), + is_featured = dict(choices=BOOLEANS, default=False), + is_dynamically_scalable = dict(choices=BOOLEANS, default=False), + state = dict(choices=['present', 'absent'], default='present'), + )) + module = AnsibleModule( - argument_spec = dict( - name = dict(required=True), - url = dict(default=None), - os_type = dict(default=None), - zone = dict(default=None), - iso_filter = dict(default='self', choices=[ 'featured', 'self', 'selfexecutable','sharedexecutable','executable', 'community' ]), - domain = dict(default=None), - account = dict(default=None), - project = dict(default=None), - checksum = dict(default=None), - is_ready = dict(choices=BOOLEANS, default=False), - bootable = dict(choices=BOOLEANS, default=True), - is_featured = dict(choices=BOOLEANS, default=False), - is_dynamically_scalable = dict(choices=BOOLEANS, default=False), - state = dict(choices=['present', 'absent'], default='present'), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py index 1cb97bf86e..6dea3dd3ca 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py @@ -522,43 +522,41 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name = dict(required=True), + display_text = dict(default=None), + network_offering = dict(default=None), + zone = dict(default=None), + start_ip = dict(default=None), + end_ip = dict(default=None), + gateway = dict(default=None), + netmask = dict(default=None), + start_ipv6 = dict(default=None), + end_ipv6 = dict(default=None), + cidr_ipv6 = dict(default=None), + gateway_ipv6 = dict(default=None), + vlan = dict(default=None), + vpc = dict(default=None), + isolated_pvlan = dict(default=None), + clean_up = dict(type='bool', choices=BOOLEANS, default=False), + network_domain = dict(default=None), + state = dict(choices=['present', 'absent', 'restarted' ], default='present'), + acl_type = dict(choices=['account', 'domain'], default='account'), + project = dict(default=None), + domain = dict(default=None), + account = dict(default=None), + poll_async = dict(type='bool', choices=BOOLEANS, default=True), + )) + required_together = cs_required_together() + required_together.extend([ + ['start_ip', 'netmask', 'gateway'], + ['start_ipv6', 'cidr_ipv6', 'gateway_ipv6'], + ]) + module = AnsibleModule( - argument_spec = dict( - name = dict(required=True), - display_text = dict(default=None), - network_offering = dict(default=None), - zone = dict(default=None), - start_ip = dict(default=None), - end_ip = dict(default=None), - gateway = dict(default=None), - netmask = dict(default=None), - start_ipv6 = dict(default=None), - end_ipv6 = dict(default=None), - cidr_ipv6 = dict(default=None), - gateway_ipv6 = dict(default=None), - vlan = dict(default=None), - vpc = dict(default=None), - isolated_pvlan = dict(default=None), - clean_up = dict(type='bool', choices=BOOLEANS, default=False), - network_domain = dict(default=None), - state = dict(choices=['present', 'absent', 'restarted' ], default='present'), - acl_type = dict(choices=['account', 'domain'], default='account'), - project = dict(default=None), - domain = dict(default=None), - account = dict(default=None), - poll_async = dict(type='bool', choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ['start_ip', 'netmask', 'gateway'], - ['start_ipv6', 'cidr_ipv6', 'gateway_ipv6'], - ), + argument_spec=argument_spec, + required_together=required_together, supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py index ed590a5d87..2c70d79ddd 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py @@ -368,33 +368,28 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + ip_address = dict(required=True), + protocol= dict(choices=['tcp', 'udp'], default='tcp'), + public_port = dict(type='int', required=True), + public_end_port = dict(type='int', default=None), + private_port = dict(type='int', required=True), + private_end_port = dict(type='int', default=None), + state = dict(choices=['present', 'absent'], default='present'), + open_firewall = dict(choices=BOOLEANS, default=False), + vm_guest_ip = dict(default=None), + vm = dict(default=None), + zone = dict(default=None), + domain = dict(default=None), + account = dict(default=None), + project = dict(default=None), + poll_async = dict(choices=BOOLEANS, default=True), + )) + module = AnsibleModule( - argument_spec = dict( - ip_address = dict(required=True), - protocol= dict(choices=['tcp', 'udp'], default='tcp'), - public_port = dict(type='int', required=True), - public_end_port = dict(type='int', default=None), - private_port = dict(type='int', required=True), - private_end_port = dict(type='int', default=None), - state = dict(choices=['present', 'absent'], default='present'), - open_firewall = dict(choices=BOOLEANS, default=False), - vm_guest_ip = dict(default=None), - vm = dict(default=None), - zone = dict(default=None), - domain = dict(default=None), - account = dict(default=None), - project = dict(default=None), - poll_async = dict(choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py index a7468e6311..504fefc6f0 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py @@ -259,24 +259,19 @@ class AnsibleCloudStackProject(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name = dict(required=True), + display_text = dict(default=None), + state = dict(choices=['present', 'absent', 'active', 'suspended' ], default='present'), + domain = dict(default=None), + account = dict(default=None), + poll_async = dict(type='bool', choices=BOOLEANS, default=True), + )) + module = AnsibleModule( - argument_spec = dict( - name = dict(required=True), - display_text = dict(default=None), - state = dict(choices=['present', 'absent', 'active', 'suspended' ], default='present'), - domain = dict(default=None), - account = dict(default=None), - poll_async = dict(type='bool', choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py index 9dd6a7615d..43efa1ae16 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py @@ -150,22 +150,17 @@ class AnsibleCloudStackSecurityGroup(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name = dict(required=True), + description = dict(default=None), + state = dict(choices=['present', 'absent'], default='present'), + project = dict(default=None), + )) + module = AnsibleModule( - argument_spec = dict( - name = dict(required=True), - description = dict(default=None), - state = dict(choices=['present', 'absent'], default='present'), - project = dict(default=None), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py index a1d6005118..aea9754af9 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py @@ -370,31 +370,29 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + security_group = dict(required=True), + type = dict(choices=['ingress', 'egress'], default='ingress'), + cidr = dict(default='0.0.0.0/0'), + user_security_group = dict(default=None), + protocol = dict(choices=['tcp', 'udp', 'icmp', 'ah', 'esp', 'gre'], default='tcp'), + icmp_type = dict(type='int', default=None), + icmp_code = dict(type='int', default=None), + start_port = dict(type='int', default=None, aliases=['port']), + end_port = dict(type='int', default=None), + state = dict(choices=['present', 'absent'], default='present'), + project = dict(default=None), + poll_async = dict(choices=BOOLEANS, default=True), + )) + required_together = cs_required_together() + required_together.extend([ + ['icmp_type', 'icmp_code'], + ]) + module = AnsibleModule( - argument_spec = dict( - security_group = dict(required=True), - type = dict(choices=['ingress', 'egress'], default='ingress'), - cidr = dict(default='0.0.0.0/0'), - user_security_group = dict(default=None), - protocol = dict(choices=['tcp', 'udp', 'icmp', 'ah', 'esp', 'gre'], default='tcp'), - icmp_type = dict(type='int', default=None), - icmp_code = dict(type='int', default=None), - start_port = dict(type='int', default=None, aliases=['port']), - end_port = dict(type='int', default=None), - state = dict(choices=['present', 'absent'], default='present'), - project = dict(default=None), - poll_async = dict(choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['icmp_type', 'icmp_code'], - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=required_together, mutually_exclusive = ( ['icmp_type', 'start_port'], ['icmp_type', 'end_port'], diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py index a6576404c3..7e665cd62f 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py @@ -205,24 +205,19 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name = dict(required=True), + public_key = dict(default=None), + domain = dict(default=None), + account = dict(default=None), + project = dict(default=None), + state = dict(choices=['present', 'absent'], default='present'), + )) + module = AnsibleModule( - argument_spec = dict( - name = dict(required=True), - public_key = dict(default=None), - domain = dict(default=None), - account = dict(default=None), - project = dict(default=None), - state = dict(choices=['present', 'absent'], default='present'), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_staticnat.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_staticnat.py index c42b743d51..c8fba54885 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_staticnat.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_staticnat.py @@ -259,27 +259,22 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + ip_address = dict(required=True), + vm = dict(default=None), + vm_guest_ip = dict(default=None), + state = dict(choices=['present', 'absent'], default='present'), + zone = dict(default=None), + domain = dict(default=None), + account = dict(default=None), + project = dict(default=None), + poll_async = dict(choices=BOOLEANS, default=True), + )) + module = AnsibleModule( - argument_spec = dict( - ip_address = dict(required=True), - vm = dict(default=None), - vm_guest_ip = dict(default=None), - state = dict(choices=['present', 'absent'], default='present'), - zone = dict(default=None), - domain = dict(default=None), - account = dict(default=None), - project = dict(default=None), - poll_async = dict(choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py index fbaa5665eb..94803aeb9e 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py @@ -529,51 +529,50 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name = dict(required=True), + display_text = dict(default=None), + url = dict(default=None), + vm = dict(default=None), + snapshot = dict(default=None), + os_type = dict(default=None), + is_ready = dict(type='bool', choices=BOOLEANS, default=False), + is_public = dict(type='bool', choices=BOOLEANS, default=True), + is_featured = dict(type='bool', choices=BOOLEANS, default=False), + is_dynamically_scalable = dict(type='bool', choices=BOOLEANS, default=False), + is_extractable = dict(type='bool', choices=BOOLEANS, default=False), + is_routing = dict(type='bool', choices=BOOLEANS, default=False), + checksum = dict(default=None), + template_filter = dict(default='self', choices=['featured', 'self', 'selfexecutable', 'sharedexecutable', 'executable', 'community']), + hypervisor = dict(choices=['KVM', 'VMware', 'BareMetal', 'XenServer', 'LXC', 'HyperV', 'UCS', 'OVM', 'Simulator'], default=None), + requires_hvm = dict(type='bool', choices=BOOLEANS, default=False), + password_enabled = dict(type='bool', choices=BOOLEANS, default=False), + template_tag = dict(default=None), + sshkey_enabled = dict(type='bool', choices=BOOLEANS, default=False), + format = dict(choices=['QCOW2', 'RAW', 'VHD', 'OVA'], default=None), + details = dict(default=None), + bits = dict(type='int', choices=[ 32, 64 ], default=64), + state = dict(choices=['present', 'absent'], default='present'), + cross_zones = dict(type='bool', choices=BOOLEANS, default=False), + zone = dict(default=None), + domain = dict(default=None), + account = dict(default=None), + project = dict(default=None), + poll_async = dict(type='bool', choices=BOOLEANS, default=True), + )) + + required_together = cs_required_together() + required_together.extend([ + ['format', 'url', 'hypervisor'], + ]) + module = AnsibleModule( - argument_spec = dict( - name = dict(required=True), - display_text = dict(default=None), - url = dict(default=None), - vm = dict(default=None), - snapshot = dict(default=None), - os_type = dict(default=None), - is_ready = dict(type='bool', choices=BOOLEANS, default=False), - is_public = dict(type='bool', choices=BOOLEANS, default=True), - is_featured = dict(type='bool', choices=BOOLEANS, default=False), - is_dynamically_scalable = dict(type='bool', choices=BOOLEANS, default=False), - is_extractable = dict(type='bool', choices=BOOLEANS, default=False), - is_routing = dict(type='bool', choices=BOOLEANS, default=False), - checksum = dict(default=None), - template_filter = dict(default='self', choices=['featured', 'self', 'selfexecutable', 'sharedexecutable', 'executable', 'community']), - hypervisor = dict(choices=['KVM', 'VMware', 'BareMetal', 'XenServer', 'LXC', 'HyperV', 'UCS', 'OVM', 'Simulator'], default=None), - requires_hvm = dict(type='bool', choices=BOOLEANS, default=False), - password_enabled = dict(type='bool', choices=BOOLEANS, default=False), - template_tag = dict(default=None), - sshkey_enabled = dict(type='bool', choices=BOOLEANS, default=False), - format = dict(choices=['QCOW2', 'RAW', 'VHD', 'OVA'], default=None), - details = dict(default=None), - bits = dict(type='int', choices=[ 32, 64 ], default=64), - state = dict(choices=['present', 'absent'], default='present'), - cross_zones = dict(type='bool', choices=BOOLEANS, default=False), - zone = dict(default=None), - domain = dict(default=None), - account = dict(default=None), - project = dict(default=None), - poll_async = dict(type='bool', choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), + argument_spec=argument_spec, + required_together=required_together, mutually_exclusive = ( ['url', 'vm'], ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ['format', 'url', 'hypervisor'], - ), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_user.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_user.py index 43e83c0678..e6fe1c1f51 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_user.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_user.py @@ -404,28 +404,23 @@ class AnsibleCloudStackUser(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + username = dict(required=True), + account = dict(default=None), + state = dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked'], default='present'), + domain = dict(default='ROOT'), + email = dict(default=None), + first_name = dict(default=None), + last_name = dict(default=None), + password = dict(default=None), + timezone = dict(default=None), + poll_async = dict(choices=BOOLEANS, default=True), + )) + module = AnsibleModule( - argument_spec = dict( - username = dict(required=True), - account = dict(default=None), - state = dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked'], default='present'), - domain = dict(default='ROOT'), - email = dict(default=None), - first_name = dict(default=None), - last_name = dict(default=None), - password = dict(default=None), - timezone = dict(default=None), - poll_async = dict(choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=cs_required_together(), supports_check_mode=True ) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py index dbbbe4f96f..5a4c51885f 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py @@ -256,29 +256,28 @@ class AnsibleCloudStackVmSnapshot(AnsibleCloudStack): def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name = dict(required=True, aliases=['display_name']), + vm = dict(required=True), + description = dict(default=None), + zone = dict(default=None), + snapshot_memory = dict(choices=BOOLEANS, default=False), + state = dict(choices=['present', 'absent', 'revert'], default='present'), + domain = dict(default=None), + account = dict(default=None), + project = dict(default=None), + poll_async = dict(type='bool', choices=BOOLEANS, default=True), + )) + + required_together = cs_required_together() + required_together.extend([ + ['icmp_type', 'icmp_code'], + ]) + module = AnsibleModule( - argument_spec = dict( - name = dict(required=True, aliases=['display_name']), - vm = dict(required=True), - description = dict(default=None), - zone = dict(default=None), - snapshot_memory = dict(choices=BOOLEANS, default=False), - state = dict(choices=['present', 'absent', 'revert'], default='present'), - domain = dict(default=None), - account = dict(default=None), - project = dict(default=None), - poll_async = dict(choices=BOOLEANS, default=True), - api_key = dict(default=None), - api_secret = dict(default=None, no_log=True), - api_url = dict(default=None), - api_http_method = dict(choices=['get', 'post'], default='get'), - api_timeout = dict(type='int', default=10), - api_region = dict(default='cloudstack'), - ), - required_together = ( - ['icmp_type', 'icmp_code'], - ['api_key', 'api_secret', 'api_url'], - ), + argument_spec=argument_spec, + required_together=required_together, supports_check_mode=True )