本文整理汇总了Python中nova.context.elevated函数的典型用法代码示例。如果您正苦于以下问题:Python elevated函数的具体用法?Python elevated怎么用?Python elevated使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了elevated函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _update_network_host
def _update_network_host(self, context, net_uuid):
"""Set the host column in the networks table: note that this won't
work with multi-host but QuantumManager doesn't support that
anyways. The floating IPs mixin required network['host'] to be
set."""
entry = db.network_get_by_uuid(context.elevated(), net_uuid)
entry['host'] = self.host
db.network_update(context.elevated(), entry['id'], entry)
开发者ID:anbangr,项目名称:trusted-nova,代码行数:8,代码来源:manager.py
示例2: disassociate_floating_ip
def disassociate_floating_ip(self, context, address,
affect_auto_assigned=False):
"""Disassociates a floating ip from its fixed ip.
Makes sure everything makes sense then calls _disassociate_floating_ip,
rpc'ing to correct host if i'm not it.
"""
floating_ip = floating_ip_obj.FloatingIP.get_by_address(context,
address)
# handle auto assigned
if not affect_auto_assigned and floating_ip.auto_assigned:
raise exception.CannotDisassociateAutoAssignedFloatingIP()
# make sure project owns this floating ip (allocated)
self._floating_ip_owned_by_project(context, floating_ip)
# make sure floating ip is associated
if not floating_ip.fixed_ip_id:
floating_address = floating_ip.address
raise exception.FloatingIpNotAssociated(address=floating_address)
fixed_ip = fixed_ip_obj.FixedIP.get_by_id(context,
floating_ip.fixed_ip_id)
# send to correct host, unless i'm the correct host
network = network_obj.Network.get_by_id(context.elevated(),
fixed_ip.network_id)
interface = floating_ip.interface
if network.multi_host:
instance = instance_obj.Instance.get_by_uuid(
context, fixed_ip.instance_uuid)
service = service_obj.Service.get_by_host_and_topic(
context.elevated(), instance.host, CONF.network_topic)
if service and self.servicegroup_api.service_is_up(service):
host = instance.host
else:
# NOTE(vish): if the service is down just deallocate the data
# locally. Set the host to local so the call will
# not go over rpc and set interface to None so the
# teardown in the driver does not happen.
host = self.host
interface = None
else:
host = network.host
if host == self.host:
# i'm the correct host
self._disassociate_floating_ip(context, address, interface,
fixed_ip.instance_uuid)
else:
# send to correct host
self.network_rpcapi._disassociate_floating_ip(context, address,
interface, host, fixed_ip.instance_uuid)
开发者ID:devoid,项目名称:nova,代码行数:54,代码来源:floating_ips.py
示例3: test_get_network_not_in_db
def test_get_network_not_in_db(self):
context = self.mox.CreateMockAnything()
context.elevated().AndReturn('elevated')
self.mox.StubOutWithMock(db, 'network_get_by_uuid')
self.net_man.context = context
db.network_get_by_uuid('elevated', 'quantum_net_id').AndReturn(None)
self.mox.ReplayAll()
network = self.net_man.get_network(context, ('quantum_net_id',
'net_tenant_id'))
self.assertEquals(network['quantum_net_id'], 'quantum_net_id')
self.assertEquals(network['uuid'], 'quantum_net_id')
开发者ID:A7Zulu,项目名称:nova,代码行数:13,代码来源:test_quantum.py
示例4: allocate_fixed_ip
def allocate_fixed_ip(self, context, instance_id, *args, **kwargs):
"""Gets a fixed ip from the pool."""
# TODO(vish): when this is called by compute, we can associate compute
# with a network, or a cluster of computes with a network
# and use that network here with a method like
# network_get_by_compute_host
network_ref = self.db.network_get_by_bridge(context.elevated(),
FLAGS.flat_network_bridge)
address = self.db.fixed_ip_associate_pool(context.elevated(),
network_ref['id'],
instance_id)
self.db.fixed_ip_update(context, address, {'allocated': True})
return address
开发者ID:superstack,项目名称:nova,代码行数:13,代码来源:manager.py
示例5: allocate_for_instance
def allocate_for_instance(self, context, **kwargs):
"""Handles allocating the various network resources for an instance.
rpc.called by network_api
"""
instance_id = kwargs.pop('instance_id')
host = kwargs.pop('host')
project_id = kwargs.pop('project_id')
type_id = kwargs.pop('instance_type_id')
vpn = kwargs.pop('vpn')
admin_context = context.elevated()
LOG.debug(_("network allocations for instance %s"), instance_id,
context=context)
networks = self._get_networks_for_instance(admin_context, instance_id,
project_id)
# Create a port via quantum and attach the vif
tenant_id = project_id
for n in networks:
vif_id = "nova-" + str(instance_id) + "-" + str(n['id'])
quantum_net_id = n['bridge']
LOG.debug("Using quantum_net_id: %s" % quantum_net_id)
port_id = quantum.create_port(tenant_id, quantum_net_id)
quantum.plug_iface(tenant_id, quantum_net_id, port_id, vif_id)
# TODO: also communicate "interface-binding" and "tenant-id"
# to Quantum
LOG.warn(networks)
self._allocate_mac_addresses(context, instance_id, networks)
ips = self._allocate_fixed_ips(admin_context, instance_id, host,
networks, vpn=vpn)
vifs = self.db.virtual_interface_get_by_instance(context, instance_id)
return self._construct_instance_nw_info(context, instance_id, type_id,
host, ips, vifs)
开发者ID:rajarammallya,项目名称:openstack-nova,代码行数:34,代码来源:quantummanager.py
示例6: _create
def _create(self, req, body):
context = req.environ['nova.context']
context = context.elevated()
print "context!!"
print context.to_dict()
vals = body['network']
name = vals['name']
size = vals['size']
project_id=str(req.environ['HTTP_X_TENANT_ID'])
print FLAGS.network_manager
cidr = self.get_new_cidr(context, size)
print cidr
print"!!!!!!!!!!!!!!!!strat creating"
self.create_network(context=context, label=name, fixed_range_v4=cidr, num_networks=1,
network_size=size, multi_host=None, vlan_start=None,
vpn_start=None, fixed_range_v6=None, gateway=None,
gateway_v6=None, bridge=None, bridge_interface=None,
dns1=None, dns2=None, project_id=project_id, priority=None,
uuid=None, fixed_cidr=None)
print cidr
db_net = db.network_get_by_cidr(context, cidr)
net = dict(db_net.iteritems())
ret_net={}
ret_net['network']={'id':net['uuid'],'name':net['label'],'cidr':net['cidr']}
return ret_net
开发者ID:HolySparky,项目名称:Openstack-NetworkAPI,代码行数:25,代码来源:networks.py
示例7: resize_claim
def resize_claim(self, context, instance_ref, instance_type, limits=None):
"""Indicate that resources are needed for a resize operation to this
compute host.
:param context: security context
:param instance_ref: instance to reserve resources for
:param instance_type: new instance_type being resized to
:param limits: Dict of oversubscription limits for memory, disk,
and CPUs.
:returns: A Claim ticket representing the reserved resources. This
should be turned into finalize a resource claim or free
resources after the compute operation is finished.
"""
if self.disabled:
# compute_driver doesn't support resource tracking, just
# generate the migration record and continue the resize:
migration_ref = self._create_migration(context, instance_ref, instance_type)
return claims.NopClaim(migration=migration_ref)
claim = claims.ResizeClaim(instance_ref, instance_type, self)
if claim.test(self.compute_node, limits):
migration_ref = self._create_migration(context, instance_ref, instance_type)
claim.migration = migration_ref
# Mark the resources in-use for the resize landing on this
# compute host:
self._update_usage_from_migration(context, instance_ref, self.compute_node, migration_ref)
elevated = context.elevated()
self._update(elevated, self.compute_node)
return claim
else:
raise exception.ComputeResourcesUnavailable()
开发者ID:mygoda,项目名称:openstack,代码行数:35,代码来源:resource_tracker.py
示例8: _list_cobalt_hosts
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
开发者ID:peterfeiner,项目名称:cobalt,代码行数:25,代码来源:api.py
示例9: create_volume
def create_volume(self, context, volume_id):
"""Creates and exports the volume."""
context = context.elevated()
volume_ref = self.db.volume_get(context, volume_id)
LOG.info(_("volume %s: creating"), volume_ref['name'])
self.db.volume_update(context,
volume_id,
{'host': self.host})
# NOTE(vish): so we don't have to get volume from db again
# before passing it to the driver.
volume_ref['host'] = self.host
try:
vol_name = volume_ref['name']
vol_size = volume_ref['size']
LOG.debug(_("volume %(vol_name)s: creating lv of"
" size %(vol_size)sG") % locals())
self.driver.create_volume(volume_ref)
LOG.debug(_("volume %s: creating export"), volume_ref['name'])
self.driver.create_export(context, volume_ref)
except Exception:
self.db.volume_update(context,
volume_ref['id'], {'status': 'error'})
raise
now = datetime.datetime.utcnow()
self.db.volume_update(context,
volume_ref['id'], {'status': 'available',
'launched_at': now})
LOG.debug(_("volume %s: created successfully"), volume_ref['name'])
return volume_id
开发者ID:anotherjesse,项目名称:nova,代码行数:33,代码来源:manager.py
示例10: associate_floating_ip
def associate_floating_ip(self, context, floating_address, fixed_address,
affect_auto_assigned=False):
"""Associates a floating ip with a fixed ip.
Makes sure everything makes sense then calls _associate_floating_ip,
rpc'ing to correct host if i'm not it.
Access to the floating_address is verified but access to the
fixed_address is not verified. This assumes that that the calling
side has already verified that the fixed_address is legal by
checking access to the instance.
"""
floating_ip = self.db.floating_ip_get_by_address(context,
floating_address)
# handle auto_assigned
if not affect_auto_assigned and floating_ip.get('auto_assigned'):
return
# make sure project owns this floating ip (allocated)
self._floating_ip_owned_by_project(context, floating_ip)
# disassociate any already associated
orig_instance_uuid = None
if floating_ip['fixed_ip_id']:
# find previously associated instance
fixed_ip = fixed_ip_obj.FixedIP.get_by_id(
context, floating_ip['fixed_ip_id'])
if str(fixed_ip.address) == fixed_address:
# NOTE(vish): already associated to this address
return
orig_instance_uuid = fixed_ip.instance_uuid
self.disassociate_floating_ip(context, floating_address)
fixed_ip = fixed_ip_obj.FixedIP.get_by_address(context,
fixed_address)
# send to correct host, unless i'm the correct host
network = self.db.network_get(context.elevated(),
fixed_ip.network_id)
if network['multi_host']:
instance = self.db.instance_get_by_uuid(context,
fixed_ip['instance_uuid'])
host = instance['host']
else:
host = network['host']
interface = floating_ip.get('interface')
if host == self.host:
# i'm the correct host
self._associate_floating_ip(context, floating_address,
fixed_address, interface,
fixed_ip.instance_uuid)
else:
# send to correct host
self.network_rpcapi._associate_floating_ip(context,
floating_address, fixed_address, interface, host,
fixed_ip.instance_uuid)
return orig_instance_uuid
开发者ID:zhangqi-net,项目名称:nova,代码行数:60,代码来源:floating_ips.py
示例11: trigger_security_group_rule_destroy_refresh
def trigger_security_group_rule_destroy_refresh(self, context, rule_ids):
LOG.debug('rule_ids=%r', rule_ids)
ctxt = context.elevated()
tenant_id = context.to_dict()['project_id']
for rule_id in rule_ids:
self.rule_manager.delete_for_sg(tenant_id, rule_id)
开发者ID:JoeMido,项目名称:midonet-openstack,代码行数:7,代码来源:sg.py
示例12: get_vnc_console
def get_vnc_console(self, context, console_type, instance):
"""Return connection information for a vnc console."""
context = context.elevated()
LOG.debug(_("Getting vnc console"), instance=instance)
token = str(utils.gen_uuid())
if console_type == 'ajaxterm':
access_url = '%s?token=%s' % (FLAGS.ajaxterm_base_url, token)
connect_info = self.driver.get_web_console(instance)
connect_info['token'] = token
connect_info['access_url'] = access_url
return connect_info
elif console_type == 'novnc':
# For essex, novncproxy_base_url must include the full path
# including the html file (like http://myhost/vnc_auto.html)
access_url = '%s?token=%s' % (FLAGS.novncproxy_base_url, token)
elif console_type == 'xvpvnc':
access_url = '%s?token=%s' % (FLAGS.xvpvncproxy_base_url, token)
else:
raise exception.ConsoleTypeInvalid(console_type=console_type)
# Retrieve connect info from driver, and then decorate with our
# access info token
connect_info = self.driver.get_vnc_console(instance)
connect_info['token'] = token
connect_info['access_url'] = access_url
return connect_info
开发者ID:leloulight,项目名称:nova-dynamips-driver,代码行数:28,代码来源:manager.py
示例13: deallocate_for_instance
def deallocate_for_instance(self, context, **kwargs):
instance_id = kwargs.get('instance_id')
project_id = kwargs.pop('project_id', None)
admin_context = context.elevated()
networks = self._get_networks_for_instance(admin_context, instance_id,
project_id)
vifs = self.db.virtual_interface_get_by_instance(context, instance_id)
for n in networks:
vif_id = "nova-" + str(instance_id) + "-" + str(n['id'])
# Un-attach the vif and delete the port
tenant_id = project_id or FLAGS.quantum_default_tenant_id
quantum_net_id = n['bridge']
LOG.debug("Using quantum_net_id: %s" % quantum_net_id)
attachment = vif_id
port_id = quantum.get_port_by_attachment(tenant_id,
quantum_net_id, attachment)
# FIXME: tell Quantum that this interface-binding is no
# longer valid.
if not port_id:
LOG.error("Unable to find port with attachment: %s" % \
(attachment))
else:
quantum.unplug_iface(tenant_id, quantum_net_id, port_id)
quantum.delete_port(tenant_id, quantum_net_id, port_id)
vif = filter(lambda vif: vif['network_id'] == n['id'], vifs)[0]
melange.deallocate_ips(n['id'], vif['id'],
project_id=n['project_id'])
self.db.virtual_interface_delete_by_instance(context, instance_id)
开发者ID:rajarammallya,项目名称:openstack-nova,代码行数:32,代码来源:quantummanager.py
示例14: allocate_fixed_ip
def allocate_fixed_ip(self, context, instance_id, network, **kwargs):
"""Gets a fixed ip from the pool."""
# TODO(vish): when this is called by compute, we can associate compute
# with a network, or a cluster of computes with a network
# and use that network here with a method like
# network_get_by_compute_host
address = None
if network['cidr']:
address = kwargs.get('address', None)
if address:
address = self.db.fixed_ip_associate(context,
address, instance_id,
network['id'])
else:
address = self.db.fixed_ip_associate_pool(context.elevated(),
network['id'],
instance_id)
self._do_trigger_security_group_members_refresh_for_instance(
instance_id)
get_vif = self.db.virtual_interface_get_by_instance_and_network
vif = get_vif(context, instance_id, network['id'])
values = {'allocated': True,
'virtual_interface_id': vif['id']}
self.db.fixed_ip_update(context, address, values)
self._setup_network(context, network)
return address
开发者ID:shidax,项目名称:openstack-baremetal-compute,代码行数:27,代码来源:manager.py
示例15: deallocate_for_instance
def deallocate_for_instance(self, context, **kwargs):
"""Called when a VM is terminated. Loop through each virtual
interface in the Nova DB and remove the Quantum port and
clear the IP allocation using the IPAM. Finally, remove
the virtual interfaces from the Nova DB.
"""
instance_id = kwargs.get('instance_id')
project_id = kwargs.pop('project_id', None)
admin_context = context.elevated()
vifs = db.virtual_interface_get_by_instance(admin_context,
instance_id)
for vif in vifs:
network = db.network_get(admin_context, vif['network_id'])
self.deallocate_port(vif['uuid'], network['uuid'], project_id,
instance_id)
ipam_tenant_id = self.deallocate_ip_address(context,
network['uuid'], project_id, vif, instance_id)
if FLAGS.quantum_use_dhcp:
self.update_dhcp(context, ipam_tenant_id, network,
vif, project_id)
db.virtual_interface_delete(admin_context, vif['id'])
开发者ID:anbangr,项目名称:trusted-nova,代码行数:27,代码来源:manager.py
示例16: _teardown_network_on_host
def _teardown_network_on_host(self, context, network):
if not CONF.fake_network:
network['dhcp_server'] = self._get_dhcp_ip(context, network)
dev = self.driver.get_dev(network)
# NOTE(): For multi hosted networks, if the network is no
# more used on this host and if VPN forwarding rule aren't handed
# by the host, we delete the network gateway.
vpn_address = network['vpn_public_address']
if (CONF.teardown_unused_network_gateway and
not objects.Network.in_use_on_host(context, network['id'],
self.host)):
LOG.debug("Remove unused gateway %s", network['bridge'])
if network.enable_dhcp:
self.driver.kill_dhcp(dev)
self.l3driver.remove_gateway(network)
if not self._uses_shared_ip(network):
fip = objects.FixedIP.get_by_address(context,
network.dhcp_server)
fip.allocated = False
fip.host = None
fip.save()
# NOTE(): if dhcp server is not set then don't dhcp
elif network.enable_dhcp:
# NOTE(): dhcp DB queries require elevated context
elevated = context.elevated()
self.driver.update_dhcp(elevated, dev, network)
开发者ID:nkapotoxin,项目名称:fs_spc111t_plus_hc,代码行数:27,代码来源:manager.py
示例17: _create_migration
def _create_migration(self, context, instance, instance_type):
"""Create a migration record for the upcoming resize. This should
be done while the COMPUTE_RESOURCES_SEMAPHORE is held so the resource
claim will not be lost if the audit process starts.
"""
# TODO(russellb): no-db-compute: Send the old instance type
# info that is needed via rpc so db access isn't required
# here.
old_instance_type_id = instance["instance_type_id"]
old_instance_type = instance_types.get_instance_type(old_instance_type_id)
return db.migration_create(
context.elevated(),
{
"instance_uuid": instance["uuid"],
"source_compute": instance["host"],
"source_node": instance["node"],
"dest_compute": self.host,
"dest_node": self.nodename,
"dest_host": self.driver.get_host_ip_addr(),
"old_instance_type_id": old_instance_type["id"],
"new_instance_type_id": instance_type["id"],
"status": "pre-migrating",
},
)
开发者ID:ameade,项目名称:nova,代码行数:25,代码来源:resource_tracker.py
示例18: create_snapshot
def create_snapshot(self, context, volume_id, snapshot_id):
"""Creates and exports the snapshot."""
context = context.elevated()
snapshot_ref = self.db.snapshot_get(context, snapshot_id)
LOG.info(_("snapshot %s: creating"), snapshot_ref['name'])
try:
snap_name = snapshot_ref['name']
LOG.debug(_("snapshot %(snap_name)s: creating") % locals())
model_update = self.driver.create_snapshot(snapshot_ref)
if model_update:
self.db.snapshot_update(context, snapshot_ref['id'],
model_update)
except Exception:
with utils.save_and_reraise_exception():
self.db.snapshot_update(context,
snapshot_ref['id'],
{'status': 'error'})
self.db.snapshot_update(context,
snapshot_ref['id'], {'status': 'available',
'progress': '100%'})
LOG.debug(_("snapshot %s: created successfully"), snapshot_ref['name'])
return snapshot_id
开发者ID:xinnet-iaas-openstack,项目名称:io,代码行数:25,代码来源:manager.py
示例19: trigger_instance_remove_security_group_refresh
def trigger_instance_remove_security_group_refresh(self, context,
instance_ref):
"""Refresh and remove security groups given an instance reference."""
admin_context = context.elevated()
for group in instance_ref['security_groups']:
self.conductor_api.security_groups_trigger_handler(context,
'instance_remove_security_group', instance_ref, group['name'])
开发者ID:ashkasugai,项目名称:nova,代码行数:7,代码来源:api.py
示例20: _setup_network_on_host
def _setup_network_on_host(self, context, network):
"""Sets up network on this host."""
if context.is_admin:
if not objects.Network.in_use_on_host(context, network['id'],
None):
return
if not network.vpn_public_address:
address = CONF.vpn_ip
network.vpn_public_address = address
network.save()
else:
address = network.vpn_public_address
network.dhcp_server = self._get_dhcp_ip(context, network)
self._initialize_network(network)
# NOTE(): only ensure this forward if the address hasn't been set
# manually.
if address == CONF.vpn_ip and hasattr(self.driver,
"ensure_vpn_forward"):
self.l3driver.add_vpn(CONF.vpn_ip,
network.vpn_public_port,
network.vpn_private_address)
if not CONF.fake_network:
dev = self.driver.get_dev(network)
# NOTE(): dhcp DB queries require elevated context
if network.enable_dhcp:
elevated = context.elevated()
self.driver.update_dhcp(elevated, dev, network)
if CONF.use_ipv6:
self.driver.update_ra(context, dev, network)
gateway = utils.get_my_linklocal(dev)
network.gateway_v6 = gateway
network.save()
开发者ID:nkapotoxin,项目名称:fs_spc111t_plus_hc,代码行数:35,代码来源:manager.py
注:本文中的nova.context.elevated函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论