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:
Matthew Edmonds 2018-08-10 15:10:01 -04:00
parent bea1b97178
commit d7ed9a550b
2 changed files with 8 additions and 8 deletions

View File

@ -23,7 +23,6 @@ import contextlib
import math
import os
import time
import urllib
from xml.dom import minidom
from xml.parsers import expat
@ -42,6 +41,7 @@ from oslo_utils import versionutils
import six
from six.moves import range
import six.moves.urllib.parse as urlparse
import six.moves.urllib.request as urlrequest
from nova.api.metadata import base as instance_metadata
from nova.compute import power_state
@ -1950,7 +1950,7 @@ def _get_rrd_server():
def _get_rrd(server, vm_uuid):
"""Return the VM RRD XML as a string."""
try:
xml = urllib.urlopen("%s://%s:%s@%s/vm_rrd?uuid=%s" % (
xml = urlrequest.urlopen("%s://%s:%s@%s/vm_rrd?uuid=%s" % (
server[0],
CONF.xenserver.connection_username,
CONF.xenserver.connection_password,

View File

@ -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))