本文整理汇总了Python中tricircle.common.context.get_context_from_neutron_context函数的典型用法代码示例。如果您正苦于以下问题:Python get_context_from_neutron_context函数的具体用法?Python get_context_from_neutron_context怎么用?Python get_context_from_neutron_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_context_from_neutron_context函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_networks
def get_networks(self, context, filters=None, fields=None,
sorts=None, limit=None, marker=None, page_reverse=False):
# if id is not specified in the filter, we just return network data in
# local Neutron server, otherwise id is specified, we need to retrieve
# network data from central Neutron server and create network which
# doesn't exist in local Neutron server.
if not filters or 'id' not in filters:
return self.core_plugin.get_networks(
context, filters, fields, sorts, limit, marker, page_reverse)
b_full_networks = self.core_plugin.get_networks(
context, filters, None, sorts, limit, marker, page_reverse)
b_networks = []
for b_network in b_full_networks:
subnet_ids = self._ensure_subnet(context, b_network, False)
if subnet_ids:
b_network['subnets'] = subnet_ids
b_networks.append(db_utils.resource_fields(b_network, fields))
if len(b_networks) == len(filters['id']):
return b_networks
t_ctx = t_context.get_context_from_neutron_context(context)
if self._skip_non_api_query(t_ctx):
return b_networks
t_ctx.auth_token = client.Client.get_admin_token(context.project_id)
raw_client = self.neutron_handle._get_client(t_ctx)
params = self._construct_params(filters, sorts, limit, marker,
page_reverse)
t_networks = raw_client.list_networks(**params)['networks']
t_id_set = set([network['id'] for network in t_networks])
b_id_set = set([network['id'] for network in b_networks])
missing_id_set = t_id_set - b_id_set
if missing_id_set:
missing_networks = [network for network in t_networks if (
network['id'] in missing_id_set)]
for network in missing_networks:
region_name = self._get_neutron_region()
located = self._is_network_located_in_region(network,
region_name)
if not located:
LOG.error('network: %(net_id)s not located in current '
'region: %(region_name)s, '
'az_hints: %(az_hints)s',
{'net_id': network['id'],
'region_name': region_name,
'az_hints': network[az_def.AZ_HINTS]})
continue
self._adapt_network_body(network)
network.pop('qos_policy_id', None)
b_network = self.core_plugin.create_network(
context, {'network': network})
subnet_ids = self._ensure_subnet(context, network)
if subnet_ids:
b_network['subnets'] = subnet_ids
b_networks.append(db_utils.resource_fields(b_network, fields))
return b_networks
开发者ID:openstack,项目名称:tricircle,代码行数:60,代码来源:local_plugin.py
示例2: delete_flow_classifier_precommit
def delete_flow_classifier_precommit(self, context):
t_ctx = t_context.get_context_from_neutron_context(
context._plugin_context)
flowclassifier_id = context.current['id']
db_api.create_recycle_resource(
t_ctx, flowclassifier_id, t_constants.RT_FLOW_CLASSIFIER,
t_ctx.project_id)
开发者ID:openstack,项目名称:tricircle,代码行数:7,代码来源:central_fc_driver.py
示例3: delete_security_group_rule
def delete_security_group_rule(self, q_context, _id):
rule = self.get_security_group_rule(q_context, _id)
if rule['remote_group_id']:
raise n_exceptions.RemoteGroupNotSupported()
sg_id = rule['security_group_id']
sg = self.get_security_group(q_context, sg_id)
if sg['name'] == 'default':
raise n_exceptions.DefaultGroupUpdateNotSupported()
t_context = context.get_context_from_neutron_context(q_context)
mappings = db_api.get_bottom_mappings_by_top_id(
t_context, sg_id, constants.RT_SG)
try:
for pod, b_sg_id in mappings:
client = self._get_client(pod['pod_name'])
rule['security_group_id'] = b_sg_id
b_sg = client.get_security_groups(t_context, b_sg_id)
for b_rule in b_sg['security_group_rules']:
if not self._compare_rule(b_rule, rule):
continue
self._safe_delete_security_group_rule(t_context, client,
b_rule['id'])
break
except Exception:
raise n_exceptions.BottomPodOperationFailure(
resource='security group rule', pod_name=pod['pod_name'])
super(TricircleSecurityGroupMixin,
self).delete_security_group_rule(q_context, _id)
开发者ID:Ronghui,项目名称:tricircle,代码行数:30,代码来源:security_groups.py
示例4: update_port
def update_port(self, context, _id, port):
# ovs agent will not call update_port, it updates port status via rpc
# and direct db operation
profile_dict = port['port'].get(portbindings.PROFILE, {})
if profile_dict.pop(t_constants.PROFILE_FORCE_UP, None):
port['port']['status'] = q_constants.PORT_STATUS_ACTIVE
port['port'][
portbindings.VNIC_TYPE] = q_constants.ATTR_NOT_SPECIFIED
b_port = self.core_plugin.update_port(context, _id, port)
if self._need_top_update(b_port, port['port']):
region_name = self._get_neutron_region()
update_dict = {portbindings.PROFILE: {
t_constants.PROFILE_REGION: region_name,
t_constants.PROFILE_DEVICE: b_port['device_owner']}}
self._fill_agent_info_in_profile(
context, _id, port['port'][portbindings.HOST_ID],
update_dict[portbindings.PROFILE])
if directory.get_plugin('trunk'):
trunk_details = b_port.get('trunk_details')
if trunk_details:
update_dict['binding:profile'].update({
t_constants.PROFILE_LOCAL_TRUNK_ID:
trunk_details['trunk_id']})
t_ctx = t_context.get_context_from_neutron_context(context)
self.neutron_handle.handle_update(t_ctx, 'port', _id,
{'port': update_dict})
return b_port
开发者ID:LongXQ,项目名称:tricircle,代码行数:29,代码来源:local_plugin.py
示例5: delete_port_pair_precommit
def delete_port_pair_precommit(self, context):
t_ctx = t_context.get_context_from_neutron_context(
context._plugin_context)
portpair_id = context.current['id']
db_api.create_recycle_resource(
t_ctx, portpair_id, t_constants.RT_PORT_PAIR,
t_ctx.project_id)
开发者ID:openstack,项目名称:tricircle,代码行数:7,代码来源:central_sfc_driver.py
示例6: update_subnet
def update_subnet(self, context, _id, subnet):
"""update bottom subnet
Can not directly use ML2 plugin's update_subnet function,
because it will call local plugin's get_subnet in a transaction,
the local plugin's get_subnet will create a dhcp port when subnet's
enable_dhcp attribute is changed from False to True, but neutron
doesn't allow calling create_port in a transaction and will raise an
exception.
:param context: neutron context
:param _id: subnet_id
:param subnet: update body
:return: updated subnet
"""
t_ctx = t_context.get_context_from_neutron_context(context)
b_subnet = self.core_plugin.get_subnet(context, _id)
origin_enable_dhcp = b_subnet['enable_dhcp']
req_enable_dhcp = subnet['subnet'].get('enable_dhcp')
# when request enable dhcp, and origin dhcp is disabled,
# ensure subnet dhcp port is created
if req_enable_dhcp and not origin_enable_dhcp:
self._ensure_subnet_dhcp_port(t_ctx, context, b_subnet)
res = self.core_plugin.update_subnet(context, _id, subnet)
return res
开发者ID:openstack,项目名称:tricircle,代码行数:25,代码来源:local_plugin.py
示例7: create_security_group_rule
def create_security_group_rule(self, q_context, security_group_rule):
rule = security_group_rule['security_group_rule']
if rule['remote_group_id']:
raise n_exceptions.RemoteGroupNotSupported()
sg_id = rule['security_group_id']
sg = self.get_security_group(q_context, sg_id)
if sg['name'] == 'default':
raise n_exceptions.DefaultGroupUpdateNotSupported()
new_rule = super(TricircleSecurityGroupMixin,
self).create_security_group_rule(q_context,
security_group_rule)
t_context = context.get_context_from_neutron_context(q_context)
mappings = db_api.get_bottom_mappings_by_top_id(
t_context, sg_id, constants.RT_SG)
try:
for pod, b_sg_id in mappings:
client = self._get_client(pod['pod_name'])
rule['security_group_id'] = b_sg_id
self._safe_create_security_group_rule(
t_context, client, {'security_group_rule': rule})
except Exception:
super(TricircleSecurityGroupMixin,
self).delete_security_group_rule(q_context, new_rule['id'])
raise n_exceptions.BottomPodOperationFailure(
resource='security group rule', pod_name=pod['pod_name'])
return new_rule
开发者ID:Ronghui,项目名称:tricircle,代码行数:29,代码来源:security_groups.py
示例8: update_port_pair_group_precommit
def update_port_pair_group_precommit(self, context):
plugin_context = context._plugin_context
t_ctx = t_context.get_context_from_neutron_context(
context._plugin_context)
port_pair_group = context.current
mappings = db_api.get_bottom_mappings_by_top_id(
t_ctx, port_pair_group['id'], t_constants.RT_PORT_PAIR_GROUP)
if mappings:
portchain_id = self._get_chain_id_by_group_id(
plugin_context, context._plugin, port_pair_group['id'])
if port_pair_group['port_pairs']:
net_id = self._get_net_id_by_portpairgroups(
plugin_context, context._plugin, [port_pair_group['id']])
elif context.original['port_pairs']:
portpair_id = context.original['port_pairs'][0]
port_pair = context._plugin._get_port_pair(
plugin_context, portpair_id)
net_id = self._get_net_id_by_port_id(
plugin_context, port_pair['ingress'])
else:
net_id = ''
if not portchain_id and not net_id:
return
self.xjob_handler.sync_service_function_chain(
t_ctx, port_pair_group['project_id'], portchain_id, net_id,
t_constants.POD_NOT_SPECIFIED)
开发者ID:openstack,项目名称:tricircle,代码行数:26,代码来源:central_sfc_driver.py
示例9: prepare_bottom_external_subnet_by_bottom_name
def prepare_bottom_external_subnet_by_bottom_name(
self, context, subnet, region_name, b_net_name, top_subnet_id):
t_ctx = t_context.get_context_from_neutron_context(context)
pod = db_api.get_pod_by_name(t_ctx, region_name)
b_client = self._get_client(region_name)
bottom_network = b_client.list_networks(
t_ctx, [{'key': 'name',
'comparator': 'eq',
'value': b_net_name}]
)
if not bottom_network:
raise t_exceptions.InvalidInput(
reason='bottom network not found for %(b_net_name)s'
% {'b_net_name': b_net_name})
body = {
'subnet': {
'name': top_subnet_id,
'network_id': bottom_network[0]['id'],
'tenant_id': subnet['tenant_id']
}
}
attrs = ('ip_version', 'cidr', 'gateway_ip', 'allocation_pools',
'enable_dhcp')
for attr in attrs:
if validators.is_attr_set(subnet.get(attr)):
body['subnet'][attr] = subnet[attr]
self.prepare_bottom_element(
t_ctx, subnet['tenant_id'], pod, {'id': top_subnet_id},
t_constants.RT_SUBNET, body)
开发者ID:openstack,项目名称:tricircle,代码行数:29,代码来源:helper.py
示例10: create_port
def create_port(self, context, port):
port_body = port['port']
network_id = port_body['network_id']
# get_network will create bottom network if it doesn't exist
self.get_network(context, network_id)
t_ctx = t_context.get_context_from_neutron_context(context)
raw_client = self.neutron_handle._get_client(t_ctx)
def get_top_port_by_ip(ip):
params = {'fixed_ips': 'ip_address=%s' % ip,
'network_id': network_id}
t_ports = raw_client.list_ports(**params)['ports']
if not t_ports:
raise q_exceptions.InvalidIpForNetwork(
ip_address=fixed_ip['ip_address'])
return t_ports[0]
if port_body['fixed_ips'] is not q_constants.ATTR_NOT_SPECIFIED and (
port_body.get('device_owner') != (
q_constants.DEVICE_OWNER_LOADBALANCERV2)):
if not self._is_special_port(port_body):
fixed_ip = port_body['fixed_ips'][0]
ip_address = fixed_ip.get('ip_address')
if not ip_address:
# dhcp agent may request to create a dhcp port without
# specifying ip address, we just raise an exception to
# reject this request
raise q_exceptions.InvalidIpForNetwork(ip_address='None')
t_port = get_top_port_by_ip(ip_address)
elif helper.NetworkHelper.is_need_top_sync_port(
port_body, cfg.CONF.client.bridge_cidr):
# for port that needs to be synced with top port, we keep ids
# the same
ip_address = port_body['fixed_ips'][0]['ip_address']
port_body['id'] = get_top_port_by_ip(ip_address)['id']
t_port = port_body
else:
self._handle_dvr_snat_port(t_ctx, port_body)
t_port = port_body
else:
self._adapt_port_body_for_client(port['port'])
t_port = raw_client.create_port(port)['port']
if not self._is_special_port(port_body):
subnet_id = t_port['fixed_ips'][0]['subnet_id']
# get_subnet will create bottom subnet if it doesn't exist
self.get_subnet(context, subnet_id)
for field in ('name', 'device_id', 'device_owner', 'binding:host_id'):
if port_body.get(field):
t_port[field] = port_body[field]
self._handle_security_group(t_ctx, context, t_port)
self._create_shadow_agent(context, port_body)
t_port.pop('qos_policy_id', None)
b_port = self.core_plugin.create_port(context, {'port': t_port})
return b_port
开发者ID:openstack,项目名称:tricircle,代码行数:59,代码来源:local_plugin.py
示例11: get_trunks
def get_trunks(self, context, filters=None, fields=None,
sorts=None, limit=None, marker=None, page_reverse=False):
ret = []
bottom_top_map = {}
top_bottom_map = {}
t_ctx = t_context.get_context_from_neutron_context(context)
route_filters = [{'key': 'resource_type',
'comparator': 'eq',
'value': t_constants.RT_TRUNK}]
routes = db_api.list_resource_routings(t_ctx, route_filters)
for route in routes:
bottom_top_map[route['bottom_id']] = route['top_id']
top_bottom_map[route['top_id']] = route['bottom_id']
if limit:
if marker:
mappings = db_api.get_bottom_mappings_by_top_id(
t_ctx, marker, t_constants.RT_TRUNK)
# if mapping exists, we retrieve trunk information
# from bottom, otherwise from top
if mappings:
pod_id = mappings[0][0]['pod_id']
current_pod = db_api.get_pod(t_ctx, pod_id)
ret = self._get_trunks_from_pod_with_limit(
context, current_pod, bottom_top_map, top_bottom_map,
filters, limit, marker)
else:
ret = self._get_trunks_from_top_with_limit(
context, top_bottom_map, filters, limit, marker)
else:
current_pod = db_api.get_next_bottom_pod(t_ctx)
# if current_pod exists, we retrieve trunk information
# from bottom, otherwise from top
if current_pod:
ret = self._get_trunks_from_pod_with_limit(
context, current_pod, bottom_top_map, top_bottom_map,
filters, limit, None)
else:
ret = self._get_trunks_from_top_with_limit(
context, top_bottom_map, filters, limit, None)
else:
pods = db_api.list_pods(t_ctx)
_filters = self._transform_trunk_filters(filters, top_bottom_map)
for pod in pods:
if not pod['az_name']:
continue
client = self._get_client(pod['region_name'])
pod_trunks = client.list_trunks(t_ctx, filters=_filters)
ret.extend(pod_trunks)
ret = self._map_trunks_from_bottom_to_top(ret, bottom_top_map)
top_trunks = self._get_trunks_from_top(context,
top_bottom_map, filters)
ret.extend(top_trunks)
return [super(TricircleTrunkPlugin, self)._fields(trunk, fields)
for trunk in ret]
开发者ID:southeast02,项目名称:tricircle,代码行数:57,代码来源:central_trunk_plugin.py
示例12: remove_bottom_router_by_name
def remove_bottom_router_by_name(self, n_context, region_name,
router_name):
t_ctx = t_context.get_context_from_neutron_context(n_context)
b_client = self._get_client(region_name)
bottom_router = b_client.list_routers(
t_ctx, [{'key': 'name',
'comparator': 'eq',
'value': router_name}])
if bottom_router:
b_client.delete_routers(t_ctx, bottom_router[0]['id'])
开发者ID:openstack,项目名称:tricircle,代码行数:10,代码来源:helper.py
示例13: create_port_chain_precommit
def create_port_chain_precommit(self, context):
plugin_context = context._plugin_context
t_ctx = t_context.get_context_from_neutron_context(plugin_context)
port_chain = context.current
net_id = self._get_net_id_by_portpairgroups(
plugin_context, context._plugin, port_chain['port_pair_groups'])
if net_id:
self.xjob_handler.sync_service_function_chain(
t_ctx, port_chain['project_id'], port_chain['id'], net_id,
t_constants.POD_NOT_SPECIFIED)
开发者ID:openstack,项目名称:tricircle,代码行数:10,代码来源:central_sfc_driver.py
示例14: remove_bottom_external_network_by_name
def remove_bottom_external_network_by_name(
self, n_context, region_name, name):
t_ctx = t_context.get_context_from_neutron_context(n_context)
b_client = self._get_client(region_name)
b_net = b_client.list_networks(
t_ctx, [{'key': 'name',
'comparator': 'eq',
'value': name}])
if b_net:
b_client.delete_networks(t_ctx, b_net[0]['id'])
开发者ID:openstack,项目名称:tricircle,代码行数:10,代码来源:helper.py
示例15: _create_bottom_network
def _create_bottom_network(self, context, _id):
t_ctx = t_context.get_context_from_neutron_context(context)
t_network = self.neutron_handle.handle_get(t_ctx, 'network', _id)
if not t_network:
raise q_exceptions.NetworkNotFound(net_id=_id)
self._adapt_network_body(t_network)
t_network.pop('qos_policy_id', None)
b_network = self.core_plugin.create_network(context,
{'network': t_network})
return t_network, b_network
开发者ID:openstack,项目名称:tricircle,代码行数:10,代码来源:local_plugin.py
示例16: delete_trunk
def delete_trunk(self, context, trunk_id):
t_ctx = t_context.get_context_from_neutron_context(context)
res = super(TricircleTrunkPlugin, self).get_trunk(context, trunk_id)
with context.session.begin():
super(TricircleTrunkPlugin, self).delete_trunk(context, trunk_id)
mappings = db_api.get_bottom_mappings_by_top_id(
t_ctx, trunk_id, t_constants.RT_TRUNK)
if mappings:
b_pod = mappings[0][0]
self.xjob_handler.sync_trunk(t_ctx, res['project_id'],
trunk_id, b_pod['pod_id'])
开发者ID:southeast02,项目名称:tricircle,代码行数:11,代码来源:central_trunk_plugin.py
示例17: update_trunk
def update_trunk(self, context, trunk_id, trunk):
# update trunk
t_ctx = t_context.get_context_from_neutron_context(context)
with context.session.begin():
res = super(TricircleTrunkDriver, self).update_trunk(
context, trunk_id, trunk)
mappings = db_api.get_bottom_mappings_by_top_id(
t_ctx, trunk_id, t_constants.RT_TRUNK)
if mappings:
b_pod = mappings[0][0]
self.xjob_handler.sync_trunk(t_ctx, res['project_id'],
trunk_id, b_pod['pod_id'])
return res
开发者ID:openstack,项目名称:tricircle,代码行数:13,代码来源:central_trunk_driver.py
示例18: remove_subports
def remove_subports(self, context, trunk_id, subports):
t_ctx = t_context.get_context_from_neutron_context(context)
with context.session.begin():
self.update_subports_device_id(context, subports, '', '')
res = super(TricircleTrunkDriver, self).remove_subports(
context, trunk_id, subports)
mappings = db_api.get_bottom_mappings_by_top_id(
t_ctx, trunk_id, t_constants.RT_TRUNK)
if mappings:
b_pod = mappings[0][0]
self.xjob_handler.sync_trunk(
t_ctx, res['project_id'], trunk_id, b_pod['pod_id'])
return res
开发者ID:openstack,项目名称:tricircle,代码行数:14,代码来源:central_trunk_driver.py
示例19: get_security_group
def get_security_group(self, context, _id, fields=None, tenant_id=None):
try:
return self.core_plugin.get_security_group(
context, _id, fields, tenant_id)
except q_exceptions.NotFound:
t_ctx = t_context.get_context_from_neutron_context(context)
t_sg = self.neutron_handle.handle_get(t_ctx,
'security_group', _id)
if not t_sg:
raise ext_sg.SecurityGroupNotFound(id=_id)
self.core_plugin.create_security_group(context,
{'security_group': t_sg})
return self.core_plugin.get_security_group(
context, _id, fields, tenant_id)
开发者ID:openstack,项目名称:tricircle,代码行数:14,代码来源:local_plugin.py
示例20: update_port_chain_precommit
def update_port_chain_precommit(self, context):
plugin_context = context._plugin_context
t_ctx = t_context.get_context_from_neutron_context(plugin_context)
port_chain = context.current
mappings = db_api.get_bottom_mappings_by_top_id(
t_ctx, port_chain['id'], t_constants.RT_PORT_CHAIN)
if mappings:
net_id = self._get_net_id_by_portpairgroups(
plugin_context, context._plugin,
port_chain['port_pair_groups'])
if not net_id:
return
self.xjob_handler.sync_service_function_chain(
t_ctx, port_chain['project_id'], port_chain['id'],
net_id, t_constants.POD_NOT_SPECIFIED)
开发者ID:openstack,项目名称:tricircle,代码行数:15,代码来源:central_sfc_driver.py
注:本文中的tricircle.common.context.get_context_from_neutron_context函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论