cloudstack: implement common argument spec handling

This commit is contained in:
Rene Moser 2015-09-22 16:28:14 +02:00 committed by Matt Clay
parent 6e4c78d165
commit a134a71187
18 changed files with 356 additions and 424 deletions

View file

@ -343,8 +343,8 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
name = dict(required=True), name = dict(required=True),
state = dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked'], default='present'), state = dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked'], default='present'),
account_type = dict(choices=['user', 'root_admin', 'domain_admin'], default='user'), account_type = dict(choices=['user', 'root_admin', 'domain_admin'], default='user'),
@ -357,16 +357,11 @@ def main():
password = dict(default=None), password = dict(default=None),
timezone = dict(default=None), timezone = dict(default=None),
poll_async = dict(choices=BOOLEANS, default=True), 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -200,8 +200,8 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
name = dict(required=True), name = dict(required=True),
affinty_type = dict(default=None), affinty_type = dict(default=None),
description = dict(default=None), description = dict(default=None),
@ -209,16 +209,11 @@ def main():
domain = dict(default=None), domain = dict(default=None),
account = dict(default=None), account = dict(default=None),
poll_async = dict(choices=BOOLEANS, default=True), 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -239,23 +239,18 @@ class AnsibleCloudStackDomain(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
path = dict(required=True), path = dict(required=True),
state = dict(choices=['present', 'absent'], default='present'), state = dict(choices=['present', 'absent'], default='present'),
network_domain = dict(default=None), network_domain = dict(default=None),
clean_up = dict(choices=BOOLEANS, default=False), clean_up = dict(choices=BOOLEANS, default=False),
poll_async = dict(choices=BOOLEANS, default=True), 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -391,8 +391,8 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
ip_address = dict(default=None), ip_address = dict(default=None),
network = dict(default=None), network = dict(default=None),
cidr = dict(default='0.0.0.0/0'), cidr = dict(default='0.0.0.0/0'),
@ -407,20 +407,19 @@ def main():
account = dict(default=None), account = dict(default=None),
project = dict(default=None), project = dict(default=None),
poll_async = dict(choices=BOOLEANS, default=True), 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), required_together = cs_required_together()
api_http_method = dict(choices=['get', 'post'], default='get'), required_together.extend([
api_timeout = dict(type='int', default=10), ['icmp_type', 'icmp_code'],
api_region = dict(default='cloudstack'), ])
),
module = AnsibleModule(
argument_spec=argument_spec,
required_together=required_together,
required_one_of = ( required_one_of = (
['ip_address', 'network'], ['ip_address', 'network'],
), ),
required_together = (
['icmp_type', 'icmp_code'],
['api_key', 'api_secret', 'api_url'],
),
mutually_exclusive = ( mutually_exclusive = (
['icmp_type', 'start_port'], ['icmp_type', 'start_port'],
['icmp_type', 'end_port'], ['icmp_type', 'end_port'],

View file

@ -818,8 +818,8 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
return self.result return self.result
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
name = dict(required=True), name = dict(required=True),
display_name = dict(default=None), display_name = dict(default=None),
group = dict(default=None), group = dict(default=None),
@ -850,20 +850,19 @@ def main():
force = dict(choices=BOOLEANS, default=False), force = dict(choices=BOOLEANS, default=False),
tags = dict(type='list', aliases=[ 'tag' ], default=None), tags = dict(type='list', aliases=[ 'tag' ], default=None),
poll_async = dict(choices=BOOLEANS, default=True), 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), required_together = cs_required_together()
api_http_method = dict(choices=['get', 'post'], default='get'), required_together.extend([
api_timeout = dict(type='int', default=10), ['cpu', 'cpu_speed', 'memory'],
api_region = dict(default='cloudstack'), ])
),
module = AnsibleModule(
argument_spec=argument_spec,
required_together=required_together,
mutually_exclusive = ( mutually_exclusive = (
['template', 'iso'], ['template', 'iso'],
), ),
required_together = (
['api_key', 'api_secret', 'api_url'],
['cpu', 'cpu_speed', 'memory'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -170,23 +170,18 @@ class AnsibleCloudStackInstanceGroup(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
name = dict(required=True), name = dict(required=True),
state = dict(default='present', choices=['present', 'absent']), state = dict(default='present', choices=['present', 'absent']),
domain = dict(default=None), domain = dict(default=None),
account = dict(default=None), account = dict(default=None),
project = 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -224,8 +224,8 @@ class AnsibleCloudStackIPAddress(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
ip_address = dict(required=False), ip_address = dict(required=False),
state = dict(choices=['present', 'absent'], default='present'), state = dict(choices=['present', 'absent'], default='present'),
zone = dict(default=None), zone = dict(default=None),
@ -234,16 +234,11 @@ def main():
network = dict(default=None), network = dict(default=None),
project = dict(default=None), project = dict(default=None),
poll_async = dict(choices=BOOLEANS, default=True), 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -295,8 +295,8 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
name = dict(required=True), name = dict(required=True),
url = dict(default=None), url = dict(default=None),
os_type = dict(default=None), os_type = dict(default=None),
@ -311,16 +311,11 @@ def main():
is_featured = dict(choices=BOOLEANS, default=False), is_featured = dict(choices=BOOLEANS, default=False),
is_dynamically_scalable = dict(choices=BOOLEANS, default=False), is_dynamically_scalable = dict(choices=BOOLEANS, default=False),
state = dict(choices=['present', 'absent'], default='present'), 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -522,8 +522,8 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
name = dict(required=True), name = dict(required=True),
display_text = dict(default=None), display_text = dict(default=None),
network_offering = dict(default=None), network_offering = dict(default=None),
@ -547,18 +547,16 @@ def main():
domain = dict(default=None), domain = dict(default=None),
account = dict(default=None), account = dict(default=None),
poll_async = dict(type='bool', choices=BOOLEANS, default=True), poll_async = dict(type='bool', choices=BOOLEANS, default=True),
api_key = dict(default=None), ))
api_secret = dict(default=None, no_log=True), required_together = cs_required_together()
api_url = dict(default=None), required_together.extend([
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_ip', 'netmask', 'gateway'],
['start_ipv6', 'cidr_ipv6', 'gateway_ipv6'], ['start_ipv6', 'cidr_ipv6', 'gateway_ipv6'],
), ])
module = AnsibleModule(
argument_spec=argument_spec,
required_together=required_together,
supports_check_mode=True supports_check_mode=True
) )

View file

@ -368,8 +368,8 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
ip_address = dict(required=True), ip_address = dict(required=True),
protocol= dict(choices=['tcp', 'udp'], default='tcp'), protocol= dict(choices=['tcp', 'udp'], default='tcp'),
public_port = dict(type='int', required=True), public_port = dict(type='int', required=True),
@ -385,16 +385,11 @@ def main():
account = dict(default=None), account = dict(default=None),
project = dict(default=None), project = dict(default=None),
poll_async = dict(choices=BOOLEANS, default=True), 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -259,24 +259,19 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
name = dict(required=True), name = dict(required=True),
display_text = dict(default=None), display_text = dict(default=None),
state = dict(choices=['present', 'absent', 'active', 'suspended' ], default='present'), state = dict(choices=['present', 'absent', 'active', 'suspended' ], default='present'),
domain = dict(default=None), domain = dict(default=None),
account = dict(default=None), account = dict(default=None),
poll_async = dict(type='bool', choices=BOOLEANS, default=True), 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -150,22 +150,17 @@ class AnsibleCloudStackSecurityGroup(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
name = dict(required=True), name = dict(required=True),
description = dict(default=None), description = dict(default=None),
state = dict(choices=['present', 'absent'], default='present'), state = dict(choices=['present', 'absent'], default='present'),
project = 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -370,8 +370,8 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
security_group = dict(required=True), security_group = dict(required=True),
type = dict(choices=['ingress', 'egress'], default='ingress'), type = dict(choices=['ingress', 'egress'], default='ingress'),
cidr = dict(default='0.0.0.0/0'), cidr = dict(default='0.0.0.0/0'),
@ -384,17 +384,15 @@ def main():
state = dict(choices=['present', 'absent'], default='present'), state = dict(choices=['present', 'absent'], default='present'),
project = dict(default=None), project = dict(default=None),
poll_async = dict(choices=BOOLEANS, default=True), poll_async = dict(choices=BOOLEANS, default=True),
api_key = dict(default=None), ))
api_secret = dict(default=None, no_log=True), required_together = cs_required_together()
api_url = dict(default=None), required_together.extend([
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'], ['icmp_type', 'icmp_code'],
['api_key', 'api_secret', 'api_url'], ])
),
module = AnsibleModule(
argument_spec=argument_spec,
required_together=required_together,
mutually_exclusive = ( mutually_exclusive = (
['icmp_type', 'start_port'], ['icmp_type', 'start_port'],
['icmp_type', 'end_port'], ['icmp_type', 'end_port'],

View file

@ -205,24 +205,19 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
name = dict(required=True), name = dict(required=True),
public_key = dict(default=None), public_key = dict(default=None),
domain = dict(default=None), domain = dict(default=None),
account = dict(default=None), account = dict(default=None),
project = dict(default=None), project = dict(default=None),
state = dict(choices=['present', 'absent'], default='present'), 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -259,8 +259,8 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
ip_address = dict(required=True), ip_address = dict(required=True),
vm = dict(default=None), vm = dict(default=None),
vm_guest_ip = dict(default=None), vm_guest_ip = dict(default=None),
@ -270,16 +270,11 @@ def main():
account = dict(default=None), account = dict(default=None),
project = dict(default=None), project = dict(default=None),
poll_async = dict(choices=BOOLEANS, default=True), 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -529,8 +529,8 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
name = dict(required=True), name = dict(required=True),
display_text = dict(default=None), display_text = dict(default=None),
url = dict(default=None), url = dict(default=None),
@ -560,20 +560,19 @@ def main():
account = dict(default=None), account = dict(default=None),
project = dict(default=None), project = dict(default=None),
poll_async = dict(type='bool', choices=BOOLEANS, default=True), poll_async = dict(type='bool', choices=BOOLEANS, default=True),
api_key = dict(default=None), ))
api_secret = dict(default=None),
api_url = dict(default=None), required_together = cs_required_together()
api_http_method = dict(choices=['get', 'post'], default='get'), required_together.extend([
api_timeout = dict(type='int', default=10), ['format', 'url', 'hypervisor'],
api_region = dict(default='cloudstack'), ])
),
module = AnsibleModule(
argument_spec=argument_spec,
required_together=required_together,
mutually_exclusive = ( mutually_exclusive = (
['url', 'vm'], ['url', 'vm'],
), ),
required_together = (
['api_key', 'api_secret', 'api_url'],
['format', 'url', 'hypervisor'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -404,8 +404,8 @@ class AnsibleCloudStackUser(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
username = dict(required=True), username = dict(required=True),
account = dict(default=None), account = dict(default=None),
state = dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked'], default='present'), state = dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked'], default='present'),
@ -416,16 +416,11 @@ def main():
password = dict(default=None), password = dict(default=None),
timezone = dict(default=None), timezone = dict(default=None),
poll_async = dict(choices=BOOLEANS, default=True), 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), module = AnsibleModule(
api_http_method = dict(choices=['get', 'post'], default='get'), argument_spec=argument_spec,
api_timeout = dict(type='int', default=10), required_together=cs_required_together(),
api_region = dict(default='cloudstack'),
),
required_together = (
['api_key', 'api_secret', 'api_url'],
),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -256,8 +256,8 @@ class AnsibleCloudStackVmSnapshot(AnsibleCloudStack):
def main(): def main():
module = AnsibleModule( argument_spec = cs_argument_spec()
argument_spec = dict( argument_spec.update(dict(
name = dict(required=True, aliases=['display_name']), name = dict(required=True, aliases=['display_name']),
vm = dict(required=True), vm = dict(required=True),
description = dict(default=None), description = dict(default=None),
@ -267,18 +267,17 @@ def main():
domain = dict(default=None), domain = dict(default=None),
account = dict(default=None), account = dict(default=None),
project = dict(default=None), project = dict(default=None),
poll_async = dict(choices=BOOLEANS, default=True), 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), required_together = cs_required_together()
api_http_method = dict(choices=['get', 'post'], default='get'), required_together.extend([
api_timeout = dict(type='int', default=10),
api_region = dict(default='cloudstack'),
),
required_together = (
['icmp_type', 'icmp_code'], ['icmp_type', 'icmp_code'],
['api_key', 'api_secret', 'api_url'], ])
),
module = AnsibleModule(
argument_spec=argument_spec,
required_together=required_together,
supports_check_mode=True supports_check_mode=True
) )