Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
msg = _("Requested network does not contain "
"enough (2+) usable hosts")
raise exc.HTTPBadRequest(explanation=msg)
except netexc.AddrFormatError:
msg = _("CIDR is malformed.")
raise exc.HTTPBadRequest(explanation=msg)
except netexc.AddrConversionError:
msg = _("Address could not be converted.")
raise exc.HTTPBadRequest(explanation=msg)
networks = []
try:
if CONF.enable_network_quota:
reservation = QUOTAS.reserve(context, networks=1)
except exception.OverQuota:
msg = _("Quota exceeded, too many networks.")
raise exc.HTTPBadRequest(explanation=msg)
kwargs['project_id'] = context.project_id
try:
networks = self.network_api.create(context,
label=label, **kwargs)
if CONF.enable_network_quota:
QUOTAS.commit(context, reservation)
except exception.PolicyNotAuthorized as e:
raise exc.HTTPForbidden(explanation=six.text_type(e))
except exception.CidrConflict as e:
raise exc.HTTPConflict(explanation=e.format_message())
except Exception:
if CONF.enable_network_quota:
QUOTAS.rollback(context, reservation)
class FloatingIpPoolNotFound(NotFound):
msg_fmt = _("Floating IP pool not found.")
safe = True
class NoMoreFloatingIps(FloatingIpNotFound):
msg_fmt = _("Zero floating IPs available.")
safe = True
class FloatingIpAssociated(NovaException):
msg_fmt = _("Floating IP %(address)s is associated.")
class FloatingIpNotAssociated(NovaException):
msg_fmt = _("Floating IP %(address)s is not associated.")
class NoFloatingIpsDefined(NotFound):
msg_fmt = _("Zero floating IPs exist.")
class NoFloatingIpInterface(NotFound):
msg_fmt = _("Interface %(interface)s not found.")
class FloatingIpAllocateFailed(NovaException):
msg_fmt = _("Floating IP allocate failed.")
class FloatingIpAssociateFailed(NovaException):
msg_fmt = _("Floating IP %(address)s association has failed.")
# be rolled up at the end of the check() function. These functions are
# intended to be run in order and build on top of each other so order
# matters.
_upgrade_checks = (
# Added in Ocata
(_('Cells v2'), _check_cellsv2),
# Added in Ocata
(_('Placement API'), _check_placement),
# Added in Rocky (but also useful going back to Pike)
(_('Ironic Flavor Migration'), _check_ironic_flavor_migration),
# Added in Rocky
(_('Request Spec Migration'), _check_request_spec_migration),
# Added in Stein (but also useful going back to Rocky)
(_('Console Auths'), _check_console_auths),
# Added in Train
(_('Cinder API'), _check_cinder),
)
CATEGORIES = {
'upgrade': UpgradeCommands,
}
add_command_parsers = functools.partial(cmd_common.add_command_parsers,
categories=CATEGORIES)
category_opt = cfg.SubCommandOpt('category',
title='Command categories',
help='Available categories',
handler=add_command_parsers)
def _get_kstat_by_name(self, kstat_class, module, instance, name):
"""Return Kstat snapshot data via RAD as a dictionary."""
pattern = {
'class': kstat_class,
'module': module,
'instance': instance,
'name': name
}
try:
self._kstat_control.update()
kstat_object = self.rad_connection.get_object(
kstat.Kstat(), rad.client.ADRGlobPattern(pattern))
except Exception as reason:
LOG.info(_("Unable to retrieve kstat object '%s:%s:%s' of class "
"'%s' via kstat(3RAD): %s")
% (module, instance, name, kstat_class, reason))
return None
kstat_data = {}
for named in kstat_object.fresh_snapshot().data.NAMED:
kstat_data[named.name] = getattr(named.value,
str(named.value.discriminant))
return kstat_data
def __init__(self, driver, name, pool=None, snapshot=None,
read_only=False):
client, ioctx = driver._connect_to_rados(pool)
try:
self.volume = tpool.Proxy(rbd.Image(ioctx, name,
snapshot=snapshot,
read_only=read_only))
except rbd.ImageNotFound:
with excutils.save_and_reraise_exception():
LOG.debug("rbd image %s does not exist", name)
driver._disconnect_from_rados(client, ioctx)
except rbd.Error:
with excutils.save_and_reraise_exception():
LOG.exception(_("error opening rbd image %s"), name)
driver._disconnect_from_rados(client, ioctx)
self.driver = driver
self.client = client
self.ioctx = ioctx
class OsInfoNotFound(NotFound):
msg_fmt = _("No configuration information found for operating system "
"%(os_name)s")
class BuildRequestNotFound(NotFound):
msg_fmt = _("BuildRequest not found for instance %(uuid)s")
class AttachInterfaceNotSupported(Invalid):
msg_fmt = _("Attaching interfaces is not supported for "
"instance %(instance_uuid)s.")
class AttachInterfaceWithQoSPolicyNotSupported(AttachInterfaceNotSupported):
msg_fmt = _("Attaching interfaces with QoS policy is not supported for "
"instance %(instance_uuid)s.")
class NetworksWithQoSPolicyNotSupported(Invalid):
msg_fmt = _("Using networks with QoS policy is not supported for "
"instance %(instance_uuid)s. (Network ID is %(network_id)s)")
class CreateWithPortResourceRequestOldVersion(Invalid):
msg_fmt = _("Creating servers with ports having resource requests, like a "
"port with a QoS minimum bandwidth policy, is not supported "
"until microversion 2.72.")
class InvalidReservedMemoryPagesOption(Invalid):
msg_fmt = _("The format of the option 'reserved_huge_pages' is invalid. "
instance, network_id, port_id, req_ip)
except (exception.PortNotFound,
exception.NetworkNotFound) as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except (exception.FixedIpAlreadyInUse,
exception.InterfaceAttachFailedNoNetwork,
exception.NoMoreFixedIps,
exception.PortInUse,
exception.NetworkDuplicated,
exception.NetworkAmbiguous,
exception.PortNotUsable) as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except NotImplementedError:
msg = _("Network driver does not support this function.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
except exception.InterfaceAttachFailed:
msg = _("Failed to attach interface")
raise webob.exc.HTTPInternalServerError(explanation=msg)
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'attach_interface', server_id)
return self.show(req, server_id, vif['id'])
"value": value,
"aggregate_id": aggregate_id})
if new_entries:
context.session.execute(
api_models.AggregateMetadata.__table__.insert(),
new_entries)
return metadata
except db_exc.DBDuplicateEntry:
# a concurrent transaction has been committed,
# try again unless this was the last attempt
with excutils.save_and_reraise_exception() as ctxt:
if attempt < max_retries - 1:
ctxt.reraise = False
else:
msg = _("Add metadata failed for aggregate %(id)s "
"after %(retries)s retries") % \
{"id": aggregate_id, "retries": max_retries}
LOG.warning(msg)
def _check_body(self, body):
if body is None or body == "":
raise webob.exc.HTTPBadRequest(explanation=_("No request body"))
def validate_device_name(value):
try:
# NOTE (ndipanov): Do not allow empty device names
# until assigning default values
# are supported by nova.compute
utils.check_string_length(value, 'Device name',
min_length=1, max_length=255)
except exception.InvalidInput:
raise exception.InvalidBDMFormat(
details=_("Device name empty or too long."))
if ' ' in value:
raise exception.InvalidBDMFormat(
details=_("Device name contains spaces."))