Python neutron_lib.callbacks.registry.subscribe() Examples

The following are 15 code examples of neutron_lib.callbacks.registry.subscribe(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module neutron_lib.callbacks.registry , or try the search function .
Example #1
Source File: vpn_db.py    From neutron-vpnaas with Apache License 2.0 6 votes vote down vote up
def subscribe():
    registry.subscribe(
        vpn_router_gateway_callback, resources.ROUTER_GATEWAY,
        events.BEFORE_DELETE)
    registry.subscribe(
        vpn_router_gateway_callback, resources.ROUTER_INTERFACE,
        events.BEFORE_DELETE)
    registry.subscribe(
        migration_callback, resources.ROUTER, events.BEFORE_UPDATE)
    registry.subscribe(
        subnet_callback, resources.SUBNET, events.BEFORE_DELETE)


# NOTE(armax): multiple VPN service plugins (potentially out of tree) may
# inherit from vpn_db and may need the callbacks to be processed. Having an
# implicit subscription (through the module import) preserves the existing
# behavior, and at the same time it avoids fixing it manually in each and
# every vpn plugin outta there. That said, The subscription is also made
# explicitly in the reference vpn plugin. The subscription operation is
# idempotent so there is no harm in registering the same callback multiple
# times. 
Example #2
Source File: bgp_plugin.py    From neutron-dynamic-routing with Apache License 2.0 6 votes vote down vote up
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) 
Example #3
Source File: callback.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def _subscribe(self):
        if self._precommit is not None:
            for event in (events.PRECOMMIT_CREATE, events.PRECOMMIT_DELETE):
                registry.subscribe(self.sg_callback_precommit,
                                   resources.SECURITY_GROUP, event)
                registry.subscribe(self.sg_callback_precommit,
                                   resources.SECURITY_GROUP_RULE, event)
            registry.subscribe(
                self.sg_callback_precommit, resources.SECURITY_GROUP,
                events.PRECOMMIT_UPDATE)

        for event in (events.AFTER_CREATE, events.AFTER_DELETE):
            registry.subscribe(self.sg_callback_postcommit,
                               resources.SECURITY_GROUP, event)
            registry.subscribe(self.sg_callback_postcommit,
                               resources.SECURITY_GROUP_RULE, event)

        registry.subscribe(self.sg_callback_postcommit,
                           resources.SECURITY_GROUP, events.AFTER_UPDATE) 
Example #4
Source File: bgp_plugin.py    From dragonflow with Apache License 2.0 6 votes vote down vote up
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) 
Example #5
Source File: bgp_dragent_scheduler.py    From neutron-dynamic-routing with Apache License 2.0 5 votes vote down vote up
def _register_callbacks(self):
        registry.subscribe(self.schedule_bgp_speaker_callback,
                           dr_resources.BGP_SPEAKER,
                           events.AFTER_CREATE) 
Example #6
Source File: l2gateway_db.py    From networking-l2gw with Apache License 2.0 5 votes vote down vote up
def subscribe():
    interested_events = (events.AFTER_UPDATE,
                         events.AFTER_DELETE)
    for x in interested_events:
        registry.subscribe(
            l2gw_callback, resources.PORT, x) 
Example #7
Source File: trunk_driver_v2.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def register(self, resource, event, trigger, payload=None):
        super(OpenDaylightTrunkDriverV2, self).register(
            resource, event, trigger, payload=payload)
        self._handler = OpenDaylightTrunkHandlerV2()
        registry.subscribe(self._handler.trunk_create_precommit,
                           resources.TRUNK, events.PRECOMMIT_CREATE)
        registry.subscribe(self._handler.trunk_create_postcommit,
                           resources.TRUNK, events.AFTER_CREATE)
        registry.subscribe(self._handler.trunk_update_precommit,
                           resources.TRUNK, events.PRECOMMIT_UPDATE)
        registry.subscribe(self._handler.trunk_update_postcommit,
                           resources.TRUNK, events.AFTER_UPDATE)
        registry.subscribe(self._handler.trunk_delete_precommit,
                           resources.TRUNK, events.PRECOMMIT_DELETE)
        registry.subscribe(self._handler.trunk_delete_postcommit,
                           resources.TRUNK, events.AFTER_DELETE)
        for event_ in (events.PRECOMMIT_CREATE, events.PRECOMMIT_DELETE):
            registry.subscribe(self._handler.trunk_update_precommit,
                               resources.SUBPORTS, event_)
        for event_ in (events.AFTER_CREATE, events.AFTER_DELETE):
            registry.subscribe(self._handler.trunk_update_postcommit,
                               resources.SUBPORTS, event_)
            # Upon subport creation/deletion we need to set the right port
            # status:
            # 1. Set it to parent status when it is attached to the trunk
            # 2. Set it to down when is removed from the trunk
            registry.subscribe(self._handler.trunk_subports_set_status,
                               resources.SUBPORTS, event_)
        # NOTE(ltomasbo): if the status of the parent port changes, the
        # subports need to update their status too
        registry.subscribe(self._handler.trunk_subports_update_status,
                           resources.PORT, events.AFTER_UPDATE) 
Example #8
Source File: driver.py    From dragonflow with Apache License 2.0 5 votes vote down vote up
def _register_init_events(self):
        registry.subscribe(self.register,
                           resources.TRUNK_PLUGIN,
                           events.AFTER_INIT) 
Example #9
Source File: driver.py    From dragonflow with Apache License 2.0 5 votes vote down vote up
def _register_trunk_events(self):
        registry.subscribe(self._add_trunk_handler,
                           resources.TRUNK, events.AFTER_CREATE) 
Example #10
Source File: driver.py    From dragonflow with Apache License 2.0 5 votes vote down vote up
def _register_subport_events(self):
        registry.subscribe(self._add_subports_handler,
                           resources.SUBPORTS, events.AFTER_CREATE)
        registry.subscribe(self._delete_subports_handler,
                           resources.SUBPORTS, events.AFTER_DELETE)
        registry.subscribe(self._update_port_handler,
                           resources.PORT, events.AFTER_UPDATE) 
Example #11
Source File: l3_router_plugin.py    From dragonflow with Apache License 2.0 5 votes vote down vote up
def _register_callbacks(self):
        registry.subscribe(self.router_create_callback,
                           resources.ROUTER,
                           events.PRECOMMIT_CREATE)
        registry.subscribe(self._update_port_handler,
                           resources.PORT, events.AFTER_UPDATE) 
Example #12
Source File: dhcp_module.py    From dragonflow with Apache License 2.0 5 votes vote down vote up
def _register_subnet_events(self):
        # REVISIT(leyal): check if need  to handle the events inside
        # neutron-db transaction
        function_by_action = {
            events.AFTER_CREATE: self._subnet_create_handler,
            events.AFTER_UPDATE: self._subnet_update_handler,
            events.AFTER_DELETE: self._subnet_delete_handler
        }

        for action, func in function_by_action.items():
            registry.subscribe(func, resources.SUBNET, action) 
Example #13
Source File: test_registry.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_object_inheriting_others_no_double_subscribe(self):
        with mock.patch.object(registry, 'subscribe') as sub:
            callback = AnotherObjectWithDecoratedCallback()
            # there are 3 methods (2 in parent and one in child) and 1
            # subscribes to 2 events, so we expect 4 subscribes
            priority_call = [mock.call(
                callback.callback2,
                resources.NETWORK, events.AFTER_DELETE, PRI_CALLBACK)]
            self.assertEqual(4, len(sub.mock_calls))
            sub.assert_has_calls(priority_call) 
Example #14
Source File: test_registry.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_subscribe(self):
        registry.subscribe(my_callback, 'my-resource', 'my-event')
        self.callback_manager.subscribe.assert_called_with(
            my_callback, 'my-resource', 'my-event',
            priority_group.PRIORITY_DEFAULT) 
Example #15
Source File: test_registry.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_subscribe_explicit_priority(self):
        registry.subscribe(my_callback, 'my-resource', 'my-event',
                           PRI_CALLBACK)
        self.callback_manager.subscribe.assert_called_with(
            my_callback, 'my-resource', 'my-event', PRI_CALLBACK)