From 8ecc3d2516c92429367e2d0c408a74b3394d58cd Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Tue, 17 May 2016 10:39:23 -0700 Subject: [PATCH] Port vspherer_copy to pass syntax checks on python3 --- cloud/vmware/vsphere_copy.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cloud/vmware/vsphere_copy.py b/cloud/vmware/vsphere_copy.py index b51efa2d777..931645235f8 100644 --- a/cloud/vmware/vsphere_copy.py +++ b/cloud/vmware/vsphere_copy.py @@ -82,6 +82,9 @@ import mmap import errno import socket +from ansible.module_utils.basic import AnsibleModule, get_exception +from ansible.module_utils.urls import open_url + def vmware_path(datastore, datacenter, path): ''' Constructs a URL path that VSphere accepts reliably ''' path = "/folder/%s" % path.lstrip("/") @@ -140,13 +143,15 @@ def main(): r = open_url(url, data=data, headers=headers, method='PUT', url_username=login, url_password=password, validate_certs=validate_certs, force_basic_auth=True) - except socket.error, e: + except socket.error: + e = get_exception() if isinstance(e.args, tuple) and e[0] == errno.ECONNRESET: # VSphere resets connection if the file is in use and cannot be replaced module.fail_json(msg='Failed to upload, image probably in use', status=None, errno=e[0], reason=str(e), url=url) else: module.fail_json(msg=str(e), status=None, errno=e[0], reason=str(e), url=url) - except Exception, e: + except Exception: + e = get_exception() error_code = -1 try: if isinstance(e[0], int): @@ -167,8 +172,5 @@ def main(): module.fail_json(msg='Failed to upload', errno=None, status=status, reason=r.msg, length=length, headers=dict(r.headers), chunked=chunked, url=url) -# Import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main()