本文整理汇总了Python中neutron_lib.callbacks.events.BEFORE_CREATE属性的典型用法代码示例。如果您正苦于以下问题:Python events.BEFORE_CREATE属性的具体用法?Python events.BEFORE_CREATE怎么用?Python events.BEFORE_CREATE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类neutron_lib.callbacks.events
的用法示例。
在下文中一共展示了events.BEFORE_CREATE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _register_callbacks
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def _register_callbacks(self):
registry.subscribe(self.floatingip_update_callback,
resources.FLOATING_IP,
events.AFTER_UPDATE)
registry.subscribe(self.router_interface_callback,
resources.ROUTER_INTERFACE,
events.AFTER_CREATE)
registry.subscribe(self.router_interface_callback,
resources.ROUTER_INTERFACE,
events.BEFORE_CREATE)
registry.subscribe(self.router_interface_callback,
resources.ROUTER_INTERFACE,
events.AFTER_DELETE)
registry.subscribe(self.router_gateway_callback,
resources.ROUTER_GATEWAY,
events.AFTER_CREATE)
registry.subscribe(self.router_gateway_callback,
resources.ROUTER_GATEWAY,
events.AFTER_DELETE)
registry.subscribe(self.port_callback,
resources.PORT,
events.AFTER_UPDATE)
示例2: test__register_callbacks
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test__register_callbacks(self):
with mock.patch.object(registry, 'subscribe') as subscribe:
plugin = bgp_plugin.BgpPlugin()
expected_calls = [
mock.call(plugin.bgp_drscheduler.schedule_bgp_speaker_callback,
dr_resources.BGP_SPEAKER, events.AFTER_CREATE),
mock.call(plugin.floatingip_update_callback,
resources.FLOATING_IP, events.AFTER_UPDATE),
mock.call(plugin.router_interface_callback,
resources.ROUTER_INTERFACE, events.AFTER_CREATE),
mock.call(plugin.router_interface_callback,
resources.ROUTER_INTERFACE, events.BEFORE_CREATE),
mock.call(plugin.router_interface_callback,
resources.ROUTER_INTERFACE, events.AFTER_DELETE),
mock.call(plugin.router_gateway_callback,
resources.ROUTER_GATEWAY, events.AFTER_CREATE),
mock.call(plugin.router_gateway_callback,
resources.ROUTER_GATEWAY, events.AFTER_DELETE),
mock.call(plugin.port_callback,
resources.PORT, events.AFTER_UPDATE),
]
self.assertEqual(subscribe.call_args_list, expected_calls)
示例3: test_unsubscribe_by_resource
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test_unsubscribe_by_resource(self):
self.manager.subscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.manager.subscribe(
callback_1, resources.PORT, events.BEFORE_DELETE)
self.manager.subscribe(
callback_2, resources.PORT, events.BEFORE_DELETE)
self.manager.unsubscribe_by_resource(callback_1, resources.PORT)
self.assertEqual(
0,
len(self.manager._callbacks
[resources.PORT][events.BEFORE_CREATE]))
self.assertEqual(
1,
len(self.manager._callbacks[resources.PORT][events.BEFORE_DELETE]))
self.assertIn(
callback_id_2,
self.manager._callbacks
[resources.PORT][events.BEFORE_DELETE][0][1])
self.assertNotIn(callback_id_1, self.manager._index)
示例4: test_decorated_inst_method_receives
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test_decorated_inst_method_receives(self):
i1 = ObjectWithDecoratedCallback()
registry.notify(resources.PORT, events.BEFORE_CREATE, self)
self.assertEqual(0, i1.counter)
registry.notify(resources.PORT, events.AFTER_CREATE, self)
self.assertEqual(1, i1.counter)
registry.notify(resources.PORT, events.AFTER_UPDATE, self)
self.assertEqual(2, i1.counter)
registry.notify(resources.NETWORK, events.AFTER_UPDATE, self)
self.assertEqual(2, i1.counter)
registry.notify(resources.NETWORK, events.AFTER_DELETE, self)
self.assertEqual(3, i1.counter)
i2 = ObjectWithDecoratedCallback()
self.assertEqual(0, i2.counter)
registry.notify(resources.NETWORK, events.AFTER_DELETE, self)
self.assertEqual(4, i1.counter)
self.assertEqual(1, i2.counter)
示例5: test_schedule_bgp_speaker_callback_with_invalid_event
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test_schedule_bgp_speaker_callback_with_invalid_event(self):
payload = self._create_test_payload()
with mock.patch.object(self.plugin,
'schedule_bgp_speaker') as sched_bgp:
self.scheduler.schedule_bgp_speaker_callback(
dr_resources.BGP_SPEAKER,
events.BEFORE_CREATE,
self.scheduler, payload)
sched_bgp.assert_not_called()
示例6: _call_before_port_binding
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def _call_before_port_binding(self, host):
kwargs = {
'context': mock.Mock(),
'port': {
portbindings.HOST_ID: host
}
}
registry.notify(resources.PORT, events.BEFORE_CREATE, self.ml2_plugin,
**kwargs)
示例7: before_port_binding
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def before_port_binding(self, resource, event, trigger, **kwargs):
LOG.debug("before_port resource %s event %s %s",
resource, event, kwargs)
assert resource == resources.PORT
assert event in [events.BEFORE_CREATE, events.BEFORE_UPDATE]
ml2_plugin = trigger
context = kwargs['context']
port = kwargs['port']
host = nl_const.ATTR_NOT_SPECIFIED
if port and portbindings.HOST_ID in port:
host = port.get(portbindings.HOST_ID)
if host == nl_const.ATTR_NOT_SPECIFIED or not host:
return
agent_type = PseudoAgentDBBindingWorker.L2_TYPE
if self._worker.known_agent(host, agent_type):
return
agents = ml2_plugin.get_agents(
context, filters={'agent_type': [agent_type], 'host': [host]})
if agents and all(agent['alive'] for agent in agents):
self._worker.add_known_agents(agents)
LOG.debug("agents %s", agents)
return
# This host may not be created/updated by worker.
# try to populate it.
urlpath = "hostconfig/{0}/{1}".format(
host, PseudoAgentDBBindingWorker.L2_TYPE)
try:
response = self.odl_rest_client.get(urlpath)
response.raise_for_status()
except Exception:
LOG.warning("REST/GET odl hostconfig/%s failed.", host,
exc_info=True)
return
LOG.debug("response %s", response.json())
hostconfig = response.json().get('hostconfig', [])
if hostconfig:
self._worker.update_agents_db_row(hostconfig[0])
示例8: test_subscribe
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test_subscribe(self):
self.manager.subscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.assertIsNotNone(
self.manager._callbacks[resources.PORT][events.BEFORE_CREATE])
self.assertIn(callback_id_1, self.manager._index)
self.assertEqual(self.__module__ + '.callback_1-%s' %
hash(callback_1), callback_id_1)
示例9: test_subscribe_is_idempotent
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test_subscribe_is_idempotent(self):
self.manager.subscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.manager.subscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.assertEqual(
1,
len(self.manager._callbacks[resources.PORT][events.BEFORE_CREATE]))
callbacks = self.manager._index[callback_id_1][resources.PORT]
self.assertEqual(1, len(callbacks))
示例10: test_subscribe_multiple_callbacks
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test_subscribe_multiple_callbacks(self):
self.manager.subscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.manager.subscribe(
callback_2, resources.PORT, events.BEFORE_CREATE)
self.assertEqual(2, len(self.manager._index))
self.assertEqual(
1,
len(self.manager._callbacks[resources.PORT][events.BEFORE_CREATE]))
self.assertEqual(
2,
len(self.manager._callbacks
[resources.PORT][events.BEFORE_CREATE][0][1]))
示例11: test_unsubscribe_during_iteration
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test_unsubscribe_during_iteration(self):
def unsub(r, e, *a, **k):
return self.manager.unsubscribe(unsub, r, e)
self.manager.subscribe(unsub, resources.PORT,
events.BEFORE_CREATE)
self.manager.notify(resources.PORT, events.BEFORE_CREATE, mock.ANY)
self.assertNotIn(unsub, self.manager._index)
示例12: test_unsubscribe
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test_unsubscribe(self):
self.manager.subscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.manager.unsubscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.assertNotIn(
callback_id_1,
self.manager._callbacks[resources.PORT][events.BEFORE_CREATE])
self.assertNotIn(callback_id_1, self.manager._index)
示例13: test_fail_to_unsubscribe
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test_fail_to_unsubscribe(self):
self.manager.subscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.assertRaises(exceptions.Invalid,
self.manager.unsubscribe,
callback_1, resources.PORT, None)
self.assertRaises(exceptions.Invalid,
self.manager.unsubscribe,
callback_1, None, events.BEFORE_CREATE)
示例14: test_unsubscribe_is_idempotent
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test_unsubscribe_is_idempotent(self):
self.manager.subscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.manager.unsubscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.manager.unsubscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.assertNotIn(callback_id_1, self.manager._index)
self.assertNotIn(callback_id_1,
self.manager._callbacks[resources.PORT]
[events.BEFORE_CREATE])
示例15: test_unsubscribe_all
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import BEFORE_CREATE [as 别名]
def test_unsubscribe_all(self):
self.manager.subscribe(
callback_1, resources.PORT, events.BEFORE_CREATE)
self.manager.subscribe(
callback_1, resources.PORT, events.BEFORE_DELETE)
self.manager.subscribe(
callback_1, resources.ROUTER, events.BEFORE_CREATE)
self.manager.unsubscribe_all(callback_1)
self.assertNotIn(
callback_id_1,
self.manager._callbacks[resources.PORT][events.BEFORE_CREATE])
self.assertNotIn(callback_id_1, self.manager._index)