Make Xen code py3-compatible
A couple places in the Xen code have been using syntax that is python2-specific. This replaces those instances with code that will work in both python2 and python3. PEP 3108 [1] moves urllib.urlopen to urllib.request.urlopen. The six module is used in order to work in both python2 and python3 [2]. PEP 3110 [3] changed the grammar for except clauses, such that the 'as' keyword is now required in place of a comma when specifying an exception variable. [1] https://www.python.org/dev/peps/pep-3108/ [2] https://pythonhosted.org/six/#module-six.moves.urllib.request [3] https://www.python.org/dev/peps/pep-3110/ Change-Id: I1235d767718a4207f4cef3e5b140319d003ad7b0
This commit is contained in:
@@ -105,7 +105,7 @@ def _get_applicable_vm_recs(xenapi):
|
||||
for vm_ref in call_xenapi(xenapi, 'VM.get_all'):
|
||||
try:
|
||||
vm_rec = call_xenapi(xenapi, 'VM.get_record', vm_ref)
|
||||
except XenAPI.Failure, e:
|
||||
except XenAPI.Failure as e:
|
||||
if e.details[0] != 'HANDLE_INVALID':
|
||||
raise
|
||||
continue
|
||||
@@ -161,7 +161,7 @@ def _find_vdis_connected_to_vm(xenapi, connected_vdi_uuids):
|
||||
try:
|
||||
cur_vdi_rec = call_xenapi(xenapi, 'VDI.get_record',
|
||||
cur_vdi_ref)
|
||||
except XenAPI.Failure, e:
|
||||
except XenAPI.Failure as e:
|
||||
if e.details[0] != 'HANDLE_INVALID':
|
||||
raise
|
||||
break
|
||||
@@ -176,7 +176,7 @@ def _find_vdis_connected_to_vm(xenapi, connected_vdi_uuids):
|
||||
for vbd_ref in vbd_refs:
|
||||
try:
|
||||
vbd_rec = call_xenapi(xenapi, 'VBD.get_record', vbd_ref)
|
||||
except XenAPI.Failure, e:
|
||||
except XenAPI.Failure as e:
|
||||
if e.details[0] != 'HANDLE_INVALID':
|
||||
raise
|
||||
continue
|
||||
@@ -191,7 +191,7 @@ def _find_vdis_connected_to_vm(xenapi, connected_vdi_uuids):
|
||||
|
||||
try:
|
||||
vdi_rec = call_xenapi(xenapi, 'VDI.get_record', vbd_vdi_ref)
|
||||
except XenAPI.Failure, e:
|
||||
except XenAPI.Failure as e:
|
||||
if e.details[0] != 'HANDLE_INVALID':
|
||||
raise
|
||||
continue
|
||||
@@ -210,7 +210,7 @@ def _find_all_vdis_and_system_vdis(xenapi, all_vdi_uuids, connected_vdi_uuids):
|
||||
for vdi_ref in call_xenapi(xenapi, 'VDI.get_all'):
|
||||
try:
|
||||
vdi_rec = call_xenapi(xenapi, 'VDI.get_record', vdi_ref)
|
||||
except XenAPI.Failure, e:
|
||||
except XenAPI.Failure as e:
|
||||
if e.details[0] != 'HANDLE_INVALID':
|
||||
raise
|
||||
continue
|
||||
@@ -254,7 +254,7 @@ def clean_orphaned_vdis(xenapi, vdi_uuids):
|
||||
vdi_ref = call_xenapi(xenapi, 'VDI.get_by_uuid', vdi_uuid)
|
||||
try:
|
||||
call_xenapi(xenapi, 'VDI.destroy', vdi_ref)
|
||||
except XenAPI.Failure, exc:
|
||||
except XenAPI.Failure as exc:
|
||||
sys.stderr.write("Skipping %s: %s" % (vdi_uuid, exc))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user