Merge pull request #1384 from resmo/for-ansible

[stable-2.0] cloudstack: fixes and improvements
This commit is contained in:
Brian Coca 2015-12-16 08:11:11 -05:00
commit fef9c99d00
20 changed files with 68 additions and 72 deletions

View file

@ -356,7 +356,7 @@ def main():
username = dict(default=None), username = dict(default=None),
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(type='bool', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -390,7 +390,7 @@ def main():
result = acs_acc.get_result(account) result = acs_acc.get_result(account)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -233,7 +233,7 @@ 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', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -256,7 +256,7 @@ def main():
result = acs_ag.get_result(affinity_group) result = acs_ag.get_result(affinity_group)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -244,8 +244,8 @@ def main():
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(type='bool', default=False),
poll_async = dict(choices=BOOLEANS, default=True), poll_async = dict(type='bool', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -268,7 +268,7 @@ def main():
result = acs_dom.get_result(domain) result = acs_dom.get_result(domain)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -414,7 +414,7 @@ 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', default=True),
)) ))
required_together = cs_required_together() required_together = cs_required_together()
@ -450,7 +450,7 @@ def main():
result = acs_fw.get_result(fw_rule) result = acs_fw.get_result(fw_rule)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -44,7 +44,6 @@ options:
state: state:
description: description:
- State of the instance. - State of the instance.
- C(restored) added in version 2.1.
required: false required: false
default: 'present' default: 'present'
choices: [ 'deployed', 'started', 'stopped', 'restarted', 'restored', 'destroyed', 'expunged', 'present', 'absent' ] choices: [ 'deployed', 'started', 'stopped', 'restarted', 'restored', 'destroyed', 'expunged', 'present', 'absent' ]
@ -827,13 +826,9 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
def restore_instance(self): def restore_instance(self):
instance = self.get_instance() instance = self.get_instance()
if not instance:
instance = self.deploy_instance()
return instance
self.result['changed'] = True self.result['changed'] = True
# in check mode intance may not be instanciated
if instance:
args = {} args = {}
args['templateid'] = self.get_template_or_iso(key='id') args['templateid'] = self.get_template_or_iso(key='id')
args['virtualmachineid'] = instance['id'] args['virtualmachineid'] = instance['id']
@ -897,9 +892,9 @@ def main():
user_data = dict(default=None), user_data = dict(default=None),
zone = dict(default=None), zone = dict(default=None),
ssh_key = dict(default=None), ssh_key = dict(default=None),
force = dict(choices=BOOLEANS, default=False), force = dict(type='bool', 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(type='bool', default=True),
)) ))
required_together = cs_required_together() required_together = cs_required_together()
@ -931,6 +926,7 @@ def main():
instance = acs_instance.expunge_instance() instance = acs_instance.expunge_instance()
elif state in ['restored']: elif state in ['restored']:
acs_instance.present_instance()
instance = acs_instance.restore_instance() instance = acs_instance.restore_instance()
elif state in ['present', 'deployed']: elif state in ['present', 'deployed']:
@ -953,7 +949,7 @@ def main():
result = acs_instance.get_result(instance) result = acs_instance.get_result(instance)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -199,7 +199,7 @@ def main():
result = acs_ig.get_result(instance_group) result = acs_ig.get_result(instance_group)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -233,7 +233,7 @@ def main():
account = dict(default=None), account = dict(default=None),
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(type='bool', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -256,7 +256,7 @@ def main():
result = acs_ip_address.get_result(ip_address) result = acs_ip_address.get_result(ip_address)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -306,10 +306,10 @@ def main():
account = dict(default=None), account = dict(default=None),
project = dict(default=None), project = dict(default=None),
checksum = dict(default=None), checksum = dict(default=None),
is_ready = dict(choices=BOOLEANS, default=False), is_ready = dict(type='bool', default=False),
bootable = dict(choices=BOOLEANS, default=True), bootable = dict(type='bool', default=True),
is_featured = dict(choices=BOOLEANS, default=False), is_featured = dict(type='bool', default=False),
is_dynamically_scalable = dict(choices=BOOLEANS, default=False), is_dynamically_scalable = dict(type='bool', default=False),
state = dict(choices=['present', 'absent'], default='present'), state = dict(choices=['present', 'absent'], default='present'),
)) ))
@ -333,7 +333,7 @@ def main():
result = acs_iso.get_result(iso) result = acs_iso.get_result(iso)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -355,12 +355,12 @@ def main():
ip_address = dict(required=True, aliases=['public_ip']), ip_address = dict(required=True, aliases=['public_ip']),
cidr = dict(default=None), cidr = dict(default=None),
project = dict(default=None), project = dict(default=None),
open_firewall = dict(choices=BOOLEANS, default=False), open_firewall = dict(type='bool', default=False),
tags = dict(type='list', aliases=['tag'], default=None), tags = dict(type='list', aliases=['tag'], default=None),
zone = dict(default=None), zone = dict(default=None),
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(type='bool', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -383,7 +383,7 @@ def main():
result = acs_lb_rule.get_result(rule) result = acs_lb_rule.get_result(rule)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -335,7 +335,7 @@ def main():
domain = dict(default=None), domain = dict(default=None),
project = dict(default=None), project = dict(default=None),
account = dict(default=None), account = dict(default=None),
poll_async = dict(choices=BOOLEANS, default=True), poll_async = dict(type='bool', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -358,7 +358,7 @@ def main():
result = acs_lb_rule_member.get_result(rule) result = acs_lb_rule_member.get_result(rule)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -539,14 +539,14 @@ def main():
vlan = dict(default=None), vlan = dict(default=None),
vpc = dict(default=None), vpc = dict(default=None),
isolated_pvlan = dict(default=None), isolated_pvlan = dict(default=None),
clean_up = dict(type='bool', choices=BOOLEANS, default=False), clean_up = dict(type='bool', default=False),
network_domain = dict(default=None), network_domain = dict(default=None),
state = dict(choices=['present', 'absent', 'restarted' ], default='present'), state = dict(choices=['present', 'absent', 'restarted' ], default='present'),
acl_type = dict(choices=['account', 'domain'], default='account'), acl_type = dict(choices=['account', 'domain'], default='account'),
project = dict(default=None), project = dict(default=None),
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', default=True),
)) ))
required_together = cs_required_together() required_together = cs_required_together()
required_together.extend([ required_together.extend([
@ -578,7 +578,7 @@ def main():
result = acs_network.get_result(network) result = acs_network.get_result(network)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -376,14 +376,14 @@ def main():
private_port = dict(type='int', required=True), private_port = dict(type='int', required=True),
private_end_port = dict(type='int', default=None), private_end_port = dict(type='int', default=None),
state = dict(choices=['present', 'absent'], default='present'), state = dict(choices=['present', 'absent'], default='present'),
open_firewall = dict(choices=BOOLEANS, default=False), open_firewall = dict(type='bool', default=False),
vm_guest_ip = dict(default=None), vm_guest_ip = dict(default=None),
vm = dict(default=None), vm = dict(default=None),
zone = dict(default=None), zone = 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),
poll_async = dict(choices=BOOLEANS, default=True), poll_async = dict(type='bool', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -405,7 +405,7 @@ def main():
result = acs_pf.get_result(pf_rule) result = acs_pf.get_result(pf_rule)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -266,7 +266,7 @@ def main():
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', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -293,7 +293,7 @@ def main():
result = acs_project.get_result(project) result = acs_project.get_result(project)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -180,7 +180,7 @@ def main():
result = acs_sg.get_result(sg) result = acs_sg.get_result(sg)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -384,7 +384,7 @@ def main():
end_port = dict(type='int', default=None), end_port = dict(type='int', default=None),
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(type='bool', default=True),
)) ))
required_together = cs_required_together() required_together = cs_required_together()
required_together.extend([ required_together.extend([
@ -417,7 +417,7 @@ def main():
result = acs_sg_rule.get_result(sg_rule) result = acs_sg_rule.get_result(sg_rule)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -241,7 +241,7 @@ def main():
result = acs_sshkey.get_result(ssh_key) result = acs_sshkey.get_result(ssh_key)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -269,7 +269,7 @@ 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', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -292,7 +292,7 @@ def main():
result = acs_static_nat.get_result(ip_address) result = acs_static_nat.get_result(ip_address)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -537,29 +537,29 @@ def main():
vm = dict(default=None), vm = dict(default=None),
snapshot = dict(default=None), snapshot = dict(default=None),
os_type = dict(default=None), os_type = dict(default=None),
is_ready = dict(type='bool', choices=BOOLEANS, default=False), is_ready = dict(type='bool', default=False),
is_public = dict(type='bool', choices=BOOLEANS, default=True), is_public = dict(type='bool', default=True),
is_featured = dict(type='bool', choices=BOOLEANS, default=False), is_featured = dict(type='bool', default=False),
is_dynamically_scalable = dict(type='bool', choices=BOOLEANS, default=False), is_dynamically_scalable = dict(type='bool', default=False),
is_extractable = dict(type='bool', choices=BOOLEANS, default=False), is_extractable = dict(type='bool', default=False),
is_routing = dict(type='bool', choices=BOOLEANS, default=False), is_routing = dict(type='bool', default=False),
checksum = dict(default=None), checksum = dict(default=None),
template_filter = dict(default='self', choices=['featured', 'self', 'selfexecutable', 'sharedexecutable', 'executable', 'community']), 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), hypervisor = dict(choices=['KVM', 'VMware', 'BareMetal', 'XenServer', 'LXC', 'HyperV', 'UCS', 'OVM', 'Simulator'], default=None),
requires_hvm = dict(type='bool', choices=BOOLEANS, default=False), requires_hvm = dict(type='bool', default=False),
password_enabled = dict(type='bool', choices=BOOLEANS, default=False), password_enabled = dict(type='bool', default=False),
template_tag = dict(default=None), template_tag = dict(default=None),
sshkey_enabled = dict(type='bool', choices=BOOLEANS, default=False), sshkey_enabled = dict(type='bool', default=False),
format = dict(choices=['QCOW2', 'RAW', 'VHD', 'OVA'], default=None), format = dict(choices=['QCOW2', 'RAW', 'VHD', 'OVA'], default=None),
details = dict(default=None), details = dict(default=None),
bits = dict(type='int', choices=[ 32, 64 ], default=64), bits = dict(type='int', choices=[ 32, 64 ], default=64),
state = dict(choices=['present', 'absent'], default='present'), state = dict(choices=['present', 'absent'], default='present'),
cross_zones = dict(type='bool', choices=BOOLEANS, default=False), cross_zones = dict(type='bool', default=False),
zone = dict(default=None), zone = 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),
poll_async = dict(type='bool', choices=BOOLEANS, default=True), poll_async = dict(type='bool', default=True),
)) ))
required_together = cs_required_together() required_together = cs_required_together()
@ -595,7 +595,7 @@ def main():
result = acs_tpl.get_result(tpl) result = acs_tpl.get_result(tpl)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -415,7 +415,7 @@ def main():
last_name = dict(default=None), last_name = dict(default=None),
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(type='bool', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -449,7 +449,7 @@ def main():
result = acs_acc.get_result(user) result = acs_acc.get_result(user)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

View file

@ -263,12 +263,12 @@ def main():
vm = dict(required=True), vm = dict(required=True),
description = dict(default=None), description = dict(default=None),
zone = dict(default=None), zone = dict(default=None),
snapshot_memory = dict(choices=BOOLEANS, default=False), snapshot_memory = dict(type='bool', default=False),
state = dict(choices=['present', 'absent', 'revert'], default='present'), state = dict(choices=['present', 'absent', 'revert'], default='present'),
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(type='bool', choices=BOOLEANS, default=True), poll_async = dict(type='bool', default=True),
)) ))
required_together = cs_required_together() required_together = cs_required_together()
@ -298,7 +298,7 @@ def main():
result = acs_vmsnapshot.get_result(snapshot) result = acs_vmsnapshot.get_result(snapshot)
except CloudStackException, e: except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e)) module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)