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:
@@ -23,7 +23,6 @@ import contextlib
|
|||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import urllib
|
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
from xml.parsers import expat
|
from xml.parsers import expat
|
||||||
|
|
||||||
@@ -42,6 +41,7 @@ from oslo_utils import versionutils
|
|||||||
import six
|
import six
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
import six.moves.urllib.parse as urlparse
|
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.api.metadata import base as instance_metadata
|
||||||
from nova.compute import power_state
|
from nova.compute import power_state
|
||||||
@@ -1950,7 +1950,7 @@ def _get_rrd_server():
|
|||||||
def _get_rrd(server, vm_uuid):
|
def _get_rrd(server, vm_uuid):
|
||||||
"""Return the VM RRD XML as a string."""
|
"""Return the VM RRD XML as a string."""
|
||||||
try:
|
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],
|
server[0],
|
||||||
CONF.xenserver.connection_username,
|
CONF.xenserver.connection_username,
|
||||||
CONF.xenserver.connection_password,
|
CONF.xenserver.connection_password,
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ def _get_applicable_vm_recs(xenapi):
|
|||||||
for vm_ref in call_xenapi(xenapi, 'VM.get_all'):
|
for vm_ref in call_xenapi(xenapi, 'VM.get_all'):
|
||||||
try:
|
try:
|
||||||
vm_rec = call_xenapi(xenapi, 'VM.get_record', vm_ref)
|
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':
|
if e.details[0] != 'HANDLE_INVALID':
|
||||||
raise
|
raise
|
||||||
continue
|
continue
|
||||||
@@ -161,7 +161,7 @@ def _find_vdis_connected_to_vm(xenapi, connected_vdi_uuids):
|
|||||||
try:
|
try:
|
||||||
cur_vdi_rec = call_xenapi(xenapi, 'VDI.get_record',
|
cur_vdi_rec = call_xenapi(xenapi, 'VDI.get_record',
|
||||||
cur_vdi_ref)
|
cur_vdi_ref)
|
||||||
except XenAPI.Failure, e:
|
except XenAPI.Failure as e:
|
||||||
if e.details[0] != 'HANDLE_INVALID':
|
if e.details[0] != 'HANDLE_INVALID':
|
||||||
raise
|
raise
|
||||||
break
|
break
|
||||||
@@ -176,7 +176,7 @@ def _find_vdis_connected_to_vm(xenapi, connected_vdi_uuids):
|
|||||||
for vbd_ref in vbd_refs:
|
for vbd_ref in vbd_refs:
|
||||||
try:
|
try:
|
||||||
vbd_rec = call_xenapi(xenapi, 'VBD.get_record', vbd_ref)
|
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':
|
if e.details[0] != 'HANDLE_INVALID':
|
||||||
raise
|
raise
|
||||||
continue
|
continue
|
||||||
@@ -191,7 +191,7 @@ def _find_vdis_connected_to_vm(xenapi, connected_vdi_uuids):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
vdi_rec = call_xenapi(xenapi, 'VDI.get_record', vbd_vdi_ref)
|
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':
|
if e.details[0] != 'HANDLE_INVALID':
|
||||||
raise
|
raise
|
||||||
continue
|
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'):
|
for vdi_ref in call_xenapi(xenapi, 'VDI.get_all'):
|
||||||
try:
|
try:
|
||||||
vdi_rec = call_xenapi(xenapi, 'VDI.get_record', vdi_ref)
|
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':
|
if e.details[0] != 'HANDLE_INVALID':
|
||||||
raise
|
raise
|
||||||
continue
|
continue
|
||||||
@@ -254,7 +254,7 @@ def clean_orphaned_vdis(xenapi, vdi_uuids):
|
|||||||
vdi_ref = call_xenapi(xenapi, 'VDI.get_by_uuid', vdi_uuid)
|
vdi_ref = call_xenapi(xenapi, 'VDI.get_by_uuid', vdi_uuid)
|
||||||
try:
|
try:
|
||||||
call_xenapi(xenapi, 'VDI.destroy', vdi_ref)
|
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))
|
sys.stderr.write("Skipping %s: %s" % (vdi_uuid, exc))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user