本文整理汇总了Python中neutron_lib.context.get_admin_context方法的典型用法代码示例。如果您正苦于以下问题:Python context.get_admin_context方法的具体用法?Python context.get_admin_context怎么用?Python context.get_admin_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neutron_lib.context
的用法示例。
在下文中一共展示了context.get_admin_context方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def setUp(self):
super(SfcAgentExtensionTestCase, self).setUp()
conn_patcher = mock.patch('neutron.agent.ovsdb.impl_idl._connection')
conn_patcher.start()
self.addCleanup(conn_patcher.stop)
self.sfc_ext = sfc.SfcAgentExtension()
self.context = context.get_admin_context()
self.connection = mock.Mock()
os_ken_app = mock.Mock()
self.agent_api = ovs_ext_api.OVSAgentExtensionAPI(
ovs_bridge.OVSAgentBridge('br-int', os_ken_app=os_ken_app),
ovs_bridge.OVSAgentBridge('br-tun', os_ken_app=os_ken_app))
self.sfc_ext.consume_api(self.agent_api)
# Don't rely on used driver
mock.patch(
'neutron.manager.NeutronManager.load_class_for_provider',
return_value=lambda: mock.Mock(spec=sfc.SfcAgentDriver)
).start()
self.sfc_ext.initialize(
self.connection, constants.EXTENSION_DRIVER_TYPE)
示例2: setUp
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def setUp(self):
super(TestIPsecDriver, self).setUp()
mock.patch('neutron_lib.rpc.Connection').start()
l3_agent = mock.Mock()
l3_agent.host = FAKE_HOST
plugin = mock.Mock()
plugin.get_l3_agents_hosting_routers.return_value = [l3_agent]
directory.add_plugin(constants.CORE, plugin)
directory.add_plugin(constants.L3, plugin)
self.svc_plugin = mock.Mock()
self.svc_plugin.get_l3_agents_hosting_routers.return_value = [l3_agent]
self._fake_vpn_router_id = _uuid()
self.svc_plugin._get_vpnservice.return_value = {
'router_id': self._fake_vpn_router_id
}
self.driver = ipsec_driver.IPsecVPNDriver(self.svc_plugin)
self.validator = ipsec_validator.IpsecVpnValidator(self.driver)
self.context = n_ctx.get_admin_context()
示例3: setUp
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def setUp(self):
super(TestVPNDriverPluginMultipleDrivers, self).setUp()
vpnaas_providers = [
{'service_type': p_constants.VPN,
'name': 'ipsec',
'driver': IPSEC_SERVICE_DRIVER,
'default': True},
{'service_type': p_constants.VPN,
'name': 'dummy',
'driver': DUMMY_IPSEC_SERVICE_DRIVER,
'default': False}]
self.service_providers = (
mock.patch.object(st_db.ServiceTypeManager,
'get_service_providers').start())
self.service_providers.return_value = vpnaas_providers
self.adminContext = context.get_admin_context()
示例4: _handle_router_interface_after_create
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def _handle_router_interface_after_create(self, **kwargs):
gw_network = kwargs['network_id']
if not gw_network:
return
ctx = context.get_admin_context()
with ctx.session.begin(subtransactions=True):
speakers = self._bgp_speakers_for_gateway_network(ctx,
gw_network)
next_hops = self._next_hops_from_gateway_ips(
kwargs['gateway_ips'])
for speaker in speakers:
prefixes = self._tenant_prefixes_by_router(
ctx,
kwargs['router_id'],
speaker.id)
next_hop = next_hops.get(speaker.ip_version)
if next_hop:
rl = self._route_list_from_prefixes_and_next_hop(prefixes,
next_hop)
self.start_route_advertisements(ctx,
self._bgp_rpc,
speaker.id,
rl)
示例5: router_gateway_callback
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def router_gateway_callback(self, resource, event, trigger, payload=None):
if event == events.AFTER_CREATE:
self._handle_router_gateway_after_create(payload)
if event == events.AFTER_DELETE:
gw_network = payload.metadata.get('network_id')
router_id = payload.resource_id
next_hops = self._next_hops_from_gateway_ips(
payload.metadata.get('gateway_ips'))
ctx = context.get_admin_context()
speakers = self._bgp_speakers_for_gateway_network(ctx, gw_network)
for speaker in speakers:
if speaker.ip_version in next_hops:
next_hop = next_hops[speaker.ip_version]
prefixes = self._tenant_prefixes_by_router(ctx,
router_id,
speaker.id)
routes = self._route_list_from_prefixes_and_next_hop(
prefixes,
next_hop)
self._handle_router_interface_after_delete(gw_network, routes)
示例6: _handle_router_gateway_after_create
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def _handle_router_gateway_after_create(self, payload):
ctx = context.get_admin_context()
gw_network = payload.metadata.get('network_id')
router_id = payload.resource_id
with ctx.session.begin(subtransactions=True):
speakers = self._bgp_speakers_for_gateway_network(ctx,
gw_network)
next_hops = self._next_hops_from_gateway_ips(
payload.metadata.get('gateway_ips'))
for speaker in speakers:
if speaker.ip_version in next_hops:
next_hop = next_hops[speaker.ip_version]
prefixes = self._tenant_prefixes_by_router(ctx,
router_id,
speaker.id)
routes = self._route_list_from_prefixes_and_next_hop(
prefixes,
next_hop)
self.start_route_advertisements(ctx, self._bgp_rpc,
speaker.id, routes)
示例7: monitor_agent_state
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def monitor_agent_state(self):
"""Represents L2gateway agent scheduler thread.
Maintains list of active and inactive agents based on
the heartbeat recorded.
"""
context = neutron_context.get_admin_context()
try:
all_agents = self.plugin.get_agents(
context,
filters={'agent_type': [srv_const.AGENT_TYPE_L2GATEWAY]})
except Exception:
LOG.exception("Unable to get the agent list. Continuing...")
return
# Reset the agents that will be processed for selecting the
# Monitor agent
agents_to_process = []
for agent in all_agents:
if not utils.is_agent_down(agent['heartbeat_timestamp']):
agents_to_process.append(agent)
if agents_to_process:
self._select_agent_type(context, agents_to_process)
return
示例8: test_create_l2gateway_connection_with_invalid_device
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def test_create_l2gateway_connection_with_invalid_device(self,
phy_switch):
self.db_context = ctx.get_admin_context()
fake_l2gw_conn_dict = {'l2_gateway_connection': {
'id': 'fake_id', 'network_id': 'fake_network_id',
'l2_gateway_id': 'fake_l2gw_id'}}
fake_device = {'devices': [{'device_name': 'fake_device',
'interfaces': [{'name': 'fake_interface'}]}]}
fake_physical_switch = None
phy_switch.return_value = fake_physical_switch
with mock.patch.object(self.service_plugin,
'_admin_check',
return_value=True), \
mock.patch.object(self.service_plugin,
'get_l2_gateway',
return_value=fake_device), \
mock.patch.object(self.service_plugin,
'_get_network',
return_value=True), \
mock.patch.object(self.service_plugin,
'_get_l2_gateway',
return_value=True):
self.assertRaises(l2gw_exc.L2GatewayDeviceNotFound,
self.plugin.create_l2_gateway_connection,
self.db_context, fake_l2gw_conn_dict)
示例9: setUp
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def setUp(self):
super(TestAgentScheduler, self).setUp()
cfg.CONF.set_override('core_plugin',
"neutron.plugins.ml2.plugin.Ml2Plugin")
self.plugin = FakePlugin()
self.agent_rpc = agent_api.L2gatewayAgentApi(
l2gw_topics.L2GATEWAY_AGENT, cfg.CONF.host)
self.context = neutron_context.get_admin_context()
cfg.CONF.set_override('agent_down_time', 10)
cfg.CONF.set_override('periodic_monitoring_interval', 5)
self.agentsch = agent_scheduler.L2GatewayAgentScheduler(self.agent_rpc,
cfg.CONF)
self.agentsch._plugin = self.plugin
self.agentsch.context = self.context
self.agentsch.agent_ext_support = True
self.LOG = agent_scheduler.LOG
示例10: execute_ops
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def execute_ops(self, forced=False):
LOG.info("Starting %s periodic task.", self.task)
context = neutron_context.get_admin_context()
# Lock make sure that periodic task is executed only after
# specified interval. It makes sure that maintenance tasks
# are not executed back to back.
if not forced and self.task_already_executed_recently(context):
LOG.info("Periodic %s task executed after periodic interval "
"Skipping execution.", self.task)
return
if not self._lock_task(context):
LOG.info("Periodic %s task already running task", self.task)
return
try:
for phase in self.phases:
self._execute_op(phase, context)
finally:
self._clear_and_unlock_task(context)
LOG.info("%s task has been finished", self.task)
示例11: _process_websocket_recv
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def _process_websocket_recv(self, payload, reconnect):
# Callback for websocket notification
LOG.debug("Websocket notification for port status update")
for event in odl_ws_client.EventDataParser.get_item(payload):
operation, path, data = event.get_fields()
if ((operation in [event.OPERATION_UPDATE,
event.OPERATION_CREATE])):
port_id = event.extract_field(path, "neutron:uuid")
port_id = str(port_id).strip("'")
status_field = data.get('status')
if status_field is not None:
status = status_field.get('content')
LOG.debug("Update port for port id %s %s", port_id, status)
# for now we only support transition from DOWN->ACTIVE
# https://bugs.launchpad.net/networking-odl/+bug/1686023
if status == n_const.PORT_STATUS_ACTIVE:
provisioning_blocks.provisioning_complete(
context.get_admin_context(),
port_id, resources.PORT,
provisioning_blocks.L2_AGENT_ENTITY)
if operation == event.OPERATION_DELETE:
LOG.debug("PortStatus: Ignoring delete operation")
示例12: _update_agents_db_row
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def _update_agents_db_row(self, host_config):
if self.agents_db is None:
self.agents_db = directory.get_plugin()
# Update one row in agent db
host_id = host_config['host-id']
host_type = host_config['host-type']
config = host_config['config']
try:
agentdb_row = self._AGENTDB_ROW.copy()
agentdb_row['host'] = host_id
agentdb_row['agent_type'] = host_type
agentdb_row['configurations'] = jsonutils.loads(config)
if (host_id, host_type) in self._old_agents:
agentdb_row.pop('start_flag', None)
self.agents_db.create_or_update_agent(
context.get_admin_context(), agentdb_row)
self._known_agents.add((host_id, host_type))
except Exception:
LOG.exception("Unable to update agentdb.")
示例13: delete_agents_db_row
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def delete_agents_db_row(self, host_id, host_type):
"""Delete agent row."""
try:
filters = {'agent_type': [host_type],
'host': [host_id]}
# TODO(rsood): get_agent can be used here
agent = self.agents_db.get_agents_db(
context.get_admin_context(), filters=filters)
if not agent:
return
LOG.debug("Deleting Agent with Agent id: %s", agent[0]['id'])
self.agents_db.delete_agent(
context.get_admin_context(), agent[0]['id'])
self._known_agents.remove((host_id, host_type))
except Exception:
LOG.exception("Unable to delete from agentdb.")
示例14: test_add_router_interface_by_port_failure
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def test_add_router_interface_by_port_failure(self):
class _MyException(Exception):
pass
with self.port() as port, self.router() as router:
ctx = context.get_admin_context()
plugin = directory.get_plugin()
l3_plugin = directory.get_plugin(plugin_constants.L3)
router_id = router['router']['id']
port_id = port['port']['id']
interface_info = {
'port_id': port_id,
}
with mock.patch.object(l3_plugin.client,
'add_router_interface_postcommit',
auto_spec=True,
side_effect=_MyException), \
testtools.ExpectedException(_MyException):
l3_plugin.add_router_interface(ctx, router_id, interface_info)
port2 = plugin.get_port(ctx, port_id)
self.assertEqual(port_id, port2['id'])
示例15: router_port_callback
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import get_admin_context [as 别名]
def router_port_callback(self, resource, event, trigger, **kwargs):
if 'payload' in kwargs:
# TODO(boden): remove shim once all events use payloads
gw_network = kwargs['payload'].metadata.get('network_id')
else:
gw_network = kwargs['network_id']
# NOTE(xiaohhui) Not all events have context in kwargs(e.g router
# gw after create event), just get a admin context here.
admin_ctx = n_context.get_admin_context()
speakers = self._bgp_speakers_for_gateway_network(admin_ctx,
gw_network)
for speaker in speakers:
self._update_bgp_speaker_tenant_network_routes(admin_ctx,
speaker.id,
speaker.project_id)