Fix proxmox for python 3

Since it doesn't work on python 2.4, we can use the native
exception handling way for python 3
This commit is contained in:
Michael Scherer 2016-10-15 17:30:50 +02:00 committed by Matt Clay
parent 37b62a1db3
commit 8676924da5
3 changed files with 11 additions and 13 deletions

View file

@ -350,7 +350,7 @@ def main():
if not api_password:
try:
api_password = os.environ['PROXMOX_PASSWORD']
except KeyError, e:
except KeyError as e:
module.fail_json(msg='You should set api_password param or use PROXMOX_PASSWORD environment variable')
try:
@ -358,7 +358,7 @@ def main():
global VZ_TYPE
VZ_TYPE = 'openvz' if float(proxmox.version.get()['version']) < 4.0 else 'lxc'
except Exception, e:
except Exception as e:
module.fail_json(msg='authorization on proxmox cluster failed with exception: %s' % e)
if state == 'present':
@ -387,7 +387,7 @@ def main():
force = int(module.params['force']))
module.exit_json(changed=True, msg="deployed VM %s from template %s" % (vmid, module.params['ostemplate']))
except Exception, e:
except Exception as e:
module.fail_json(msg="creation of %s VM %s failed with exception: %s" % ( VZ_TYPE, vmid, e ))
elif state == 'started':
@ -400,7 +400,7 @@ def main():
if start_instance(module, proxmox, vm, vmid, timeout):
module.exit_json(changed=True, msg="VM %s started" % vmid)
except Exception, e:
except Exception as e:
module.fail_json(msg="starting of VM %s failed with exception: %s" % ( vmid, e ))
elif state == 'stopped':
@ -422,7 +422,7 @@ def main():
if stop_instance(module, proxmox, vm, vmid, timeout, force = module.params['force']):
module.exit_json(changed=True, msg="VM %s is shutting down" % vmid)
except Exception, e:
except Exception as e:
module.fail_json(msg="stopping of VM %s failed with exception: %s" % ( vmid, e ))
elif state == 'restarted':
@ -437,7 +437,7 @@ def main():
if ( stop_instance(module, proxmox, vm, vmid, timeout, force = module.params['force']) and
start_instance(module, proxmox, vm, vmid, timeout) ):
module.exit_json(changed=True, msg="VM %s is restarted" % vmid)
except Exception, e:
except Exception as e:
module.fail_json(msg="restarting of VM %s failed with exception: %s" % ( vmid, e ))
elif state == 'absent':
@ -463,7 +463,7 @@ def main():
% proxmox_node.tasks(taskid).log.get()[:1])
time.sleep(1)
except Exception, e:
except Exception as e:
module.fail_json(msg="deletion of VM %s failed with exception: %s" % ( vmid, e ))
# import module snippets

View file

@ -184,12 +184,12 @@ def main():
if not api_password:
try:
api_password = os.environ['PROXMOX_PASSWORD']
except KeyError, e:
except KeyError as e:
module.fail_json(msg='You should set api_password param or use PROXMOX_PASSWORD environment variable')
try:
proxmox = ProxmoxAPI(api_host, user=api_user, password=api_password, verify_ssl=validate_certs)
except Exception, e:
except Exception as e:
module.fail_json(msg='authorization on proxmox cluster failed with exception: %s' % e)
if state == 'present':
@ -209,7 +209,7 @@ def main():
if upload_template(module, proxmox, api_host, node, storage, content_type, realpath, timeout):
module.exit_json(changed=True, msg='template with volid=%s:%s/%s uploaded' % (storage, content_type, template))
except Exception, e:
except Exception as e:
module.fail_json(msg="uploading of template %s failed with exception: %s" % ( template, e ))
elif state == 'absent':
@ -224,7 +224,7 @@ def main():
if delete_template(module, proxmox, node, storage, content_type, template, timeout):
module.exit_json(changed=True, msg='template with volid=%s:%s/%s deleted' % (storage, content_type, template))
except Exception, e:
except Exception as e:
module.fail_json(msg="deleting of template %s failed with exception: %s" % ( template, e ))
# import module snippets

View file

@ -31,8 +31,6 @@
/cloud/centurylink/clc_aa_policy.py
/cloud/centurylink/clc_group.py
/cloud/centurylink/clc_publicip.py
/cloud/misc/proxmox.py
/cloud/misc/proxmox_template.py
/cloud/misc/virt_net.py
/cloud/misc/virt_pool.py
/cloud/profitbricks/profitbricks.py