Improve Python 3.x compatibility
A bit of mechanical translation to clean out the deprecated except x,y: construct Change-Id: I80883b6b0c014bdf4799e8b7b2c4a4a07d951a0b
This commit is contained in:
parent
18d9a8b4b4
commit
f3826902a0
@ -839,7 +839,7 @@ class InstanceTypeCommands(object):
|
||||
instance_types.create(name, memory, vcpus, root_gb,
|
||||
ephemeral_gb, flavorid, swap, rxtx_factor,
|
||||
is_public)
|
||||
except exception.InvalidInput, e:
|
||||
except exception.InvalidInput as e:
|
||||
print _("Must supply valid parameters to create instance_type")
|
||||
print e
|
||||
return(1)
|
||||
@ -865,7 +865,7 @@ class InstanceTypeCommands(object):
|
||||
except exception.InstanceTypeNotFound:
|
||||
print _("Valid instance type name is required")
|
||||
return(1)
|
||||
except db_exc.DBError, e:
|
||||
except db_exc.DBError as e:
|
||||
print _("DB Error: %s") % e
|
||||
return(2)
|
||||
except Exception:
|
||||
@ -881,7 +881,7 @@ class InstanceTypeCommands(object):
|
||||
inst_types = instance_types.get_all_types()
|
||||
else:
|
||||
inst_types = instance_types.get_instance_type_by_name(name)
|
||||
except db_exc.DBError, e:
|
||||
except db_exc.DBError as e:
|
||||
_db_error(e)
|
||||
if isinstance(inst_types.values()[0], dict):
|
||||
for k, v in inst_types.iteritems():
|
||||
@ -897,7 +897,7 @@ class InstanceTypeCommands(object):
|
||||
try:
|
||||
try:
|
||||
inst_type = instance_types.get_instance_type_by_name(name)
|
||||
except exception.InstanceTypeNotFoundByName, e:
|
||||
except exception.InstanceTypeNotFoundByName as e:
|
||||
print e
|
||||
return(2)
|
||||
|
||||
@ -909,7 +909,7 @@ class InstanceTypeCommands(object):
|
||||
ext_spec)
|
||||
print _("Key %(key)s set to %(value)s on instance"
|
||||
" type %(name)s") % locals()
|
||||
except db_exc.DBError, e:
|
||||
except db_exc.DBError as e:
|
||||
_db_error(e)
|
||||
|
||||
@args('--name', metavar='<name>', help='Name of instance type/flavor')
|
||||
@ -919,7 +919,7 @@ class InstanceTypeCommands(object):
|
||||
try:
|
||||
try:
|
||||
inst_type = instance_types.get_instance_type_by_name(name)
|
||||
except exception.InstanceTypeNotFoundByName, e:
|
||||
except exception.InstanceTypeNotFoundByName as e:
|
||||
print e
|
||||
return(2)
|
||||
|
||||
@ -930,7 +930,7 @@ class InstanceTypeCommands(object):
|
||||
key)
|
||||
|
||||
print _("Key %(key)s on instance type %(name)s unset") % locals()
|
||||
except db_exc.DBError, e:
|
||||
except db_exc.DBError as e:
|
||||
_db_error(e)
|
||||
|
||||
|
||||
|
@ -2655,7 +2655,7 @@ class AggregateAPI(base.Base):
|
||||
self.db.aggregate_metadata_delete(context,
|
||||
aggregate_id, key)
|
||||
metadata.pop(key)
|
||||
except exception.AggregateMetadataNotFound, e:
|
||||
except exception.AggregateMetadataNotFound as e:
|
||||
LOG.warn(e.message)
|
||||
self.db.aggregate_metadata_add(context, aggregate_id, metadata)
|
||||
return self.get_aggregate(context, aggregate_id)
|
||||
|
@ -134,7 +134,7 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None,
|
||||
|
||||
try:
|
||||
return db.instance_type_create(context.get_admin_context(), kwargs)
|
||||
except db_exc.DBError, e:
|
||||
except db_exc.DBError as e:
|
||||
LOG.exception(_('DB error: %s') % e)
|
||||
raise exception.InstanceTypeCreateFailed()
|
||||
|
||||
|
@ -228,7 +228,7 @@ def wrap_instance_fault(function):
|
||||
return function(self, context, *args, **kwargs)
|
||||
except exception.InstanceNotFound:
|
||||
raise
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
# NOTE(gtt): If argument 'instance' is in args rather than kwargs,
|
||||
# we will get a KeyError exception which will cover up the real
|
||||
# exception. So, we update kwargs with the values from args first.
|
||||
@ -525,7 +525,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
instance, self._legacy_nw_info(net_info),
|
||||
self._get_instance_volume_block_device_info(context,
|
||||
instance))
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
LOG.exception(_('Failed to revert crashed migration'),
|
||||
instance=instance)
|
||||
finally:
|
||||
@ -1948,7 +1948,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
# interrupted by another (most likely delete) task
|
||||
# do not retry
|
||||
raise
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
# Catch all here because this could be anything.
|
||||
LOG.exception(_('set_admin_password failed: %s') % e,
|
||||
instance=instance)
|
||||
@ -3541,7 +3541,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
try:
|
||||
self.conductor_api.compute_confirm_resize(
|
||||
context, instance, migration_ref=migration)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
msg = _("Error auto-confirming resize: %(e)s. "
|
||||
"Will retry later.")
|
||||
LOG.error(msg % locals(), instance=instance)
|
||||
|
@ -69,7 +69,7 @@ class IP(Model):
|
||||
if self['address'] and not self['version']:
|
||||
try:
|
||||
self['version'] = netaddr.IPAddress(self['address']).version
|
||||
except netaddr.AddrFormatError, e:
|
||||
except netaddr.AddrFormatError as e:
|
||||
raise exception.InvalidIpAddressError(self['address'])
|
||||
|
||||
def __eq__(self, other):
|
||||
|
@ -60,7 +60,7 @@ def _load_config():
|
||||
NOVA_PACKAGE = cfg.get("Nova", "package")
|
||||
if cfg.has_option("Nova", "package"):
|
||||
NOVA_PACKAGE = cfg.get("Nova", "package")
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG.error("Failed to load %(cfgfile)s: %(ex)s" % locals())
|
||||
|
||||
|
@ -397,7 +397,7 @@ def bm_interface_set_vif_uuid(context, if_id, vif_uuid):
|
||||
try:
|
||||
session.add(bm_interface)
|
||||
session.flush()
|
||||
except db_exc.DBError, e:
|
||||
except db_exc.DBError as e:
|
||||
# TODO(deva): clean up when db layer raises DuplicateKeyError
|
||||
if str(e).find('IntegrityError') != -1:
|
||||
raise exception.NovaException(_("Baremetal interface %s "
|
||||
|
@ -307,7 +307,7 @@ class BareMetalDriver(driver.ComputeDriver):
|
||||
self._unplug_vifs(instance, network_info)
|
||||
|
||||
_update_state(context, node, None, baremetal_states.DELETED)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
try:
|
||||
LOG.error(_("Error from baremetal driver "
|
||||
|
@ -45,7 +45,7 @@ def inject_into_image(image, key, net, metadata, admin_password,
|
||||
def unlink_without_raise(path):
|
||||
try:
|
||||
os.unlink(path)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
return
|
||||
else:
|
||||
@ -56,7 +56,7 @@ def rmtree_without_raise(path):
|
||||
try:
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
LOG.warn(_("Failed to remove dir %(path)s, error: %(e)s") % locals())
|
||||
|
||||
|
||||
@ -68,7 +68,7 @@ def write_to_file(path, contents):
|
||||
def create_link_without_raise(source, link):
|
||||
try:
|
||||
os.symlink(source, link)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno == errno.EEXIST:
|
||||
return
|
||||
else:
|
||||
|
@ -173,7 +173,7 @@ class ConfigDriveBuilder(object):
|
||||
|
||||
try:
|
||||
shutil.rmtree(self.tempdir)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
LOG.error(_('Could not remove tmpdir: %s'), str(e))
|
||||
|
||||
|
||||
|
@ -145,7 +145,7 @@ def can_resize_fs(image, size, use_cow=False):
|
||||
fs = vfs.VFS.instance_for_image(image, 'qcow2', None)
|
||||
fs.setup()
|
||||
fs.teardown()
|
||||
except exception.NovaException, e:
|
||||
except exception.NovaException as e:
|
||||
LOG.debug(_('Unable to mount image %(image)s with '
|
||||
'error %(error)s. Cannot resize.'),
|
||||
{'image': image,
|
||||
@ -155,7 +155,7 @@ def can_resize_fs(image, size, use_cow=False):
|
||||
# For raw, we can directly inspect the file system
|
||||
try:
|
||||
utils.execute('e2label', image)
|
||||
except exception.ProcessExecutionError, e:
|
||||
except exception.ProcessExecutionError as e:
|
||||
LOG.debug(_('Unable to determine label for image %(image)s with '
|
||||
'error %(errror)s. Cannot resize.'),
|
||||
{'image': image,
|
||||
@ -331,7 +331,7 @@ def teardown_container(container_dir):
|
||||
try:
|
||||
img = _DiskImage(image=None, mount_dir=container_dir)
|
||||
img.teardown()
|
||||
except Exception, exn:
|
||||
except Exception as exn:
|
||||
LOG.exception(_('Failed to teardown ntainer filesystem: %s'), exn)
|
||||
|
||||
|
||||
@ -344,7 +344,7 @@ def clean_lxc_namespace(container_dir):
|
||||
try:
|
||||
img = _DiskImage(image=None, mount_dir=container_dir)
|
||||
img.umount()
|
||||
except Exception, exn:
|
||||
except Exception as exn:
|
||||
LOG.exception(_('Failed to umount container filesystem: %s'), exn)
|
||||
|
||||
|
||||
|
@ -106,7 +106,7 @@ class VFSGuestFS(vfs.VFS):
|
||||
self.setup_os()
|
||||
|
||||
self.handle.aug_init("/", 0)
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
# dereference object and implicitly close()
|
||||
self.handle = None
|
||||
raise exception.NovaException(
|
||||
@ -122,7 +122,7 @@ class VFSGuestFS(vfs.VFS):
|
||||
try:
|
||||
try:
|
||||
self.handle.aug_close()
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
LOG.warn(_("Failed to close augeas %s"), e)
|
||||
|
||||
try:
|
||||
@ -130,7 +130,7 @@ class VFSGuestFS(vfs.VFS):
|
||||
except AttributeError:
|
||||
# Older libguestfs versions haven't an explicit shutdown
|
||||
pass
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
LOG.warn(_("Failed to shutdown appliance %s"), e)
|
||||
|
||||
try:
|
||||
@ -138,7 +138,7 @@ class VFSGuestFS(vfs.VFS):
|
||||
except AttributeError:
|
||||
# Older libguestfs versions haven't an explicit close
|
||||
pass
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
LOG.warn(_("Failed to close guest handle %s"), e)
|
||||
finally:
|
||||
# dereference object and implicitly close()
|
||||
|
@ -76,7 +76,7 @@ class VFSLocalFS(vfs.VFS):
|
||||
if not mount.do_mount():
|
||||
raise exception.NovaException(mount.error)
|
||||
self.mount = mount
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
LOG.debug(_("Failed to mount image %(ex)s)") %
|
||||
{'ex': str(e)})
|
||||
self.teardown()
|
||||
@ -86,13 +86,13 @@ class VFSLocalFS(vfs.VFS):
|
||||
try:
|
||||
if self.mount:
|
||||
self.mount.do_teardown()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
LOG.debug(_("Failed to unmount %(imgdir)s: %(ex)s") %
|
||||
{'imgdir': self.imgdir, 'ex': str(e)})
|
||||
try:
|
||||
if self.imgdir:
|
||||
os.rmdir(self.imgdir)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
LOG.debug(_("Failed to remove %(imgdir)s: %(ex)s") %
|
||||
{'imgdir': self.imgdir, 'ex': str(e)})
|
||||
self.imgdir = None
|
||||
|
@ -926,7 +926,7 @@ class ComputeDriver(object):
|
||||
try:
|
||||
LOG.debug("Emitting event %s" % str(event))
|
||||
self._compute_event_callback(event)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
LOG.error(_("Exception dispatching event %(event)s: %(ex)s")
|
||||
% locals())
|
||||
|
||||
|
@ -229,7 +229,7 @@ class VMOps(object):
|
||||
with configdrive.ConfigDriveBuilder(instance_md=inst_md) as cdb:
|
||||
try:
|
||||
cdb.make_drive(configdrive_path_iso)
|
||||
except exception.ProcessExecutionError, e:
|
||||
except exception.ProcessExecutionError as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(_('Creating config drive failed with error: %s'),
|
||||
e, instance=instance)
|
||||
|
@ -566,7 +566,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE,
|
||||
self._event_lifecycle_callback,
|
||||
self)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
LOG.warn(_("URI %s does not support events"),
|
||||
self.uri())
|
||||
|
||||
@ -853,7 +853,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
# the instance as whole.
|
||||
try:
|
||||
shutil.rmtree(target)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
LOG.error(_("Failed to cleanup directory %(target)s: %(e)s"
|
||||
) % locals())
|
||||
|
||||
@ -966,7 +966,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
if state == power_state.RUNNING:
|
||||
flags |= libvirt.VIR_DOMAIN_AFFECT_LIVE
|
||||
virt_dom.attachDeviceFlags(conf.to_xml(), flags)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
if isinstance(ex, libvirt.libvirtError):
|
||||
errcode = ex.get_error_code()
|
||||
if errcode == libvirt.VIR_ERR_OPERATION_FAILED:
|
||||
@ -1671,7 +1671,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
os.close(f)
|
||||
LOG.debug(_("Path '%(path)s' supports direct I/O") %
|
||||
{'path': dirpath})
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno == errno.EINVAL:
|
||||
LOG.debug(_("Path '%(path)s' does not support direct I/O: "
|
||||
"'%(ex)s'") % {'path': dirpath, 'ex': str(e)})
|
||||
@ -1681,7 +1681,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
LOG.error(_("Error on '%(path)s' while checking "
|
||||
"direct I/O: '%(ex)s'") %
|
||||
{'path': dirpath, 'ex': str(e)})
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(_("Error on '%(path)s' while checking direct I/O: "
|
||||
"'%(ex)s'") % {'path': dirpath, 'ex': str(e)})
|
||||
@ -1869,7 +1869,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
|
||||
try:
|
||||
cdb.make_drive(configdrive_path)
|
||||
except exception.ProcessExecutionError, e:
|
||||
except exception.ProcessExecutionError as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(_('Creating config drive failed '
|
||||
'with error: %s'),
|
||||
@ -3001,7 +3001,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
# unknown character exists in xml, then libvirt complains
|
||||
try:
|
||||
ret = self._conn.compareCPU(cpu.to_xml(), 0)
|
||||
except libvirt.libvirtError, e:
|
||||
except libvirt.libvirtError as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
ret = e.message
|
||||
LOG.error(m % locals())
|
||||
|
@ -136,7 +136,7 @@ def _read_possible_json(serialized, info_file):
|
||||
try:
|
||||
d = jsonutils.loads(serialized)
|
||||
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
LOG.error(_('Error reading image info file %(filename)s: '
|
||||
'%(error)s'),
|
||||
{'filename': info_file,
|
||||
@ -478,7 +478,7 @@ class ImageCacheManager(object):
|
||||
signature = get_info_filename(base_file)
|
||||
if os.path.exists(signature):
|
||||
os.remove(signature)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
LOG.error(_('Failed to remove %(base_file)s, '
|
||||
'error was %(error)s'),
|
||||
{'base_file': base_file,
|
||||
|
@ -51,7 +51,7 @@ def load_from_conf_data(conf_data):
|
||||
for (key, value) in attribs.items():
|
||||
try:
|
||||
lpar[key] = value
|
||||
except exception.PowerVMLPARAttributeNotFound, e:
|
||||
except exception.PowerVMLPARAttributeNotFound as e:
|
||||
LOG.info(_('Encountered unknown LPAR attribute: %s\n'
|
||||
'Continuing without storing') % key)
|
||||
return lpar
|
||||
|
@ -183,7 +183,7 @@ class PowerVMOperator(object):
|
||||
vhost = self._operator.get_vhost_by_instance_id(lpar_id)
|
||||
self._operator.attach_disk_to_vhost(
|
||||
root_volume['device_name'], vhost)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
LOG.exception(_("PowerVM image creation failed: %s") % str(e))
|
||||
raise exception.PowerVMImageCreationFailed()
|
||||
|
||||
|
@ -443,7 +443,7 @@ class VMwareAPISession(object):
|
||||
self.vim.TerminateSession(
|
||||
self.vim.get_service_content().sessionManager,
|
||||
sessionId=[self._session_id])
|
||||
except Exception, excep:
|
||||
except Exception as excep:
|
||||
# This exception is something we can live with. It is
|
||||
# just an extra caution on our side. The session may
|
||||
# have been cleared. We could have made a call to
|
||||
@ -452,7 +452,7 @@ class VMwareAPISession(object):
|
||||
LOG.debug(excep)
|
||||
self._session_id = session.key
|
||||
return
|
||||
except Exception, excep:
|
||||
except Exception as excep:
|
||||
LOG.critical(_("In vmwareapi:_create_session, "
|
||||
"got this exception: %s") % excep)
|
||||
raise exception.NovaException(excep)
|
||||
@ -463,7 +463,7 @@ class VMwareAPISession(object):
|
||||
# ESX host
|
||||
try:
|
||||
self.vim.Logout(self.vim.get_service_content().sessionManager)
|
||||
except Exception, excep:
|
||||
except Exception as excep:
|
||||
# It is just cautionary on our part to do a logout in del just
|
||||
# to ensure that the session is not left active.
|
||||
LOG.debug(excep)
|
||||
@ -496,7 +496,7 @@ class VMwareAPISession(object):
|
||||
temp_module = getattr(temp_module, method_elem)
|
||||
|
||||
return temp_module(*args, **kwargs)
|
||||
except error_util.VimFaultException, excep:
|
||||
except error_util.VimFaultException as excep:
|
||||
# If it is a Session Fault Exception, it may point
|
||||
# to a session gone bad. So we try re-creating a session
|
||||
# and then proceeding ahead with the call.
|
||||
@ -520,11 +520,11 @@ class VMwareAPISession(object):
|
||||
# and is the caller's fault. Caller should handle these
|
||||
# errors. e.g, InvalidArgument fault.
|
||||
break
|
||||
except error_util.SessionOverLoadException, excep:
|
||||
except error_util.SessionOverLoadException as excep:
|
||||
# For exceptions which may come because of session overload,
|
||||
# we retry
|
||||
exc = excep
|
||||
except Exception, excep:
|
||||
except Exception as excep:
|
||||
# If it is a proper exception, say not having furnished
|
||||
# proper data in the SOAP call or the retry limit having
|
||||
# exceeded, we raise the exception
|
||||
@ -579,6 +579,6 @@ class VMwareAPISession(object):
|
||||
LOG.warn(_("Task [%(task_name)s] %(task_ref)s "
|
||||
"status: error %(error_info)s") % locals())
|
||||
done.send_exception(exception.NovaException(error_info))
|
||||
except Exception, excep:
|
||||
except Exception as excep:
|
||||
LOG.warn(_("In vmwareapi:_poll_task, Got this error %s") % excep)
|
||||
done.send_exception(excep)
|
||||
|
@ -697,7 +697,7 @@ class FakeVim(object):
|
||||
for prop in properties:
|
||||
temp_mdo.set(prop, mdo.get(prop))
|
||||
lst_ret_objs.append(temp_mdo)
|
||||
except Exception, exc:
|
||||
except Exception as exc:
|
||||
LOG.exception(exc)
|
||||
continue
|
||||
return lst_ret_objs
|
||||
|
@ -124,7 +124,7 @@ class GlanceWriteThread(object):
|
||||
"state": image_status}
|
||||
LOG.error(msg)
|
||||
self.done.send_exception(exception.NovaException(msg))
|
||||
except Exception, exc:
|
||||
except Exception as exc:
|
||||
self.stop()
|
||||
self.done.send_exception(exc)
|
||||
|
||||
@ -166,7 +166,7 @@ class IOThread(object):
|
||||
self.done.send(True)
|
||||
self.output.write(data)
|
||||
greenthread.sleep(IO_THREAD_SLEEP_TIME)
|
||||
except Exception, exc:
|
||||
except Exception as exc:
|
||||
self.stop()
|
||||
LOG.exception(exc)
|
||||
self.done.send_exception(exc)
|
||||
|
@ -167,7 +167,7 @@ def create_port_group(session, pg_name, vswitch_name, vlan_id=0, cluster=None):
|
||||
session._call_method(session._get_vim(),
|
||||
"AddPortGroup", network_system_mor,
|
||||
portgrp=add_prt_grp_spec)
|
||||
except error_util.VimFaultException, exc:
|
||||
except error_util.VimFaultException as exc:
|
||||
# There can be a race condition when two instances try
|
||||
# adding port groups at the same time. One succeeds, then
|
||||
# the other one will get an exception. Since we are
|
||||
|
@ -80,7 +80,7 @@ class VMwareHTTPFile(object):
|
||||
"""Close the file handle."""
|
||||
try:
|
||||
self.file_handle.close()
|
||||
except Exception, exc:
|
||||
except Exception as exc:
|
||||
LOG.exception(exc)
|
||||
|
||||
def __del__(self):
|
||||
@ -138,7 +138,7 @@ class VMwareHTTPWriteFile(VMwareHTTPFile):
|
||||
"""Get the response and close the connection."""
|
||||
try:
|
||||
self.conn.getresponse()
|
||||
except Exception, excep:
|
||||
except Exception as excep:
|
||||
LOG.debug(_("Exception during HTTP connection close in "
|
||||
"VMwareHTTPWrite. Exception is %s") % excep)
|
||||
super(VMwareHTTPWriteFile, self).close()
|
||||
|
@ -129,24 +129,24 @@ class Vim:
|
||||
return response
|
||||
# Catch the VimFaultException that is raised by the fault
|
||||
# check of the SOAP response
|
||||
except error_util.VimFaultException, excep:
|
||||
except error_util.VimFaultException as excep:
|
||||
raise
|
||||
except suds.WebFault, excep:
|
||||
except suds.WebFault as excep:
|
||||
doc = excep.document
|
||||
detail = doc.childAtPath("/Envelope/Body/Fault/detail")
|
||||
fault_list = []
|
||||
for child in detail.getChildren():
|
||||
fault_list.append(child.get("type"))
|
||||
raise error_util.VimFaultException(fault_list, excep)
|
||||
except AttributeError, excep:
|
||||
except AttributeError as excep:
|
||||
raise error_util.VimAttributeError(_("No such SOAP method "
|
||||
"'%s' provided by VI SDK") % (attr_name), excep)
|
||||
except (httplib.CannotSendRequest,
|
||||
httplib.ResponseNotReady,
|
||||
httplib.CannotSendHeader), excep:
|
||||
httplib.CannotSendHeader) as excep:
|
||||
raise error_util.SessionOverLoadException(_("httplib "
|
||||
"error in %s: ") % (attr_name), excep)
|
||||
except Exception, excep:
|
||||
except Exception as excep:
|
||||
# Socket errors which need special handling for they
|
||||
# might be caused by ESX API call overload
|
||||
if (str(excep).find(ADDRESS_IN_USE_ERROR) != -1 or
|
||||
|
@ -654,13 +654,13 @@ class VMwareVMOps(object):
|
||||
"Destroy_Task", vm_ref)
|
||||
self._session._wait_for_task(instance['uuid'], destroy_task)
|
||||
LOG.debug(_("Destroyed the VM"), instance=instance)
|
||||
except Exception, excep:
|
||||
except Exception as excep:
|
||||
LOG.warn(_("In vmwareapi:vmops:delete, got this exception"
|
||||
" while destroying the VM: %s") % str(excep))
|
||||
|
||||
if network_info:
|
||||
self.unplug_vifs(instance, network_info)
|
||||
except Exception, exc:
|
||||
except Exception as exc:
|
||||
LOG.exception(exc, instance=instance)
|
||||
|
||||
def destroy(self, instance, network_info, destroy_disks=True):
|
||||
@ -706,7 +706,7 @@ class VMwareVMOps(object):
|
||||
self._session._call_method(self._session._get_vim(),
|
||||
"UnregisterVM", vm_ref)
|
||||
LOG.debug(_("Unregistered the VM"), instance=instance)
|
||||
except Exception, excep:
|
||||
except Exception as excep:
|
||||
LOG.warn(_("In vmwareapi:vmops:destroy, got this exception"
|
||||
" while un-registering the VM: %s") % str(excep))
|
||||
|
||||
@ -736,12 +736,12 @@ class VMwareVMOps(object):
|
||||
"datastore %(datastore_name)s") %
|
||||
{'datastore_name': datastore_name},
|
||||
instance=instance)
|
||||
except Exception, excep:
|
||||
except Exception as excep:
|
||||
LOG.warn(_("In vmwareapi:vmops:destroy, "
|
||||
"got this exception while deleting"
|
||||
" the VM contents from the disk: %s")
|
||||
% str(excep))
|
||||
except Exception, exc:
|
||||
except Exception as exc:
|
||||
LOG.exception(exc, instance=instance)
|
||||
|
||||
def pause(self, instance):
|
||||
@ -977,7 +977,7 @@ class VMwareVMOps(object):
|
||||
"Destroy_Task", vm_ref)
|
||||
self._session._wait_for_task(instance['uuid'], destroy_task)
|
||||
LOG.debug(_("Destroyed the VM"), instance=instance)
|
||||
except Exception, excep:
|
||||
except Exception as excep:
|
||||
LOG.warn(_("In vmwareapi:vmops:confirm_migration, got this "
|
||||
"exception while destroying the VM: %s") % str(excep))
|
||||
|
||||
|
@ -68,7 +68,7 @@ def start_transfer(context, read_file_handle, data_size,
|
||||
# Wait on the read and write events to signal their end
|
||||
read_event.wait()
|
||||
write_event.wait()
|
||||
except Exception, exc:
|
||||
except Exception as exc:
|
||||
# In case of any of the reads or writes raising an exception,
|
||||
# stop the threads so that we un-necessarily don't keep the other one
|
||||
# waiting.
|
||||
|
@ -82,7 +82,7 @@ def _call_agent(session, instance, vm_ref, method, addl_args=None,
|
||||
|
||||
try:
|
||||
ret = session.call_plugin('agent', method, args)
|
||||
except session.XenAPI.Failure, e:
|
||||
except session.XenAPI.Failure as e:
|
||||
err_msg = e.details[-1].splitlines()[-1]
|
||||
if 'TIMEOUT:' in err_msg:
|
||||
LOG.error(_('TIMEOUT: The call to %(method)s timed out. '
|
||||
|
@ -638,7 +638,7 @@ class XenAPISession(object):
|
||||
session = self._create_session(url)
|
||||
with timeout.Timeout(CONF.xenapi_login_timeout, exception):
|
||||
session.login_with_password(user, pw)
|
||||
except self.XenAPI.Failure, e:
|
||||
except self.XenAPI.Failure as e:
|
||||
# if user and pw of the master are different, we're doomed!
|
||||
if e.details[0] == 'HOST_IS_SLAVE':
|
||||
master = e.details[1]
|
||||
@ -747,7 +747,7 @@ class XenAPISession(object):
|
||||
"""Parse exception details."""
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except self.XenAPI.Failure, exc:
|
||||
except self.XenAPI.Failure as exc:
|
||||
LOG.debug(_("Got exception: %s"), exc)
|
||||
if (len(exc.details) == 4 and
|
||||
exc.details[0] == 'XENAPI_PLUGIN_EXCEPTION' and
|
||||
@ -761,14 +761,14 @@ class XenAPISession(object):
|
||||
raise self.XenAPI.Failure(params)
|
||||
else:
|
||||
raise
|
||||
except xmlrpclib.ProtocolError, exc:
|
||||
except xmlrpclib.ProtocolError as exc:
|
||||
LOG.debug(_("Got exception: %s"), exc)
|
||||
raise
|
||||
|
||||
def get_rec(self, record_type, ref):
|
||||
try:
|
||||
return self.call_xenapi('%s.get_record' % record_type, ref)
|
||||
except self.XenAPI.Failure, e:
|
||||
except self.XenAPI.Failure as e:
|
||||
if e.details[0] != 'HANDLE_INVALID':
|
||||
raise
|
||||
|
||||
|
@ -864,7 +864,7 @@ class SessionBase(object):
|
||||
result = as_value(result)
|
||||
task['result'] = result
|
||||
task['status'] = 'success'
|
||||
except Failure, exc:
|
||||
except Failure as exc:
|
||||
task['error_info'] = exc.details
|
||||
task['status'] = 'failed'
|
||||
task['finished'] = timeutils.utcnow()
|
||||
|
@ -276,7 +276,7 @@ def destroy_vm(session, instance, vm_ref):
|
||||
"""Destroys a VM record."""
|
||||
try:
|
||||
session.call_xenapi('VM.destroy', vm_ref)
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.exception(exc)
|
||||
return
|
||||
|
||||
@ -292,7 +292,7 @@ def clean_shutdown_vm(session, instance, vm_ref):
|
||||
LOG.debug(_("Shutting down VM (cleanly)"), instance=instance)
|
||||
try:
|
||||
session.call_xenapi('VM.clean_shutdown', vm_ref)
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.exception(exc)
|
||||
return False
|
||||
return True
|
||||
@ -307,7 +307,7 @@ def hard_shutdown_vm(session, instance, vm_ref):
|
||||
LOG.debug(_("Shutting down VM (hard)"), instance=instance)
|
||||
try:
|
||||
session.call_xenapi('VM.hard_shutdown', vm_ref)
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.exception(exc)
|
||||
return False
|
||||
return True
|
||||
@ -339,7 +339,7 @@ def find_vbd_by_number(session, vm_ref, number):
|
||||
vbd_rec = session.call_xenapi("VBD.get_record", vbd_ref)
|
||||
if vbd_rec['userdevice'] == str(number):
|
||||
return vbd_ref
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.exception(exc)
|
||||
raise volume_utils.StorageError(
|
||||
_('VBD not found in instance %s') % vm_ref)
|
||||
@ -356,7 +356,7 @@ def unplug_vbd(session, vbd_ref):
|
||||
try:
|
||||
session.call_xenapi('VBD.unplug', vbd_ref)
|
||||
return
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
err = len(exc.details) > 0 and exc.details[0]
|
||||
if err == 'DEVICE_ALREADY_DETACHED':
|
||||
LOG.info(_('VBD %s already detached'), vbd_ref)
|
||||
@ -380,7 +380,7 @@ def destroy_vbd(session, vbd_ref):
|
||||
"""Destroy VBD from host database."""
|
||||
try:
|
||||
session.call_xenapi('VBD.destroy', vbd_ref)
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.exception(exc)
|
||||
raise volume_utils.StorageError(
|
||||
_('Unable to destroy VBD %s') % vbd_ref)
|
||||
@ -431,7 +431,7 @@ def attach_cd(session, vm_ref, vdi_ref, userdevice):
|
||||
def destroy_vdi(session, vdi_ref):
|
||||
try:
|
||||
session.call_xenapi('VDI.destroy', vdi_ref)
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.exception(exc)
|
||||
raise volume_utils.StorageError(
|
||||
_('Unable to destroy VDI %s') % vdi_ref)
|
||||
@ -493,7 +493,7 @@ def get_vdi_uuid_for_volume(session, connection_data):
|
||||
vdi_ref = volume_utils.introduce_vdi(session, sr_ref)
|
||||
vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref)
|
||||
vdi_uuid = vdi_rec['uuid']
|
||||
except volume_utils.StorageError, exc:
|
||||
except volume_utils.StorageError as exc:
|
||||
LOG.exception(exc)
|
||||
volume_utils.forget_sr(session, sr_ref)
|
||||
|
||||
@ -1389,7 +1389,7 @@ def lookup_vm_vdis(session, vm_ref):
|
||||
if not vbd_other_config.get('osvol'):
|
||||
# This is not an attached volume
|
||||
vdi_refs.append(vdi_ref)
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.exception(exc)
|
||||
return vdi_refs
|
||||
|
||||
@ -1892,7 +1892,7 @@ def cleanup_attached_vdis(session):
|
||||
try:
|
||||
vbd_rec = session.call_xenapi('VBD.get_record', vbd_ref)
|
||||
vdi_rec = session.call_xenapi('VDI.get_record', vbd_rec['VDI'])
|
||||
except session.XenAPI.Failure, e:
|
||||
except session.XenAPI.Failure as e:
|
||||
if e.details[0] != 'HANDLE_INVALID':
|
||||
raise
|
||||
continue
|
||||
|
@ -982,7 +982,7 @@ class VMOps(object):
|
||||
self._session.call_xenapi('VM.hard_reboot', vm_ref)
|
||||
else:
|
||||
self._session.call_xenapi('VM.clean_reboot', vm_ref)
|
||||
except self._session.XenAPI.Failure, exc:
|
||||
except self._session.XenAPI.Failure as exc:
|
||||
details = exc.details
|
||||
if (details[0] == 'VM_BAD_POWER_STATE' and
|
||||
details[-1] == 'halted'):
|
||||
@ -1558,7 +1558,7 @@ class VMOps(object):
|
||||
args.update(addl_args)
|
||||
try:
|
||||
return self._session.call_plugin(plugin, method, args)
|
||||
except self._session.XenAPI.Failure, e:
|
||||
except self._session.XenAPI.Failure as e:
|
||||
err_msg = e.details[-1].splitlines()[-1]
|
||||
if 'TIMEOUT:' in err_msg:
|
||||
LOG.error(_('TIMEOUT: The call to %(method)s timed out. '
|
||||
|
@ -99,7 +99,7 @@ def find_sr_from_vbd(session, vbd_ref):
|
||||
try:
|
||||
vdi_ref = session.call_xenapi("VBD.get_VDI", vbd_ref)
|
||||
sr_ref = session.call_xenapi("VDI.get_SR", vdi_ref)
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.exception(exc)
|
||||
raise StorageError(_('Unable to find SR from VBD %s') % vbd_ref)
|
||||
return sr_ref
|
||||
@ -117,7 +117,7 @@ def create_pbd(session, sr_ref, params):
|
||||
def unplug_pbds(session, sr_ref):
|
||||
try:
|
||||
pbds = session.call_xenapi("SR.get_PBDs", sr_ref)
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.warn(_('Ignoring exception %(exc)s when getting PBDs'
|
||||
' for %(sr_ref)s') % locals())
|
||||
return
|
||||
@ -125,7 +125,7 @@ def unplug_pbds(session, sr_ref):
|
||||
for pbd in pbds:
|
||||
try:
|
||||
session.call_xenapi("PBD.unplug", pbd)
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.warn(_('Ignoring exception %(exc)s when unplugging'
|
||||
' PBD %(pbd)s') % locals())
|
||||
|
||||
@ -148,7 +148,7 @@ def introduce_vdi(session, sr_ref, vdi_uuid=None, target_lun=None):
|
||||
break
|
||||
else:
|
||||
vdi_ref = (session.call_xenapi("SR.get_VDIs", sr_ref))[0]
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.exception(exc)
|
||||
raise StorageError(_('Unable to introduce VDI on SR %s') % sr_ref)
|
||||
|
||||
@ -156,7 +156,7 @@ def introduce_vdi(session, sr_ref, vdi_uuid=None, target_lun=None):
|
||||
vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref)
|
||||
LOG.debug(vdi_rec)
|
||||
LOG.debug(type(vdi_rec))
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.exception(exc)
|
||||
raise StorageError(_('Unable to get record'
|
||||
' of VDI %s on') % vdi_ref)
|
||||
@ -178,7 +178,7 @@ def introduce_vdi(session, sr_ref, vdi_uuid=None, target_lun=None):
|
||||
vdi_rec['location'],
|
||||
vdi_rec['xenstore_data'],
|
||||
vdi_rec['sm_config'])
|
||||
except session.XenAPI.Failure, exc:
|
||||
except session.XenAPI.Failure as exc:
|
||||
LOG.exception(exc)
|
||||
raise StorageError(_('Unable to introduce VDI for SR %s')
|
||||
% sr_ref)
|
||||
|
@ -172,7 +172,7 @@ class VolumeOps(object):
|
||||
# within XenServer, update this to fail-fast when this is fixed
|
||||
# upstream
|
||||
self._session.call_xenapi("SR.scan", sr_ref)
|
||||
except self._session.XenAPI.Failure, exc:
|
||||
except self._session.XenAPI.Failure as exc:
|
||||
if exc.details[0] == 'SR_BACKEND_FAILURE_40':
|
||||
vbd_rec = vbd_rec = self._session.call_xenapi(
|
||||
"VBD.get_record", vbd_ref)
|
||||
|
Loading…
Reference in New Issue
Block a user