本文整理汇总了Python中neutron_lib.callbacks.events.AFTER_CREATE属性的典型用法代码示例。如果您正苦于以下问题:Python events.AFTER_CREATE属性的具体用法?Python events.AFTER_CREATE怎么用?Python events.AFTER_CREATE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类neutron_lib.callbacks.events
的用法示例。
在下文中一共展示了events.AFTER_CREATE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _register_callbacks
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_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: router_gateway_callback
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [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)
示例3: test__register_callbacks
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_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)
示例4: test_create_bgp_speaker
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [as 别名]
def test_create_bgp_speaker(self):
test_context = 'create_bgp_context'
test_bgp_speaker = {'id': None}
payload = self._create_test_payload(context=test_context)
with mock.patch.object(bgp_db.BgpDbMixin,
'create_bgp_speaker') as create_bgp_sp:
with mock.patch.object(registry, 'notify') as notify:
create_bgp_sp.return_value = payload['bgp_speaker']
self.assertEqual(self.plugin.create_bgp_speaker(
test_context, test_bgp_speaker),
payload['bgp_speaker'])
create_bgp_sp.assert_called_once_with(test_context,
test_bgp_speaker)
notify.assert_called_once_with(dr_resources.BGP_SPEAKER,
events.AFTER_CREATE,
self.plugin,
payload=payload)
示例5: test_trunk_subports_set_status_create_parent_active
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [as 别名]
def test_trunk_subports_set_status_create_parent_active(
self, mock_set_subport_status):
resource = resources.SUBPORTS
event_type = events.AFTER_CREATE
fake_payload = self._fake_trunk_payload()
core_plugin = directory.get_plugin()
fake_payload.subports = [models.SubPort(port_id='fake_port_id',
segmentation_id=101,
segmentation_type='vlan',
trunk_id='fake_id')]
parent_port = FAKE_PARENT
with mock.patch.object(core_plugin, '_get_port') as gp:
gp.return_value = parent_port
self.handler.trunk_subports_set_status(resource, event_type,
mock.ANY, fake_payload)
mock_set_subport_status.assert_called_once_with(
core_plugin, mock.ANY, 'fake_port_id',
n_const.PORT_STATUS_ACTIVE)
示例6: test_trunk_subports_set_status_create_parent_down
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [as 别名]
def test_trunk_subports_set_status_create_parent_down(
self, mock_set_subport_status):
resource = resources.SUBPORTS
event_type = events.AFTER_CREATE
fake_payload = self._fake_trunk_payload()
core_plugin = directory.get_plugin()
fake_payload.subports = [models.SubPort(port_id='fake_port_id',
segmentation_id=101,
segmentation_type='vlan',
trunk_id='fake_id')]
parent_port = FAKE_PARENT.copy()
parent_port['status'] = n_const.PORT_STATUS_DOWN
with mock.patch.object(core_plugin, '_get_port') as gp:
gp.return_value = parent_port
self.handler.trunk_subports_set_status(resource, event_type,
mock.ANY, fake_payload)
mock_set_subport_status.assert_called_once_with(
core_plugin, mock.ANY, 'fake_port_id',
n_const.PORT_STATUS_DOWN)
示例7: _register_callbacks
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [as 别名]
def _register_callbacks(self):
registry.subscribe(self.floatingip_update_callback,
resources.FLOATING_IP,
events.AFTER_UPDATE)
registry.subscribe(self.router_port_callback,
resources.ROUTER_INTERFACE,
events.AFTER_CREATE)
registry.subscribe(self.router_port_callback,
resources.ROUTER_INTERFACE,
events.AFTER_DELETE)
registry.subscribe(self.router_port_callback,
resources.ROUTER_GATEWAY,
events.AFTER_CREATE)
registry.subscribe(self.router_port_callback,
resources.ROUTER_GATEWAY,
events.AFTER_DELETE)
示例8: subscribe_registries
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [as 别名]
def subscribe_registries(self):
registry.subscribe(self.post_fork_initialize,
resources.PROCESS,
events.AFTER_INIT)
registry.subscribe(self.update_security_group,
resources.SECURITY_GROUP,
events.AFTER_CREATE)
registry.subscribe(self.update_security_group,
resources.SECURITY_GROUP,
events.AFTER_UPDATE)
registry.subscribe(self.delete_security_group,
resources.SECURITY_GROUP,
events.BEFORE_DELETE)
registry.subscribe(self.create_security_group_rule,
resources.SECURITY_GROUP_RULE,
events.AFTER_CREATE)
registry.subscribe(self.delete_security_group_rule,
resources.SECURITY_GROUP_RULE,
events.AFTER_DELETE)
示例9: update_security_group
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [as 别名]
def update_security_group(self, resource, event, trigger, **kwargs):
sg = kwargs['security_group']
sg_name = sg.get('name')
rules = sg.get('security_group_rules', [])
for rule in rules:
try:
rule['topic'] = rule.pop('project_id')
except KeyError:
rule['topic'] = rule.pop('tenant_id', None)
sg_obj = neutron_secgroups.security_group_from_neutron_obj(sg)
if event == events.AFTER_CREATE:
self.nb_api.create(sg_obj)
LOG.info("DFMechDriver: create security group %s", sg_name)
elif event == events.AFTER_UPDATE:
self.nb_api.update(sg_obj)
LOG.info("DFMechDriver: update security group %s", sg_name)
return sg_obj
示例10: test_decorated_inst_method_receives
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_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)
示例11: create_bgp_speaker
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [as 别名]
def create_bgp_speaker(self, context, bgp_speaker):
bgp_speaker = super(BgpPlugin, self).create_bgp_speaker(context,
bgp_speaker)
payload = {'plugin': self, 'context': context,
'bgp_speaker': bgp_speaker}
registry.notify(dr_resources.BGP_SPEAKER, events.AFTER_CREATE,
self, payload=payload)
return bgp_speaker
示例12: router_interface_callback
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [as 别名]
def router_interface_callback(self, resource, event, trigger, **kwargs):
if event == events.AFTER_CREATE:
self._handle_router_interface_after_create(**kwargs)
if event == events.AFTER_DELETE:
gw_network = kwargs['network_id']
next_hops = self._next_hops_from_gateway_ips(
kwargs['gateway_ips'])
ctx = context.get_admin_context()
speakers = self._bgp_speakers_for_gateway_network(ctx, gw_network)
for speaker in speakers:
routes = self._route_list_from_prefixes_and_next_hop(
kwargs['cidrs'],
next_hops[speaker.ip_version])
self._handle_router_interface_after_delete(gw_network, routes)
示例13: _register_callbacks
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [as 别名]
def _register_callbacks(self):
registry.subscribe(self.schedule_bgp_speaker_callback,
dr_resources.BGP_SPEAKER,
events.AFTER_CREATE)
示例14: test__register_callbacks
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [as 别名]
def test__register_callbacks(self):
with mock.patch.object(registry, 'subscribe') as subscribe:
scheduler = bgp_dras.ChanceScheduler()
expected_calls = [
mock.call(scheduler.schedule_bgp_speaker_callback,
dr_resources.BGP_SPEAKER, events.AFTER_CREATE),
]
self.assertEqual(subscribe.call_args_list, expected_calls)
with mock.patch.object(registry, 'subscribe') as subscribe:
scheduler = bgp_dras.WeightScheduler()
expected_calls = [
mock.call(scheduler.schedule_bgp_speaker_callback,
dr_resources.BGP_SPEAKER, events.AFTER_CREATE),
]
self.assertEqual(subscribe.call_args_list, expected_calls)
示例15: test_schedule_bgp_speaker_callback_with_valid_event
# 需要导入模块: from neutron_lib.callbacks import events [as 别名]
# 或者: from neutron_lib.callbacks.events import AFTER_CREATE [as 别名]
def test_schedule_bgp_speaker_callback_with_valid_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.AFTER_CREATE,
self.scheduler, payload)
sched_bgp.assert_called_once_with(mock.ANY,
payload['bgp_speaker'])