Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _list_cobalt_hosts(self, context, availability_zone=None):
""" Returns a list of all the hosts known to openstack running the cobalt service. """
admin_context = context.elevated()
services = self.db.service_get_all_by_topic(admin_context, CONF.cobalt_topic)
if availability_zone is not None and ':' in availability_zone:
parts = availability_zone.split(':')
if len(parts) > 2:
raise exception.NovaException(_('Invalid availability zone'))
az = parts[0]
host = parts[1]
if (az, host) in [(srv['availability_zone'], srv['host']) for srv in services]:
return [host]
else:
return []
hosts = []
for srv in services:
in_availability_zone = availability_zone is None or \
availability_zone == \
availability_zones.get_host_availability_zone(context,srv['host'])
if srv['host'] not in hosts and in_availability_zone:
hosts.append(srv['host'])
return hosts
raise exception.NovaException(msg)
_execute('brctl', 'setfd', bridge, 0, run_as_root=True)
# _execute('brctl setageing %s 10' % bridge, run_as_root=True)
_execute('brctl', 'stp', bridge, 'off', run_as_root=True)
nova.privsep.linux_net.set_device_enabled(bridge)
if interface:
LOG.debug('Adding interface %(interface)s to bridge %(bridge)s',
{'interface': interface, 'bridge': bridge})
out, err = _execute('brctl', 'addif', bridge, interface,
check_exit_code=False, run_as_root=True)
if (err and err != "device %s is already a member of a bridge; "
"can't enslave it to bridge %s.\n" % (interface, bridge)):
msg = _('Failed to add interface: %s') % err
raise exception.NovaException(msg)
# NOTE(apmelton): Linux bridge's default behavior is to use the
# lowest mac of all plugged interfaces. This isn't a problem when
# it is first created and the only interface is the bridged
# interface. But, as instance interfaces are plugged, there is a
# chance for the mac to change. So, set it here so that it won't
# change in the future.
if not CONF.fake_network:
interface_addrs = netifaces.ifaddresses(interface)
interface_mac = interface_addrs[netifaces.AF_LINK][0]['addr']
nova.privsep.linux_net.set_device_macaddr(
bridge, interface_mac)
nova.privsep.linux_net.set_device_enabled(interface)
# NOTE(vish): This will break if there is already an ip on the
Return a dictionary with information about the device.
"""
slot_regex = _compile_hex(r"Slot:\t"
r"((?:hex{4}:)?" # Domain: (optional)
r"hex{2}:" # Bus:
r"hex{2}\." # Device.
r"hex{1})") # Function
vendor_regex = _compile_hex(r"\nVendor:\t(hex+)")
product_regex = _compile_hex(r"\nDevice:\t(hex+)")
slot_id = slot_regex.findall(dev_string)
vendor_id = vendor_regex.findall(dev_string)
product_id = product_regex.findall(dev_string)
if not slot_id or not vendor_id or not product_id:
raise exception.NovaException(
_("Failed to parse information about"
" a pci device for passthrough"))
type_pci = host_management.get_pci_type(self._session, slot_id[0])
return {'label': '_'.join(['label',
vendor_id[0],
product_id[0]]),
'vendor_id': vendor_id[0],
'product_id': product_id[0],
'address': slot_id[0],
'dev_id': '_'.join(['pci', slot_id[0]]),
'dev_type': type_pci,
'status': 'available'}
def unplug(self, instance, vif):
vif_type = vif['type']
LOG.debug('vif_type=%(vif_type)s instance=%(instance)s '
'vif=%(vif)s',
{'vif_type': vif_type, 'instance': instance,
'vif': vif})
if vif_type is None:
raise exception.NovaException(
_("vif_type parameter must be present "
"for this vif_driver implementation"))
# Try os-vif codepath first
vif_obj = os_vif_util.nova_to_osvif_vif(vif)
if vif_obj is not None:
self._unplug_os_vif(instance, vif_obj)
return
# Legacy non-os-vif codepath
func = getattr(self, 'unplug_%s' % vif_type, None)
if not func:
raise exception.NovaException(
_("Unexpected vif_type=%s") % vif_type)
func(instance, vif)
class FixedIpAssociatedWithMultipleInstances(NovaException):
msg_fmt = _("More than one instance is associated with fixed IP address "
"'%(address)s'.")
class FixedIpInvalid(Invalid):
msg_fmt = _("Fixed IP address %(address)s is invalid.")
class FixedIpInvalidOnHost(Invalid):
msg_fmt = _("The fixed IP associated with port %(port_id)s is not "
"compatible with the host.")
class NoMoreFixedIps(NovaException):
msg_fmt = _("No fixed IP addresses available for network: %(net)s")
class NoFixedIpsDefined(NotFound):
msg_fmt = _("Zero fixed IPs could be found.")
class FloatingIpExists(NovaException):
msg_fmt = _("Floating IP %(address)s already exists.")
class FloatingIpNotFound(NotFound):
msg_fmt = _("Floating IP not found for ID %(id)s.")
class FloatingIpDNSExists(Invalid):
class FixedIpNotFoundForSpecificInstance(FixedIpNotFound):
msg_fmt = _("Instance %(instance_uuid)s doesn't have fixed IP '%(ip)s'.")
class FixedIpNotFoundForNetwork(FixedIpNotFound):
msg_fmt = _("Fixed IP address (%(address)s) does not exist in "
"network (%(network_uuid)s).")
class FixedIpAssociateFailed(NovaException):
msg_fmt = _("Fixed IP associate failed for network: %(net)s.")
class FixedIpAlreadyInUse(NovaException):
msg_fmt = _("Fixed IP address %(address)s is already in use on instance "
"%(instance_uuid)s.")
class FixedIpAssociatedWithMultipleInstances(NovaException):
msg_fmt = _("More than one instance is associated with fixed IP address "
"'%(address)s'.")
class FixedIpInvalid(Invalid):
msg_fmt = _("Fixed IP address %(address)s is invalid.")
class FixedIpInvalidOnHost(Invalid):
msg_fmt = _("The fixed IP associated with port %(port_id)s is not "
"compatible with the host.")
def _get_conn(self):
if not CONF.baremetal.virtual_power_ssh_host:
raise exception.NovaException(
_('virtual_power_ssh_host not defined. Can not Start'))
if not CONF.baremetal.virtual_power_host_user:
raise exception.NovaException(
_('virtual_power_host_user not defined. Can not Start'))
if not CONF.baremetal.virtual_power_host_pass:
# it is ok to not have a password if you have a keyfile
if CONF.baremetal.virtual_power_host_key is None:
raise exception.NovaException(
_('virtual_power_host_pass/key not set. Can not Start'))
_conn = connection.Connection(
CONF.baremetal.virtual_power_ssh_host,
CONF.baremetal.virtual_power_host_user,
CONF.baremetal.virtual_power_host_pass,
CONF.baremetal.virtual_power_ssh_port,
CONF.baremetal.virtual_power_host_key)
return _conn
if network["bridge"] is not None:
netobj.bridge = network['bridge']
if network['label'] is not None:
netobj.label = network['label']
if network.get_meta("mtu") is not None:
netobj.mtu = network.get_meta("mtu")
if network.get_meta("multi_host") is not None:
netobj.multi_host = network.get_meta("multi_host")
if network.get_meta("should_create_bridge") is not None:
netobj.should_provide_bridge = \
network.get_meta("should_create_bridge")
if network.get_meta("should_create_vlan") is not None:
netobj.should_provide_vlan = network.get_meta("should_create_vlan")
if network.get_meta("vlan") is None:
raise exception.NovaException(_("Missing vlan number in %s") %
network)
netobj.vlan = network.get_meta("vlan")
return netobj
def fn(self, *args, **kwargs):
try:
return action(self, *args, **kwargs)
except novaexc.NovaException as error:
raise exc.HTTPBadRequest(explanation=unicode(error))
# note(dscannell): Openstack sometimes does matching on the function name so we need to
class FixedIpNotFoundForNetwork(FixedIpNotFound):
message = _("Fixed IP address (%(address)s) does not exist in "
"network (%(network_uuid)s).")
class FixedIpAlreadyInUse(NovaException):
message = _("Fixed IP address %(address)s is already in use.")
class FixedIpInvalid(Invalid):
message = _("Fixed IP address %(address)s is invalid.")
class NoMoreFixedIps(NovaException):
message = _("Zero fixed ips available.")
class NoFixedIpsDefined(NotFound):
message = _("Zero fixed ips could be found.")
class FloatingIpNotFound(NotFound):
message = _("Floating ip not found for id %(id)s.")
class FloatingIpNotFoundForAddress(FloatingIpNotFound):
message = _("Floating ip not found for address %(address)s.")
class FloatingIpNotFoundForProject(FloatingIpNotFound):