From aca98e2f8e1f310e65fe1847d8ca628b6ee4762e Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Thu, 9 Jun 2016 22:39:03 +0200 Subject: [PATCH] cloudstack: use poll_job() from utils --- .../extras/cloud/cloudstack/cs_account.py | 4 +-- .../cloud/cloudstack/cs_affinitygroup.py | 4 +-- .../extras/cloud/cloudstack/cs_domain.py | 2 +- .../extras/cloud/cloudstack/cs_firewall.py | 4 +-- .../extras/cloud/cloudstack/cs_instance.py | 29 +++++++------------ .../extras/cloud/cloudstack/cs_ip_address.py | 4 +-- .../cloud/cloudstack/cs_loadbalancer_rule.py | 2 +- .../extras/cloud/cloudstack/cs_network.py | 6 ++-- .../extras/cloud/cloudstack/cs_portforward.py | 6 ++-- .../extras/cloud/cloudstack/cs_project.py | 8 ++--- .../extras/cloud/cloudstack/cs_router.py | 8 ++--- .../cloud/cloudstack/cs_securitygroup_rule.py | 4 +-- .../extras/cloud/cloudstack/cs_staticnat.py | 4 +-- .../extras/cloud/cloudstack/cs_template.py | 6 ++-- .../extras/cloud/cloudstack/cs_user.py | 2 +- .../extras/cloud/cloudstack/cs_vmsnapshot.py | 6 ++-- 16 files changed, 46 insertions(+), 53 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py index 28851a9cef..7e3e7e7a8d 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py @@ -261,7 +261,7 @@ class AnsibleCloudStackAccount(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - account = self._poll_job(account, 'account') + account = self.poll_job(account, 'account') return account def present_account(self): @@ -311,7 +311,7 @@ class AnsibleCloudStackAccount(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - self._poll_job(res, 'account') + self.poll_job(res, 'account') return account def get_result(self, account): diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py index 1eb852edfe..0db8977554 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py @@ -163,7 +163,7 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if res and poll_async: - affinity_group = self._poll_job(res, 'affinitygroup') + affinity_group = self.poll_job(res, 'affinitygroup') return affinity_group def remove_affinity_group(self): @@ -185,7 +185,7 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if res and poll_async: - self._poll_job(res, 'affinitygroup') + self.poll_job(res, 'affinitygroup') return affinity_group diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_domain.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_domain.py index 17a5870f27..648116013a 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_domain.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_domain.py @@ -227,7 +227,7 @@ class AnsibleCloudStackDomain(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - res = self._poll_job(res, 'domain') + res = self.poll_job(res, 'domain') return domain diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py index d81c78d644..6989b2d438 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py @@ -324,7 +324,7 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - firewall_rule = self._poll_job(res, 'firewallrule') + firewall_rule = self.poll_job(res, 'firewallrule') return firewall_rule @@ -348,7 +348,7 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - res = self._poll_job(res, 'firewallrule') + res = self.poll_job(res, 'firewallrule') return firewall_rule diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py index 87e26ad228..1b7d23a1c2 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py @@ -667,7 +667,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - instance = self._poll_job(instance, 'virtualmachine') + instance = self.poll_job(instance, 'virtualmachine') return instance @@ -716,7 +716,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): # Ensure VM has stopped instance = self.stop_instance() - instance = self._poll_job(instance, 'virtualmachine') + instance = self.poll_job(instance, 'virtualmachine') self.instance = instance # Change service offering @@ -743,7 +743,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): if 'errortext' in instance: self.module.fail_json(msg="Failed: '%s'" % instance['errortext']) - instance = self._poll_job(instance, 'virtualmachine') + instance = self.poll_job(instance, 'virtualmachine') self.instance = instance # Start VM again if it was running before @@ -776,7 +776,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - instance = self._poll_job(res, 'virtualmachine') + instance = self.poll_job(res, 'virtualmachine') return instance @@ -799,7 +799,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - res = self._poll_job(res, 'virtualmachine') + res = self.poll_job(res, 'virtualmachine') return instance @@ -820,7 +820,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - instance = self._poll_job(instance, 'virtualmachine') + instance = self.poll_job(instance, 'virtualmachine') return instance @@ -841,7 +841,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - instance = self._poll_job(instance, 'virtualmachine') + instance = self.poll_job(instance, 'virtualmachine') return instance @@ -859,7 +859,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - instance = self._poll_job(instance, 'virtualmachine') + instance = self.poll_job(instance, 'virtualmachine') elif instance['state'].lower() in [ 'stopping', 'stopped' ]: instance = self.start_instance() @@ -875,16 +875,9 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): self.result['changed'] = True - args = {} - args['templateid'] = self.get_template_or_iso(key='id') - args['virtualmachineid'] = instance['id'] - res = self.cs.restoreVirtualMachine(**args) - if 'errortext' in res: - self.module.fail_json(msg="Failed: '%s'" % res['errortext']) - - poll_async = self.module.params.get('poll_async') - if poll_async: - instance = self._poll_job(res, 'virtualmachine') + poll_async = self.module.params.get('poll_async') + if poll_async: + instance = self.poll_job(res, 'virtualmachine') return instance 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 345d793a65..bd3a4427e1 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_ip_address.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_ip_address.py @@ -202,7 +202,7 @@ class AnsibleCloudStackIPAddress(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - res = self._poll_job(res, 'ipaddress') + res = self.poll_job(res, 'ipaddress') ip_address = res return ip_address @@ -221,7 +221,7 @@ class AnsibleCloudStackIPAddress(AnsibleCloudStack): self.module.fail_json(msg="Failed: '%s'" % res['errortext']) poll_async = self.module.params.get('poll_async') if poll_async: - self._poll_job(res, 'ipaddress') + self.poll_job(res, 'ipaddress') return ip_address diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_loadbalancer_rule.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_loadbalancer_rule.py index 7255704b76..6a5bff3657 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_loadbalancer_rule.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_loadbalancer_rule.py @@ -327,7 +327,7 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack): self.module.fail_json(msg="Failed: '%s'" % res['errortext']) poll_async = self.module.params.get('poll_async') if poll_async: - res = self._poll_job(res, 'loadbalancer') + res = self.poll_job(res, 'loadbalancer') return rule diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py index 6f97240b8e..b435a05cfc 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py @@ -432,7 +432,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if network and poll_async: - network = self._poll_job(network, 'network') + network = self.poll_job(network, 'network') return network @@ -490,7 +490,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if network and poll_async: - network = self._poll_job(network, 'network') + network = self.poll_job(network, 'network') return network @@ -510,7 +510,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if res and poll_async: - res = self._poll_job(res, 'network') + res = self.poll_job(res, 'network') return network diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py index f0c1b048f0..0d3dfaaa94 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py @@ -305,7 +305,7 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack): portforwarding_rule = self.cs.createPortForwardingRule(**args) poll_async = self.module.params.get('poll_async') if poll_async: - portforwarding_rule = self._poll_job(portforwarding_rule, 'portforwardingrule') + portforwarding_rule = self.poll_job(portforwarding_rule, 'portforwardingrule') return portforwarding_rule @@ -329,7 +329,7 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack): portforwarding_rule = self.cs.createPortForwardingRule(**args) poll_async = self.module.params.get('poll_async') if poll_async: - portforwarding_rule = self._poll_job(portforwarding_rule, 'portforwardingrule') + portforwarding_rule = self.poll_job(portforwarding_rule, 'portforwardingrule') return portforwarding_rule @@ -345,7 +345,7 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack): res = self.cs.deletePortForwardingRule(**args) poll_async = self.module.params.get('poll_async') if poll_async: - self._poll_job(res, 'portforwardingrule') + self.poll_job(res, 'portforwardingrule') return portforwarding_rule diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py index fed2cd0c5f..3ed62f7924 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py @@ -193,7 +193,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if project and poll_async: - project = self._poll_job(project, 'project') + project = self.poll_job(project, 'project') return project @@ -214,7 +214,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if project and poll_async: - project = self._poll_job(project, 'project') + project = self.poll_job(project, 'project') return project @@ -238,7 +238,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if project and poll_async: - project = self._poll_job(project, 'project') + project = self.poll_job(project, 'project') return project @@ -258,7 +258,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if res and poll_async: - res = self._poll_job(res, 'project') + res = self.poll_job(res, 'project') return project diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_router.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_router.py index 29ac096c15..73575c8001 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_router.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_router.py @@ -227,7 +227,7 @@ class AnsibleCloudStackRouter(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - router = self._poll_job(res, 'router') + router = self.poll_job(res, 'router') return router def stop_router(self): @@ -248,7 +248,7 @@ class AnsibleCloudStackRouter(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - router = self._poll_job(res, 'router') + router = self.poll_job(res, 'router') return router def reboot_router(self): @@ -268,7 +268,7 @@ class AnsibleCloudStackRouter(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - router = self._poll_job(res, 'router') + router = self.poll_job(res, 'router') return router def absent_router(self): @@ -287,7 +287,7 @@ class AnsibleCloudStackRouter(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - self._poll_job(res, 'router') + self.poll_job(res, 'router') return router 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 d08649511c..a822161103 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py @@ -322,7 +322,7 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if res and poll_async: - security_group = self._poll_job(res, 'securitygroup') + security_group = self.poll_job(res, 'securitygroup') key = sg_type + "rule" # ingressrule / egressrule if key in security_group: rule = security_group[key][0] @@ -353,7 +353,7 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if res and poll_async: - res = self._poll_job(res, 'securitygroup') + res = self.poll_job(res, 'securitygroup') return rule diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_staticnat.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_staticnat.py index da17c76a57..1de6c16ff6 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_staticnat.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_staticnat.py @@ -223,7 +223,7 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack): res = self.cs.disableStaticNat(ipaddressid=ip_address['id']) if 'errortext' in res: self.module.fail_json(msg="Failed: '%s'" % res['errortext']) - self._poll_job(res, 'staticnat') + self.poll_job(res, 'staticnat') res = self.cs.enableStaticNat(**args) if 'errortext' in res: self.module.fail_json(msg="Failed: '%s'" % res['errortext']) @@ -253,7 +253,7 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack): self.module.fail_json(msg="Failed: '%s'" % res['errortext']) poll_async = self.module.params.get('poll_async') if poll_async: - self._poll_job(res, 'staticnat') + self.poll_job(res, 'staticnat') return ip_address diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py index 2a2a6e29be..8d7eddd9df 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py @@ -476,7 +476,7 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - template = self._poll_job(template, 'template') + template = self.poll_job(template, 'template') return template @@ -564,7 +564,7 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - template = self._poll_job(template, 'template') + template = self.poll_job(template, 'template') return template @@ -587,7 +587,7 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - res = self._poll_job(res, 'template') + res = self.poll_job(res, 'template') return template diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_user.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_user.py index 06d44d82f7..14d9fba2c2 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_user.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_user.py @@ -297,7 +297,7 @@ class AnsibleCloudStackUser(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: - user = self._poll_job(user, 'user') + user = self.poll_job(user, 'user') return user diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py index d404df2c81..4c7d68847b 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py @@ -208,7 +208,7 @@ class AnsibleCloudStackVmSnapshot(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if res and poll_async: - snapshot = self._poll_job(res, 'vmsnapshot') + snapshot = self.poll_job(res, 'vmsnapshot') return snapshot @@ -225,7 +225,7 @@ class AnsibleCloudStackVmSnapshot(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if res and poll_async: - res = self._poll_job(res, 'vmsnapshot') + res = self.poll_job(res, 'vmsnapshot') return snapshot @@ -242,7 +242,7 @@ class AnsibleCloudStackVmSnapshot(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if res and poll_async: - res = self._poll_job(res, 'vmsnapshot') + res = self.poll_job(res, 'vmsnapshot') return snapshot self.module.fail_json(msg="snapshot not found, could not revert VM")