mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Port vsphere_guest to py3/py2.4 syntax (#3721)
This commit is contained in:
parent
fefc0cdd50
commit
d519fca04b
1 changed files with 20 additions and 14 deletions
|
@ -680,7 +680,7 @@ def deploy_template(vsphere_client, guest, resource_pool, template_src, esxi, mo
|
||||||
try:
|
try:
|
||||||
hostmor = [k for k,
|
hostmor = [k for k,
|
||||||
v in vsphere_client.get_hosts().items() if v == esxi_hostname][0]
|
v in vsphere_client.get_hosts().items() if v == esxi_hostname][0]
|
||||||
except IndexError, e:
|
except IndexError:
|
||||||
vsphere_client.disconnect()
|
vsphere_client.disconnect()
|
||||||
module.fail_json(msg="Cannot find esx host named: %s" % esxi_hostname)
|
module.fail_json(msg="Cannot find esx host named: %s" % esxi_hostname)
|
||||||
|
|
||||||
|
@ -705,7 +705,7 @@ def deploy_template(vsphere_client, guest, resource_pool, template_src, esxi, mo
|
||||||
try:
|
try:
|
||||||
cluster = [k for k,
|
cluster = [k for k,
|
||||||
v in vsphere_client.get_clusters().items() if v == cluster_name][0] if cluster_name else None
|
v in vsphere_client.get_clusters().items() if v == cluster_name][0] if cluster_name else None
|
||||||
except IndexError, e:
|
except IndexError:
|
||||||
vsphere_client.disconnect()
|
vsphere_client.disconnect()
|
||||||
module.fail_json(msg="Cannot find Cluster named: %s" %
|
module.fail_json(msg="Cannot find Cluster named: %s" %
|
||||||
cluster_name)
|
cluster_name)
|
||||||
|
@ -714,7 +714,7 @@ def deploy_template(vsphere_client, guest, resource_pool, template_src, esxi, mo
|
||||||
rpmor = [k for k, v in vsphere_client.get_resource_pools(
|
rpmor = [k for k, v in vsphere_client.get_resource_pools(
|
||||||
from_mor=cluster).items()
|
from_mor=cluster).items()
|
||||||
if v == resource_pool][0]
|
if v == resource_pool][0]
|
||||||
except IndexError, e:
|
except IndexError:
|
||||||
vsphere_client.disconnect()
|
vsphere_client.disconnect()
|
||||||
module.fail_json(msg="Cannot find Resource Pool named: %s" %
|
module.fail_json(msg="Cannot find Resource Pool named: %s" %
|
||||||
resource_pool)
|
resource_pool)
|
||||||
|
@ -1009,7 +1009,8 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name
|
||||||
vm.power_off(sync_run=True)
|
vm.power_off(sync_run=True)
|
||||||
vm.get_status()
|
vm.get_status()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Failed to shutdown vm %s: %s' % (guest, e)
|
msg='Failed to shutdown vm %s: %s' % (guest, e)
|
||||||
)
|
)
|
||||||
|
@ -1032,7 +1033,8 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name
|
||||||
if vm.is_powered_off() and poweron:
|
if vm.is_powered_off() and poweron:
|
||||||
try:
|
try:
|
||||||
vm.power_on(sync_run=True)
|
vm.power_on(sync_run=True)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Failed to power on vm %s : %s' % (guest, e)
|
msg='Failed to power on vm %s : %s' % (guest, e)
|
||||||
)
|
)
|
||||||
|
@ -1233,7 +1235,7 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest,
|
||||||
try:
|
try:
|
||||||
hostmor = [k for k,
|
hostmor = [k for k,
|
||||||
v in vsphere_client.get_hosts().items() if v == esxi_hostname][0]
|
v in vsphere_client.get_hosts().items() if v == esxi_hostname][0]
|
||||||
except IndexError, e:
|
except IndexError:
|
||||||
vsphere_client.disconnect()
|
vsphere_client.disconnect()
|
||||||
module.fail_json(msg="Cannot find esx host named: %s" % esxi_hostname)
|
module.fail_json(msg="Cannot find esx host named: %s" % esxi_hostname)
|
||||||
|
|
||||||
|
@ -1259,7 +1261,7 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest,
|
||||||
try:
|
try:
|
||||||
cluster = [k for k,
|
cluster = [k for k,
|
||||||
v in vsphere_client.get_clusters().items() if v == cluster_name][0] if cluster_name else None
|
v in vsphere_client.get_clusters().items() if v == cluster_name][0] if cluster_name else None
|
||||||
except IndexError, e:
|
except IndexError:
|
||||||
vsphere_client.disconnect()
|
vsphere_client.disconnect()
|
||||||
module.fail_json(msg="Cannot find Cluster named: %s" %
|
module.fail_json(msg="Cannot find Cluster named: %s" %
|
||||||
cluster_name)
|
cluster_name)
|
||||||
|
@ -1268,7 +1270,7 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest,
|
||||||
rpmor = [k for k, v in vsphere_client.get_resource_pools(
|
rpmor = [k for k, v in vsphere_client.get_resource_pools(
|
||||||
from_mor=cluster).items()
|
from_mor=cluster).items()
|
||||||
if v == resource_pool][0]
|
if v == resource_pool][0]
|
||||||
except IndexError, e:
|
except IndexError:
|
||||||
vsphere_client.disconnect()
|
vsphere_client.disconnect()
|
||||||
module.fail_json(msg="Cannot find Resource Pool named: %s" %
|
module.fail_json(msg="Cannot find Resource Pool named: %s" %
|
||||||
resource_pool)
|
resource_pool)
|
||||||
|
@ -1456,7 +1458,8 @@ def delete_vm(vsphere_client, module, guest, vm, force):
|
||||||
vm.power_off(sync_run=True)
|
vm.power_off(sync_run=True)
|
||||||
vm.get_status()
|
vm.get_status()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Failed to shutdown vm %s: %s' % (guest, e))
|
msg='Failed to shutdown vm %s: %s' % (guest, e))
|
||||||
else:
|
else:
|
||||||
|
@ -1480,7 +1483,8 @@ def delete_vm(vsphere_client, module, guest, vm, force):
|
||||||
module.fail_json(msg="Error removing vm: %s %s" %
|
module.fail_json(msg="Error removing vm: %s %s" %
|
||||||
task.get_error_message())
|
task.get_error_message())
|
||||||
module.exit_json(changed=True, changes="VM %s deleted" % guest)
|
module.exit_json(changed=True, changes="VM %s deleted" % guest)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Failed to delete vm %s : %s' % (guest, e))
|
msg='Failed to delete vm %s : %s' % (guest, e))
|
||||||
|
|
||||||
|
@ -1522,8 +1526,8 @@ def power_state(vm, state, force):
|
||||||
% power_status
|
% power_status
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception, e:
|
except Exception:
|
||||||
return e
|
return get_exception()
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -1765,7 +1769,8 @@ def main():
|
||||||
module.fail_json(msg='Unable to validate the certificate of the vcenter host %s' % vcenter_hostname)
|
module.fail_json(msg='Unable to validate the certificate of the vcenter host %s' % vcenter_hostname)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
except VIApiException, err:
|
except VIApiException:
|
||||||
|
err = get_exception()
|
||||||
module.fail_json(msg="Cannot connect to %s: %s" %
|
module.fail_json(msg="Cannot connect to %s: %s" %
|
||||||
(vcenter_hostname, err))
|
(vcenter_hostname, err))
|
||||||
|
|
||||||
|
@ -1780,7 +1785,8 @@ def main():
|
||||||
if vmware_guest_facts:
|
if vmware_guest_facts:
|
||||||
try:
|
try:
|
||||||
module.exit_json(ansible_facts=gather_facts(vm))
|
module.exit_json(ansible_facts=gather_facts(vm))
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg="Fact gather failed with exception %s" % e)
|
msg="Fact gather failed with exception %s" % e)
|
||||||
# Power Changes
|
# Power Changes
|
||||||
|
|
Loading…
Reference in a new issue