Skip to content

Commit d7ed9a5

Browse files
committed
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
1 parent bea1b97 commit d7ed9a5

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

nova/virt/xenapi/vm_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import math
2424
import os
2525
import time
26-
import urllib
2726
from xml.dom import minidom
2827
from xml.parsers import expat
2928

@@ -42,6 +41,7 @@
4241
import six
4342
from six.moves import range
4443
import six.moves.urllib.parse as urlparse
44+
import six.moves.urllib.request as urlrequest
4545

4646
from nova.api.metadata import base as instance_metadata
4747
from nova.compute import power_state
@@ -1950,7 +1950,7 @@ def _get_rrd_server():
19501950
def _get_rrd(server, vm_uuid):
19511951
"""Return the VM RRD XML as a string."""
19521952
try:
1953-
xml = urllib.urlopen("%s://%s:%s@%s/vm_rrd?uuid=%s" % (
1953+
xml = urlrequest.urlopen("%s://%s:%s@%s/vm_rrd?uuid=%s" % (
19541954
server[0],
19551955
CONF.xenserver.connection_username,
19561956
CONF.xenserver.connection_password,

tools/xenserver/vm_vdi_cleaner.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _get_applicable_vm_recs(xenapi):
105105
for vm_ref in call_xenapi(xenapi, 'VM.get_all'):
106106
try:
107107
vm_rec = call_xenapi(xenapi, 'VM.get_record', vm_ref)
108-
except XenAPI.Failure, e:
108+
except XenAPI.Failure as e:
109109
if e.details[0] != 'HANDLE_INVALID':
110110
raise
111111
continue
@@ -161,7 +161,7 @@ def _add_vdi_and_parents_to_connected(vdi_rec, indent_level):
161161
try:
162162
cur_vdi_rec = call_xenapi(xenapi, 'VDI.get_record',
163163
cur_vdi_ref)
164-
except XenAPI.Failure, e:
164+
except XenAPI.Failure as e:
165165
if e.details[0] != 'HANDLE_INVALID':
166166
raise
167167
break
@@ -176,7 +176,7 @@ def _add_vdi_and_parents_to_connected(vdi_rec, indent_level):
176176
for vbd_ref in vbd_refs:
177177
try:
178178
vbd_rec = call_xenapi(xenapi, 'VBD.get_record', vbd_ref)
179-
except XenAPI.Failure, e:
179+
except XenAPI.Failure as e:
180180
if e.details[0] != 'HANDLE_INVALID':
181181
raise
182182
continue
@@ -191,7 +191,7 @@ def _add_vdi_and_parents_to_connected(vdi_rec, indent_level):
191191

192192
try:
193193
vdi_rec = call_xenapi(xenapi, 'VDI.get_record', vbd_vdi_ref)
194-
except XenAPI.Failure, e:
194+
except XenAPI.Failure as e:
195195
if e.details[0] != 'HANDLE_INVALID':
196196
raise
197197
continue
@@ -210,7 +210,7 @@ def _system_owned(vdi_rec):
210210
for vdi_ref in call_xenapi(xenapi, 'VDI.get_all'):
211211
try:
212212
vdi_rec = call_xenapi(xenapi, 'VDI.get_record', vdi_ref)
213-
except XenAPI.Failure, e:
213+
except XenAPI.Failure as e:
214214
if e.details[0] != 'HANDLE_INVALID':
215215
raise
216216
continue
@@ -254,7 +254,7 @@ def clean_orphaned_vdis(xenapi, vdi_uuids):
254254
vdi_ref = call_xenapi(xenapi, 'VDI.get_by_uuid', vdi_uuid)
255255
try:
256256
call_xenapi(xenapi, 'VDI.destroy', vdi_ref)
257-
except XenAPI.Failure, exc:
257+
except XenAPI.Failure as exc:
258258
sys.stderr.write("Skipping %s: %s" % (vdi_uuid, exc))
259259

260260

0 commit comments

Comments
 (0)