本文整理汇总了Python中nova.compute.utils.get_nw_info_for_instance函数的典型用法代码示例。如果您正苦于以下问题:Python get_nw_info_for_instance函数的具体用法?Python get_nw_info_for_instance怎么用?Python get_nw_info_for_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_nw_info_for_instance函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _test_init_instance_reverts_crashed_migrations
def _test_init_instance_reverts_crashed_migrations(self, old_vm_state=None):
power_on = True if (not old_vm_state or old_vm_state == vm_states.ACTIVE) else False
sys_meta = {"old_vm_state": old_vm_state}
instance = {
"uuid": "foo",
"vm_state": vm_states.ERROR,
"task_state": task_states.RESIZE_MIGRATING,
"power_state": power_state.SHUTDOWN,
"system_metadata": sys_meta,
}
fixed = dict(instance, task_state=None)
self.mox.StubOutWithMock(compute_utils, "get_nw_info_for_instance")
self.mox.StubOutWithMock(utils, "instance_sys_meta")
self.mox.StubOutWithMock(self.compute.driver, "plug_vifs")
self.mox.StubOutWithMock(self.compute.driver, "finish_revert_migration")
self.mox.StubOutWithMock(self.compute, "_get_instance_volume_block_device_info")
self.mox.StubOutWithMock(self.compute.driver, "get_info")
self.mox.StubOutWithMock(self.compute, "_instance_update")
compute_utils.get_nw_info_for_instance(instance).AndReturn(network_model.NetworkInfo())
self.compute.driver.plug_vifs(instance, [])
utils.instance_sys_meta(instance).AndReturn(sys_meta)
self.compute._get_instance_volume_block_device_info(self.context, instance).AndReturn([])
self.compute.driver.finish_revert_migration(instance, [], [], power_on)
self.compute._instance_update(self.context, instance["uuid"], task_state=None).AndReturn(fixed)
self.compute.driver.get_info(fixed).AndReturn({"state": power_state.SHUTDOWN})
self.mox.ReplayAll()
self.compute._init_instance(self.context, instance)
开发者ID:jziub,项目名称:nova,代码行数:30,代码来源:test_compute_mgr.py
示例2: _add_floating_ip
def _add_floating_ip(self, req, id, body):
"""Associate floating_ip to an instance."""
context = req.environ['nova.context']
authorize(context)
address = body['addFloatingIp']['address']
instance = common.get_instance(self.compute_api, context, id,
want_objects=True)
cached_nwinfo = compute_utils.get_nw_info_for_instance(instance)
if not cached_nwinfo:
msg = _('No nw_info cache associated with instance')
raise webob.exc.HTTPBadRequest(explanation=msg)
fixed_ips = cached_nwinfo.fixed_ips()
if not fixed_ips:
msg = _('No fixed ips associated to instance')
raise webob.exc.HTTPBadRequest(explanation=msg)
fixed_address = None
if 'fixed_address' in body['addFloatingIp']:
fixed_address = body['addFloatingIp']['fixed_address']
for fixed in fixed_ips:
if fixed['address'] == fixed_address:
break
else:
msg = _('Specified fixed address not assigned to instance')
raise webob.exc.HTTPBadRequest(explanation=msg)
if not fixed_address:
fixed_address = fixed_ips[0]['address']
if len(fixed_ips) > 1:
LOG.warning(_LW('multiple fixed_ips exist, using the first: '
'%s'), fixed_address)
try:
self.network_api.associate_floating_ip(context, instance,
floating_address=address,
fixed_address=fixed_address)
except exception.FloatingIpAssociated:
msg = _('floating ip is already associated')
raise webob.exc.HTTPBadRequest(explanation=msg)
except exception.NoFloatingIpInterface:
msg = _('l3driver call to add floating ip failed')
raise webob.exc.HTTPBadRequest(explanation=msg)
except exception.FloatingIpNotFoundForAddress:
msg = _('floating ip not found')
raise webob.exc.HTTPNotFound(explanation=msg)
except exception.Forbidden as e:
raise webob.exc.HTTPForbidden(explanation=e.format_message())
except Exception as e:
msg = _('Unable to associate floating ip %(address)s to '
'fixed ip %(fixed_address)s for instance %(id)s. '
'Error: %(error)s') % (
{'address': address, 'fixed_address': fixed_address,
'id': id, 'error': e})
LOG.exception(msg)
raise webob.exc.HTTPBadRequest(explanation=msg)
return webob.Response(status_int=202)
开发者ID:dtroyer,项目名称:nova,代码行数:60,代码来源:floating_ips.py
示例3: _prepare_instance
def _prepare_instance(self, context, instance):
instance["name"] = instance["display_name"]
instance["status"] = self._status_map.get(
instance["vm_state"], instance["vm_state"])
image_id = instance["image_ref"]
if image_id is None or len(image_id) == 0:
image_id = instance["system_metadata"]["image_base_image_ref"]
if image_id is None or len(image_id) == 0:
image_id = instance["system_metadata"]["image_image_id"]
image = image_api.API().get_item_by_id(context, image_id)
if image is not None:
instance["image"] = image['name']
instance["cached_nwinfo"] = \
compute_utils.get_nw_info_for_instance(instance)
attached_disks = db.block_device_mapping_get_all_by_instance(
nova_context.get_admin_context(), instance['uuid'])
for disk in attached_disks:
if disk["volume_id"] is not None:
disk["volume"] = disk_api.API().get_item_by_id(
context, disk["volume_id"])
instance["attached_disks"] = attached_disks
return instance
开发者ID:pombredanne,项目名称:gce,代码行数:26,代码来源:instance_api.py
示例4: get_vifs_for_instance
def get_vifs_for_instance(self, context, **kwargs):
"""Return the list of VIF for an instance."""
instance_id = kwargs['instance_id']
LOG.debug('get_vifs_for_instance %s' % instance_id)
instance = objects.Instance.get_by_uuid(
nova_context.get_admin_context(), instance_id)
hyper_net_info = compute_utils.get_nw_info_for_instance(instance)
neutron = neutronapi.get_client(context, admin=True)
check_host_exist(neutron, instance_id)
tenant_ids = []
LOG.debug('hyper_net_info: %s' % hyper_net_info)
for vif in hyper_net_info:
tenant_ids.append(vif['network']['meta']['tenant_id'])
neutron.update_port(vif['id'],
{'port': {'binding:host_id': instance_id}})
# get all the tenant router
LOG.debug('tenant_ids: %s' % tenant_ids)
for tenant_id in tenant_ids:
routers = neutron.list_routers({'tenant_id': tenant_id})['routers']
LOG.debug('routers: %s' % routers)
for router in routers:
neutron.update_router(router['id'],
{'router': {'admin_state_up': 'False'}})
neutron.update_router(router['id'],
{'router': {'admin_state_up': 'True'}})
return hyper_net_info
开发者ID:lionelz,项目名称:hybridcloud,代码行数:28,代码来源:hyper_agent_api.py
示例5: get_vif_for_provider_ip
def get_vif_for_provider_ip(self, context, **kwargs):
"""Return the VIF for a VM."""
provider_ip = kwargs['provider_ip']
LOG.debug("provider ip = % s" % provider_ip)
# retrieve the instance id from the provider ip
# from the nova metadata
filters = {
'filter': [{'name': 'tag:provider_ip', 'value': provider_ip}]
}
instances = objects.InstanceList.get_by_filters(
context, filters=filters)
# should return only one and check it
if len(instances) == 1:
instance = instances[0]
vif_id = instance.metadata['ip_%s' % provider_ip]
hyper_net_info = compute_utils.get_nw_info_for_instance(instance)
hyper_vif = None
for vif in hyper_net_info:
if vif.get('id') == vif_id:
hyper_vif = vif
break
neutron = neutronapi.get_client(context, admin=True)
check_host_exist(neutron, instance.uuid)
neutron.update_port(hyper_vif,
{'port': {'binding:host_id': instance.uuid}})
return {'instance_id': instance.uuid, 'hyper_vif': hyper_vif}
else:
return None
开发者ID:lionelz,项目名称:hybridcloud,代码行数:28,代码来源:hyper_agent_api.py
示例6: add_floating_ip
def add_floating_ip(uid, pool_name, context):
"""
Adds an ip to an VM instance.
uid -- id of the VM.
pool_name -- name of the pool
context -- The os context.
"""
vm_instance = vm.get_vm(uid, context)
cached_nwinfo = utils.get_nw_info_for_instance(vm_instance)
if not cached_nwinfo:
raise AttributeError('No nw_info cache associated with instance')
fixed_ips = cached_nwinfo.fixed_ips()
if not fixed_ips:
raise AttributeError('No fixed ips associated to instance')
float_address = NETWORK_API.allocate_floating_ip(context, pool_name)
try:
address = fixed_ips[0]['address']
NETWORK_API.associate_floating_ip(context, vm_instance,
float_address, address)
except exception.FloatingIpAssociated:
msg = 'floating ip is already associated'
raise AttributeError(msg)
except exception.NoFloatingIpInterface:
msg = 'l3driver call to add floating ip failed'
raise AttributeError(msg)
return float_address
开发者ID:Acidburn0zzz,项目名称:occi-os,代码行数:31,代码来源:net.py
示例7: get_vifs_for_instance
def get_vifs_for_instance(self, context, **kwargs):
"""Return the list of VIF for an instance."""
instance_id = kwargs['instance_id']
LOG.debug("get_vifs_for_instance %s" % instance_id)
instance = objects.Instance.get_by_uuid(
nova_context.get_admin_context(), instance_id)
net_info = compute_utils.get_nw_info_for_instance(instance)
# TODO: retrieve the provider_net_info (IP/MAC)
return {'net_info': net_info,
'provider_net_info': [None, None, None]}
开发者ID:Hybrid-Cloud,项目名称:jacket,代码行数:10,代码来源:hyper_agent_api.py
示例8: _get_instances_with_network
def _get_instances_with_network(self, context, network, zone_id):
affected_instances = []
network_id = network['id']
instances = self.get_items(context, zone_id)
for instance in instances:
cached_nwinfo = compute_utils.get_nw_info_for_instance(instance)
if cached_nwinfo:
for network_info in cached_nwinfo:
if network_id == network_info['network']['id']:
affected_instances.append(instance)
return affected_instances
开发者ID:pombredanne,项目名称:gce,代码行数:11,代码来源:instance_api.py
示例9: _add_floating_ip
def _add_floating_ip(self, req, id, body):
"""Associate floating_ip to an instance."""
context = req.environ['nova.context']
authorize(context)
try:
address = body['addFloatingIp']['address']
except TypeError:
msg = _("Missing parameter dict")
raise webob.exc.HTTPBadRequest(explanation=msg)
except KeyError:
msg = _("Address not specified")
raise webob.exc.HTTPBadRequest(explanation=msg)
instance = self.compute_api.get(context, id)
cached_nwinfo = compute_utils.get_nw_info_for_instance(instance)
if not cached_nwinfo:
msg = _('No nw_info cache associated with instance')
raise webob.exc.HTTPBadRequest(explanation=msg)
fixed_ips = cached_nwinfo.fixed_ips()
if not fixed_ips:
msg = _('No fixed ips associated to instance')
raise webob.exc.HTTPBadRequest(explanation=msg)
# TODO(tr3buchet): this will associate the floating IP with the
# first fixed_ip an instance has. This should be
# changed to support specifying a particular fixed_ip if
# multiple exist.
if len(fixed_ips) > 1:
msg = _('multiple fixed_ips exist, using the first: %s')
LOG.warning(msg, fixed_ips[0]['address'])
try:
self.network_api.associate_floating_ip(context, instance,
floating_address=address,
fixed_address=fixed_ips[0]['address'])
except exception.FloatingIpAssociated:
msg = _('floating ip is already associated')
raise webob.exc.HTTPBadRequest(explanation=msg)
except exception.NoFloatingIpInterface:
msg = _('l3driver call to add floating ip failed')
raise webob.exc.HTTPBadRequest(explanation=msg)
except (exception.FloatingIpNotFoundForAddress,
exception.NotAuthorized):
msg = _('floating ip not found')
raise webob.exc.HTTPNotFound(explanation=msg)
except Exception:
msg = _('Error. Unable to associate floating ip')
LOG.exception(msg)
raise webob.exc.HTTPBadRequest(explanation=msg)
return webob.Response(status_int=202)
开发者ID:DarkSinclair,项目名称:nova,代码行数:54,代码来源:floating_ips.py
示例10: _get_existing_networks
def _get_existing_networks(self, context, server_id):
"""Returns networks a server is already connected to."""
instance = self.get_instance(context, server_id)
nw_info = compute_utils.get_nw_info_for_instance(instance)
networks = []
for vif in nw_info:
networks.append(vif["network"]["id"])
if not networks:
return set()
return set(networks)
开发者ID:bria0653,项目名称:wafflehaus.nova,代码行数:12,代码来源:network_count_check.py
示例11: _test_init_instance_reverts_crashed_migrations
def _test_init_instance_reverts_crashed_migrations(self,
old_vm_state=None):
power_on = True if (not old_vm_state or
old_vm_state == vm_states.ACTIVE) else False
sys_meta = {
'old_vm_state': old_vm_state
}
instance = {
'uuid': 'foo',
'vm_state': vm_states.ERROR,
'task_state': task_states.RESIZE_MIGRATING,
'power_state': power_state.SHUTDOWN,
'system_metadata': sys_meta
}
fixed = dict(instance, task_state=None)
self.mox.StubOutWithMock(compute_utils, 'get_nw_info_for_instance')
self.mox.StubOutWithMock(utils, 'instance_sys_meta')
self.mox.StubOutWithMock(self.compute.driver, 'plug_vifs')
self.mox.StubOutWithMock(self.compute.driver,
'finish_revert_migration')
self.mox.StubOutWithMock(self.compute,
'_get_instance_volume_block_device_info')
self.mox.StubOutWithMock(self.compute.driver, 'get_info')
self.mox.StubOutWithMock(self.compute, '_instance_update')
compute_utils.get_nw_info_for_instance(instance).AndReturn(
network_model.NetworkInfo())
self.compute.driver.plug_vifs(instance, [])
utils.instance_sys_meta(instance).AndReturn(sys_meta)
self.compute._get_instance_volume_block_device_info(
self.context, instance).AndReturn([])
self.compute.driver.finish_revert_migration(instance, [], [], power_on)
self.compute._instance_update(self.context, instance['uuid'],
task_state=None).AndReturn(fixed)
self.compute.driver.get_info(fixed).AndReturn(
{'state': power_state.SHUTDOWN})
self.mox.ReplayAll()
self.compute._init_instance(self.context, instance)
开发者ID:Ivan-Zhu,项目名称:nova-v3-api-doc,代码行数:40,代码来源:test_compute_mgr.py
示例12: get_networks_for_instance
def get_networks_for_instance(context, instance):
"""Returns a prepared nw_info list for passing into the view builders
We end up with a data structure like::
{'public': {'ips': [{'addr': '10.0.0.1', 'version': 4},
{'addr': '2001::1', 'version': 6}],
'floating_ips': [{'addr': '172.16.0.1', 'version': 4},
{'addr': '172.16.2.1', 'version': 4}]},
...}
"""
nw_info = compute_utils.get_nw_info_for_instance(instance)
return get_networks_for_instance_from_nw_info(nw_info)
开发者ID:AnyBucket,项目名称:nova,代码行数:13,代码来源:common.py
示例13: _gather_port_ids
def _gather_port_ids(self, context, instance,
port_ids=None):
"""Return an instance's complete list of port_ids."""
ifaces = compute_utils.get_nw_info_for_instance(instance)
# This code path is only done when refreshing the network_cache
if port_ids is None:
port_ids = [iface['id'] for iface in ifaces]
else:
# an interface was added/removed from instance.
# Include existing interfaces so they are not removed from the db.
port_ids = [iface['id'] for iface in ifaces] + port_ids
return port_ids
开发者ID:iawells,项目名称:gluon-nova,代码行数:14,代码来源:api.py
示例14: _get_network_info
def _get_network_info(self, context, server_id, entity_maker):
"""Returns a list of VIFs, transformed through entity_maker."""
instance = self._get_instance(context, server_id)
nw_info = compute_utils.get_nw_info_for_instance(instance)
vifs = []
for vif in nw_info:
addr = [dict(network_id=vif["network"]["id"],
network_label=vif["network"]["label"],
address=ip["address"]) for ip in vif.fixed_ips()]
v = dict(address=vif["address"],
id=vif["id"],
ip_addresses=addr)
vifs.append(entity_maker(context, v))
return {'virtual_interfaces': vifs}
开发者ID:broble,项目名称:wafflehaus.nova,代码行数:14,代码来源:detach_network_check.py
示例15: __init__
def __init__(self, instance, **kwargs):
super(InstancePayload, self).__init__(**kwargs)
# Note(gibi): ugly but needed to avoid cyclic import
from nova.compute import utils
network_info = utils.get_nw_info_for_instance(instance)
ips = IpPayload.from_network_info(network_info)
flavor = flavor_payload.FlavorPayload(flavor=instance.flavor)
super(InstancePayload, self).__init__(
ip_addresses=ips,
flavor=flavor,
**kwargs)
self.populate_schema(instance=instance)
开发者ID:andymcc,项目名称:nova,代码行数:17,代码来源:instance.py
示例16: add_flaoting_ip_to_vm
def add_flaoting_ip_to_vm(uid, attributes, context):
"""
Adds an ip to an VM instance.
uid -- id of the VM.
attributes -- the call attributes (dict)
context -- The os context.
"""
vm_instance = vm.get_vm(uid, context)
cached_nwinfo = compute_utils.get_nw_info_for_instance(vm_instance)
if not cached_nwinfo:
raise AttributeError('No nw_info cache associated with instance')
fixed_ips = cached_nwinfo.fixed_ips()
if not fixed_ips:
raise AttributeError('No fixed ips associated to instance')
if 'org.openstack.network.floating.pool' not in attributes:
pool = None
else:
pool = attributes['org.openstack.network.floating.pool']
float_address = NETWORK_API.allocate_floating_ip(context, pool)
if len(fixed_ips) > 1:
LOG.warn('multiple fixed_ips exist, using the first')
try:
address = fixed_ips[0]['address']
NETWORK_API.associate_floating_ip(context, vm_instance,
floating_address=float_address,
fixed_address=address)
except exception.FloatingIpAssociated:
msg = 'floating ip is already associated'
raise AttributeError(msg)
except exception.NoFloatingIpInterface:
msg = 'l3driver call to add floating ip failed'
raise AttributeError(msg)
except Exception as error:
msg = 'Error. Unable to associate floating ip' + str(error)
raise AttributeError(msg)
return float_address
开发者ID:dizz,项目名称:occi-os,代码行数:43,代码来源:net.py
示例17: _build_network_info_model
def _build_network_info_model(self, context, instance, networks=None,
port_ids=None):
LOG.debug('Enter _build_network_info_model with instance %s and '
'networks %s' % (instance['project_id'], networks))
# Get all the nova networks associated with the neutron network passed
# in. If no neutron network was passed in, this will return all nova
# networks.
net_infos = []
if networks is None and port_ids is None:
# We need to check to see if the cache thinks we're none as well
network_info = compute_utils.get_nw_info_for_instance(instance)
# If the network info is an empty list...it may be valid. However,
# it is improbable. We should go query against the master list,
# which is neutron.
if network_info is None or len(network_info) == 0:
net_infos = self._update_instance_nw_cache(instance, context)
# We didn't get the network infos - this could mean that the cache data
# on the instance is proper. So let's call neutron's parent API and
# get network details.
if net_infos == []:
net_infos = super(PowerVMAPI,
self)._build_network_info_model(context,
instance,
networks,
port_ids)
LOG.debug('Found net_infos %s' % net_infos)
# Get the neutron networks related to our instance if the invoker did
# not pass them in.
if not networks:
networks = self._get_available_networks(context,
instance['project_id'])
msg = (ras.vif_get_msg
('info', 'NO_NET_FOUND') % {'host': instance['host']})
ras.function_tracepoint(LOG, __name__, ras.TRACE_INFO, msg)
# Pare down the nova networks list to only include those that map to
# the neutron network we're interested in. This will also add in the
# vlan id to the nova network object.
return self._match_network_models(networks, net_infos, context)
开发者ID:windskyer,项目名称:k_nova,代码行数:42,代码来源:ibmpowervm_api.py
示例18: _gather_port_ids_and_networks
def _gather_port_ids_and_networks(self, context, instance, networks=None, port_ids=None):
"""Return an instance's complete list of port_ids and networks."""
if (networks is None and port_ids is not None) or (port_ids is None and networks is not None):
message = (
"This method needs to be called with either "
"networks=None and port_ids=None or port_ids and "
" networks as not none."
)
raise exception.NovaException(message=message)
ifaces = compute_utils.get_nw_info_for_instance(instance)
# This code path is only done when refreshing the network_cache
if port_ids is None:
port_ids = [iface["id"] for iface in ifaces]
net_ids = [iface["network"]["id"] for iface in ifaces]
if networks is None:
networks = self._get_available_networks(context, instance["project_id"], net_ids)
# an interface was added/removed from instance.
else:
# Since networks does not contain the existing networks on the
# instance we use their values from the cache and add it.
networks = networks + [
{
"id": iface["network"]["id"],
"name": iface["network"]["label"],
"tenant_id": iface["network"]["meta"]["tenant_id"],
}
for iface in ifaces
]
# Include existing interfaces so they are not removed from the db.
port_ids = [iface["id"] for iface in ifaces] + port_ids
iface_slot_map = {}
for iface in ifaces:
iface_slot_map[iface["id"]] = iface["meta"].get("pci_slotnum", None)
return networks, port_ids, iface_slot_map
开发者ID:nash-x,项目名称:hws,代码行数:40,代码来源:api.py
示例19: _vpn_dict
def _vpn_dict(self, context, project_id, instance):
elevated = context.elevated()
rv = {"project_id": project_id}
if not instance:
rv["state"] = "pending"
return rv
rv["instance_id"] = instance["uuid"]
rv["created_at"] = timeutils.isotime(instance["created_at"])
nw_info = compute_utils.get_nw_info_for_instance(instance)
if not nw_info:
return rv
vif = nw_info[0]
ips = [ip for ip in vif.fixed_ips() if ip["version"] == 4]
if ips:
rv["internal_ip"] = ips[0]["address"]
# NOTE(vish): Currently network_api.get does an owner check on
# project_id. This is probably no longer necessary
# but rather than risk changes in the db layer,
# we are working around it here by changing the
# project_id in the context. This can be removed
# if we remove the project_id check in the db.
elevated.project_id = project_id
network = self.network_api.get(elevated, vif["network"]["id"])
if network:
vpn_ip = network["vpn_public_address"]
vpn_port = network["vpn_public_port"]
rv["public_ip"] = vpn_ip
rv["public_port"] = vpn_port
if vpn_ip and vpn_port:
if utils.vpn_ping(vpn_ip, vpn_port):
rv["state"] = "running"
else:
rv["state"] = "down"
else:
rv["state"] = "invalid"
return rv
开发者ID:VinceOnGit,项目名称:nova,代码行数:36,代码来源:cloudpipe.py
示例20: _add_floating_ip
def _add_floating_ip(self, req, id, body):
"""Associate floating_ip to an instance."""
context = req.environ['nova.context']
authorize(context)
address = body['addFloatingIp']['address']
instance = common.get_instance(self.compute_api, context, id,
expected_attrs=['flavor'])
cached_nwinfo = compute_utils.get_nw_info_for_instance(instance)
if not cached_nwinfo:
LOG.warning(
_LW('Info cache is %r during associate') % instance.info_cache,
instance=instance)
msg = _('No nw_info cache associated with instance')
raise webob.exc.HTTPBadRequest(explanation=msg)
fixed_ips = cached_nwinfo.fixed_ips()
if not fixed_ips:
msg = _('No fixed IPs associated to instance')
raise webob.exc.HTTPBadRequest(explanation=msg)
fixed_address = None
if 'fixed_address' in body['addFloatingIp']:
fixed_address = body['addFloatingIp']['fixed_address']
for fixed in fixed_ips:
if fixed['address'] == fixed_address:
break
else:
msg = _('Specified fixed address not assigned to instance')
raise webob.exc.HTTPBadRequest(explanation=msg)
if not fixed_address:
try:
fixed_address = next(ip['address'] for ip in fixed_ips
if netaddr.valid_ipv4(ip['address']))
except StopIteration:
msg = _('Unable to associate floating IP %(address)s '
'to any fixed IPs for instance %(id)s. '
'Instance has no fixed IPv4 addresses to '
'associate.') % (
{'address': address, 'id': id})
raise webob.exc.HTTPBadRequest(explanation=msg)
if len(fixed_ips) > 1:
LOG.warning(_LW('multiple fixed_ips exist, using the first '
'IPv4 fixed_ip: %s'), fixed_address)
try:
self.network_api.associate_floating_ip(context, instance,
floating_address=address,
fixed_address=fixed_address)
except exception.FloatingIpAssociated:
msg = _('floating IP is already associated')
raise webob.exc.HTTPBadRequest(explanation=msg)
except exception.NoFloatingIpInterface:
msg = _('l3driver call to add floating IP failed')
raise webob.exc.HTTPBadRequest(explanation=msg)
except exception.InstanceUnknownCell as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.FloatingIpNotFoundForAddress:
msg = _('floating IP not found')
raise webob.exc.HTTPNotFound(explanation=msg)
except exception.Forbidden as e:
raise webob.exc.HTTPForbidden(explanation=e.format_message())
except Exception as e:
msg = _('Unable to associate floating IP %(address)s to '
'fixed IP %(fixed_address)s for instance %(id)s. '
'Error: %(error)s') % (
{'address': address, 'fixed_address': fixed_address,
'id': id, 'error': e})
LOG.exception(msg)
raise webob.exc.HTTPBadRequest(explanation=msg)
return webob.Response(status_int=202)
开发者ID:amatuerone,项目名称:nova,代码行数:74,代码来源:floating_ips.py
注:本文中的nova.compute.utils.get_nw_info_for_instance函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论