Skip to content

Commit

Permalink
Fix proxmox for python 3
Browse files Browse the repository at this point in the history
Since it doesn't work on python 2.4, we can use the native
exception handling way for python 3
  • Loading branch information
mscherer authored and mattclay committed Dec 8, 2016
1 parent 37b62a1 commit 8676924
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
14 changes: 7 additions & 7 deletions lib/ansible/modules/extras/cloud/misc/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,15 @@ 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)
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':
Expand Down Expand Up @@ -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':
Expand All @@ -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':
Expand All @@ -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':
Expand All @@ -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':
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/ansible/modules/extras/cloud/misc/proxmox_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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':
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8676924

Please sign in to comment.