예제 #1
0
파일: nec_plugin.py 프로젝트: rodis/neutron
    def setup_rpc(self):
        self.service_topics = {
            svc_constants.CORE: topics.PLUGIN,
            svc_constants.L3_ROUTER_NAT: topics.L3PLUGIN
        }
        self.conn = n_rpc.create_connection(new=True)
        self.notifier = NECPluginV2AgentNotifierApi(topics.AGENT)
        self.agent_notifiers[const.AGENT_TYPE_DHCP] = (
            dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
        self.agent_notifiers[const.AGENT_TYPE_L3] = (
            nec_router.L3AgentNotifyAPI())

        # NOTE: callback_sg is referred to from the sg unit test.
        self.callback_sg = securitygroups_rpc.SecurityGroupServerRpcCallback()
        self.endpoints = [
            NECPluginV2RPCCallbacks(self.safe_reference),
            dhcp_rpc.DhcpRpcCallback(),
            l3_rpc.L3RpcCallback(), self.callback_sg,
            agents_db.AgentExtRpcCallback(),
            metadata_rpc.MetadataRpcCallback()
        ]
        for svc_topic in self.service_topics.values():
            self.conn.create_consumer(svc_topic, self.endpoints, fanout=False)
        # Consume from all consumers in threads
        self.conn.consume_in_threads()
예제 #2
0
    def setup_rpc(self):
        self.service_topics = {
            svc_constants.CORE: topics.PLUGIN,
            svc_constants.L3_ROUTER_NAT: topics.L3PLUGIN
        }
        self.conn = rpc.create_connection(new=True)
        self.notifier = NECPluginV2AgentNotifierApi(topics.AGENT)
        self.agent_notifiers[const.AGENT_TYPE_DHCP] = (
            dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
        self.agent_notifiers[const.AGENT_TYPE_L3] = (
            nec_router.L3AgentNotifyAPI())

        # NOTE: callback_sg is referred to from the sg unit test.
        self.callback_sg = SecurityGroupServerRpcCallback()
        callbacks = [
            NECPluginV2RPCCallbacks(self),
            DhcpRpcCallback(),
            L3RpcCallback(), self.callback_sg,
            agents_db.AgentExtRpcCallback()
        ]
        self.dispatcher = q_rpc.PluginRpcDispatcher(callbacks)
        for svc_topic in self.service_topics.values():
            self.conn.create_consumer(svc_topic, self.dispatcher, fanout=False)
        # Consume from all consumers in a thread
        self.conn.consume_in_thread()
예제 #3
0
def _destroy_metadata_access_network(plugin, context, router_id, ports):
    if not ports:
        return
    meta_port = _find_metadata_port(plugin, context, ports)
    if not meta_port:
        return
    meta_net_id = meta_port['network_id']
    meta_sub_id = meta_port['fixed_ips'][0]['subnet_id']
    plugin.remove_router_interface(context, router_id,
                                   {'port_id': meta_port['id']})
    greenthread.sleep(0)  # yield
    try:
        # Remove network (this will remove the subnet too)
        plugin.delete_network(context, meta_net_id)
        greenthread.sleep(0)  # yield
    except (ntn_exc.NeutronException, nvp_exc.NvpPluginException,
            NvpApiClient.NvpApiException):
        # must re-add the router interface
        plugin.add_router_interface(context, router_id,
                                    {'subnet_id': meta_sub_id})

    if cfg.CONF.dhcp_agent_notification:
        # We need to send a notification to the dhcp agent in
        # order to stop the metadata agent proxy
        dhcp_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
        dhcp_notifier.notify(context, {'network': {
            'id': meta_net_id
        }}, 'network.delete.end')
예제 #4
0
    def __init__(self, server_timeout=None):
        super(NeutronRestProxyV2, self).__init__()
        LOG.info(_('NeutronRestProxy: Starting plugin. Version=%s'),
                 version_string_with_vcs())
        pl_config.register_config()

        # Include the BigSwitch Extensions path in the api_extensions
        neutron_extensions.append_api_extensions_path(extensions.__path__)

        self.add_meta_server_route = cfg.CONF.RESTPROXY.add_meta_server_route

        # init network ctrl connections
        self.servers = servermanager.ServerPool(server_timeout)

        # init dhcp support
        self.topic = topics.PLUGIN
        self.network_scheduler = importutils.import_object(
            cfg.CONF.network_scheduler_driver)
        self._dhcp_agent_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
        self.agent_notifiers[const.AGENT_TYPE_DHCP] = (
            self._dhcp_agent_notifier)
        self.conn = rpc.create_connection(new=True)
        self.callbacks = RpcProxy()
        self.dispatcher = self.callbacks.create_rpc_dispatcher()
        self.conn.create_consumer(self.topic, self.dispatcher, fanout=False)
        # Consume from all consumers in a thread
        self.conn.consume_in_thread()
        if cfg.CONF.RESTPROXY.sync_data:
            self._send_all_data()

        LOG.debug(_("NeutronRestProxyV2: initialization done"))
예제 #5
0
 def _setup_rpc(self):
     # RPC support
     self.service_topics = {
         svc_constants.CORE: topics.PLUGIN,
         svc_constants.L3_ROUTER_NAT: topics.L3PLUGIN
     }
     self.rpc_context = oslo_context.RequestContext('neutron',
                                                    'neutron',
                                                    is_admin=False)
     self.conn = n_rpc.create_connection(new=True)
     self.endpoints = [
         BridgeRpcCallbacks(),
         securitygroups_rpc.SecurityGroupServerRpcCallback(),
         dhcp_rpc.DhcpRpcCallback(),
         l3_rpc.L3RpcCallback(),
         agents_db.AgentExtRpcCallback(),
         metadata_rpc.MetadataRpcCallback()
     ]
     for svc_topic in self.service_topics.values():
         self.conn.create_consumer(svc_topic, self.endpoints, fanout=False)
     # Consume from all consumers in threads
     self.conn.consume_in_threads()
     self.notifier = AgentNotifierApi(topics.AGENT)
     self.agent_notifiers[q_const.AGENT_TYPE_DHCP] = (
         dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
     self.agent_notifiers[q_const.AGENT_TYPE_L3] = (
         l3_rpc_agent_api.L3AgentNotifyAPI())
예제 #6
0
    def __init__(self,
                 plugin,
                 collection,
                 resource,
                 attr_info,
                 allow_bulk=False,
                 member_actions=None,
                 parent=None,
                 allow_pagination=False,
                 allow_sorting=False):
        if member_actions is None:
            member_actions = []
        self._plugin = plugin
        self._collection = collection.replace('-', '_')
        self._resource = resource.replace('-', '_')
        self._attr_info = attr_info
        self._allow_bulk = allow_bulk
        self._allow_pagination = allow_pagination
        self._allow_sorting = allow_sorting
        self._native_bulk = self._is_native_bulk_supported()
        self._native_pagination = self._is_native_pagination_supported()
        self._native_sorting = self._is_native_sorting_supported()
        self._policy_attrs = [
            name for (name, info) in self._attr_info.items()
            if info.get('required_by_policy')
        ]
        self._notifier = n_rpc.get_notifier('network')
        # use plugin's dhcp notifier, if this is already instantiated
        agent_notifiers = getattr(plugin, 'agent_notifiers', {})
        self._dhcp_agent_notifier = (agent_notifiers.get(
            const.AGENT_TYPE_DHCP) or dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
        if cfg.CONF.notify_nova_on_port_data_changes:
            from neutron.notifiers import nova
            self._nova_notifier = nova.Notifier()
        self._member_actions = member_actions
        self._primary_key = self._get_primary_key()
        if self._allow_pagination and self._native_pagination:
            # Native pagination need native sorting support
            if not self._native_sorting:
                raise exceptions.Invalid(
                    _("Native pagination depend on native sorting"))
            if not self._allow_sorting:
                LOG.info(
                    _LI("Allow sorting is enabled because native "
                        "pagination requires native sorting"))
                self._allow_sorting = True

        if parent:
            self._parent_id_name = '%s_id' % parent['member_name']
            parent_part = '_%s' % parent['member_name']
        else:
            self._parent_id_name = None
            parent_part = ''
        self._plugin_handlers = {
            self.LIST: 'get%s_%s' % (parent_part, self._collection),
            self.SHOW: 'get%s_%s' % (parent_part, self._resource)
        }
        for action in [self.CREATE, self.UPDATE, self.DELETE]:
            self._plugin_handlers[action] = '%s%s_%s' % (action, parent_part,
                                                         self._resource)
예제 #7
0
    def _start_rpc_notifiers(self):
        """Initialize RPC notifiers for agents."""

        if cfg.CONF.df.use_centralized_ipv6_DHCP:
            self.agent_notifiers[const.AGENT_TYPE_DHCP] = (
                dhcp_rpc_agent_api.DhcpAgentNotifyAPI())

        self.agent_notifiers[const.AGENT_TYPE_L3] = (
            l3_rpc_agent_api.L3AgentNotifyAPI())
예제 #8
0
 def _dhcp_agent_notifier(self):
     # REVISIT(rkukura): Need initialization method after all
     # plugins are loaded to grab and store notifier.
     if not self._cached_agent_notifier:
         agent_notifiers = getattr(self._core_plugin, 'agent_notifiers', {})
         self._cached_agent_notifier = (
             agent_notifiers.get(const.AGENT_TYPE_DHCP)
             or dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
     return self._cached_agent_notifier
예제 #9
0
 def _setup_rpc_dhcp_metadata(self):
     self.topic = topics.PLUGIN
     self.conn = rpc.create_connection(new=True)
     self.dispatcher = nvp_rpc.NVPRpcCallbacks().create_rpc_dispatcher()
     self.conn.create_consumer(self.topic, self.dispatcher, fanout=False)
     self.agent_notifiers[const.AGENT_TYPE_DHCP] = (
         dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
     self.conn.consume_in_thread()
     self.network_scheduler = importutils.import_object(
         cfg.CONF.network_scheduler_driver)
예제 #10
0
 def _setup_rpc(self):
     self.notifier = rpc.AgentNotifierApi(topics.AGENT)
     self.agent_notifiers[const.AGENT_TYPE_DHCP] = (
         dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
     self.callbacks = rpc.RpcCallbacks(self.notifier, self.type_manager)
     self.topic = topics.PLUGIN
     self.conn = c_rpc.create_connection(new=True)
     self.dispatcher = self.callbacks.create_rpc_dispatcher()
     self.conn.create_consumer(self.topic, self.dispatcher, fanout=False)
     self.conn.consume_in_thread()
예제 #11
0
    def __init__(self,
                 plugin,
                 collection,
                 resource,
                 attr_info,
                 allow_bulk=False,
                 member_actions=None,
                 parent=None,
                 allow_pagination=False,
                 allow_sorting=False):
        if member_actions is None:
            member_actions = []
        self._plugin = plugin
        self._collection = collection.replace('-', '_')
        self._resource = resource.replace('-', '_')
        self._attr_info = attr_info
        self._allow_bulk = allow_bulk
        self._allow_pagination = allow_pagination
        self._allow_sorting = allow_sorting
        self._native_bulk = self._is_native_bulk_supported()
        self._native_pagination = self._is_native_pagination_supported()
        self._native_sorting = self._is_native_sorting_supported()
        self._policy_attrs = [
            name for (name, info) in self._attr_info.items()
            if info.get('required_by_policy')
        ]
        self._publisher_id = notifier_api.publisher_id('network')
        self._dhcp_agent_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
        self._member_actions = member_actions
        self._primary_key = self._get_primary_key()
        if self._allow_pagination and self._native_pagination:
            # Native pagination need native sorting support
            if not self._native_sorting:
                raise exceptions.Invalid(
                    _("Native pagination depend on native sorting"))
            if not self._allow_sorting:
                LOG.info(
                    _("Allow sorting is enabled because native "
                      "pagination requires native sorting"))
                self._allow_sorting = True

        if parent:
            self._parent_id_name = '%s_id' % parent['member_name']
            parent_part = '_%s' % parent['member_name']
        else:
            self._parent_id_name = None
            parent_part = ''
        self._plugin_handlers = {
            self.LIST: 'get%s_%s' % (parent_part, self._collection),
            self.SHOW: 'get%s_%s' % (parent_part, self._resource)
        }
        for action in [self.CREATE, self.UPDATE, self.DELETE]:
            self._plugin_handlers[action] = '%s%s_%s' % (action, parent_part,
                                                         self._resource)
예제 #12
0
 def _setup_rpc_dhcp_metadata(self, notifier=None):
     self.topic = topics.PLUGIN
     self.conn = rpc.create_connection(new=True)
     self.dispatcher = nsx_rpc.NSXRpcCallbacks().create_rpc_dispatcher()
     self.conn.create_consumer(self.topic, self.dispatcher, fanout=False)
     self.agent_notifiers[const.AGENT_TYPE_DHCP] = (
         notifier or dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
     self.conn.consume_in_thread()
     self.network_scheduler = importutils.import_object(
         cfg.CONF.network_scheduler_driver)
     self.supported_extension_aliases.extend(
         ['agent', 'dhcp_agent_scheduler'])
예제 #13
0
 def _notify_dhcp_agent(self, context, resource_name, action, resources):
     plugin = manager.NeutronManager.get_plugin_for_resource(resource_name)
     notifier_method = '%s.%s.end' % (resource_name, action)
     # use plugin's dhcp notifier, if this is already instantiated
     agent_notifiers = getattr(plugin, 'agent_notifiers', {})
     dhcp_agent_notifier = (agent_notifiers.get(constants.AGENT_TYPE_DHCP)
                            or dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
     # The DHCP Agent does not accept bulk notifications
     for resource in resources:
         item = {resource_name: resource}
         LOG.debug("Sending DHCP agent notification for: %s", item)
         dhcp_agent_notifier.notify(context, item, notifier_method)
예제 #14
0
 def _setup_rpc(self):
     # RPC support
     self.topic = topics.PLUGIN
     self.conn = rpc.create_connection(new=True)
     self.notifier = AgentNotifierApi(topics.AGENT)
     self.callbacks = N1kvRpcCallbacks(self.notifier)
     self.dispatcher = self.callbacks.create_rpc_dispatcher()
     self.conn.create_consumer(self.topic, self.dispatcher, fanout=False)
     # Consume from all consumers in a thread
     self.dhcp_agent_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
     self.l3_agent_notifier = l3_rpc_agent_api.L3AgentNotify
     self.conn.consume_in_thread()
예제 #15
0
 def _setup_rpc(self):
     self.conn = rpc.create_connection(new=True)
     self.topic = topics.PLUGIN
     self.notifier = AgentNotifierApi(topics.AGENT)
     # init dhcp agent support
     self._dhcp_agent_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
     self.agent_notifiers[const.AGENT_TYPE_DHCP] = (
         self._dhcp_agent_notifier)
     self.callbacks = RestProxyCallbacks()
     self.dispatcher = self.callbacks.create_rpc_dispatcher()
     self.conn.create_consumer(self.topic, self.dispatcher, fanout=False)
     # Consume from all consumers in a thread
     self.conn.consume_in_thread()
예제 #16
0
    def setUp(self):
        super(TestDhcpAgentNotifyAPI, self).setUp()
        self.notifier = (dhcp_rpc_agent_api.DhcpAgentNotifyAPI(
            plugin=mock.Mock()))

        mock_util_p = mock.patch.object(utils, 'is_extension_supported')
        mock_log_p = mock.patch.object(dhcp_rpc_agent_api, 'LOG')
        mock_fanout_p = mock.patch.object(self.notifier, '_fanout_message')
        mock_cast_p = mock.patch.object(self.notifier, '_cast_message')
        self.mock_util = mock_util_p.start()
        self.mock_log = mock_log_p.start()
        self.mock_fanout = mock_fanout_p.start()
        self.mock_cast = mock_cast_p.start()
예제 #17
0
 def setup_rpc(self):
     # RPC support
     self.topic = topics.PLUGIN
     self.conn = rpc.create_connection(new=True)
     self.notifier = AgentNotifierApi(topics.AGENT)
     self.agent_notifiers[q_const.AGENT_TYPE_DHCP] = (
         dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
     self.agent_notifiers[q_const.AGENT_TYPE_L3] = (
         l3_rpc_agent_api.L3AgentNotify)
     self.callbacks = OVSRpcCallbacks(self.notifier, self.tunnel_type)
     self.dispatcher = self.callbacks.create_rpc_dispatcher()
     self.conn.create_consumer(self.topic, self.dispatcher, fanout=False)
     # Consume from all consumers in a thread
     self.conn.consume_in_thread()
예제 #18
0
def _create_metadata_access_network(plugin, context, router_id):
    # Add network
    # Network name is likely to be truncated on NVP
    net_data = {
        'name': 'meta-%s' % router_id,
        'tenant_id': '',  # intentionally not set
        'admin_state_up': True,
        'port_security_enabled': False,
        'shared': False,
        'status': const.NET_STATUS_ACTIVE
    }
    meta_net = plugin.create_network(context, {'network': net_data})
    greenthread.sleep(0)  # yield
    # From this point on there will be resources to garbage-collect
    # in case of failures
    meta_sub = None
    try:
        # Add subnet
        subnet_data = {
            'network_id': meta_net['id'],
            'tenant_id': '',  # intentionally not set
            'name': 'meta-%s' % router_id,
            'ip_version': 4,
            'shared': False,
            'cidr': METADATA_SUBNET_CIDR,
            'enable_dhcp': True,
            # Ensure default allocation pool is generated
            'allocation_pools': attributes.ATTR_NOT_SPECIFIED,
            'gateway_ip': METADATA_GATEWAY_IP,
            'dns_nameservers': [],
            'host_routes': []
        }
        meta_sub = plugin.create_subnet(context, {'subnet': subnet_data})
        greenthread.sleep(0)  # yield
        plugin.add_router_interface(context, router_id,
                                    {'subnet_id': meta_sub['id']})
        greenthread.sleep(0)  # yield
    except (ntn_exc.NeutronException, nvp_exc.NvpPluginException,
            NvpApiClient.NvpApiException):
        # It is not necessary to explicitly delete the subnet
        # as it will be removed with the network
        plugin.delete_network(context, meta_net['id'])

    if cfg.CONF.dhcp_agent_notification:
        # We need to send a notification to the dhcp agent in
        # order to start the metadata agent proxy
        dhcp_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
        dhcp_notifier.notify(context, {'network': meta_net},
                             'network.create.end')
예제 #19
0
 def _setup_rpc(self):
     self.conn = n_rpc.create_connection(new=True)
     self.topic = topics.PLUGIN
     self.notifier = AgentNotifierApi(topics.AGENT)
     # init dhcp agent support
     self._dhcp_agent_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
     self.agent_notifiers[const.AGENT_TYPE_DHCP] = (
         self._dhcp_agent_notifier)
     self.endpoints = [
         RestProxyCallbacks(),
         agents_db.AgentExtRpcCallback()
     ]
     self.conn.create_consumer(self.topic, self.endpoints, fanout=False)
     # Consume from all consumers in threads
     self.conn.consume_in_threads()
예제 #20
0
 def _setup_rpc_dhcp_metadata(self, notifier=None):
     self.topic = topics.PLUGIN
     self.conn = n_rpc.create_connection(new=True)
     self.endpoints = [dhcp_rpc.DhcpRpcCallback(),
                       agents_db.AgentExtRpcCallback(),
                       metadata_rpc.MetadataRpcCallback()]
     self.conn.create_consumer(self.topic, self.endpoints, fanout=False)
     self.agent_notifiers[const.AGENT_TYPE_DHCP] = (
         notifier or dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
     self.conn.consume_in_threads()
     self.network_scheduler = importutils.import_object(
         cfg.CONF.network_scheduler_driver
     )
     self.supported_extension_aliases.extend(
         ['agent', 'dhcp_agent_scheduler'])
예제 #21
0
def handle_port_dhcp_access(plugin, context, port_data, action):
    if action == 'create_port':
        net = plugin.get_network(context, port_data['network_id'])
        plugin.schedule_network(context, net)

    active_port = (cfg.CONF.NVP.metadata_mode == config.MetadataModes.INDIRECT
                   and port_data.get('device_owner') == const.DEVICE_OWNER_DHCP
                   and port_data.get('fixed_ips', []))
    if active_port:
        subnet_id = port_data['fixed_ips'][0]['subnet_id']
        subnet = plugin.get_subnet(context, subnet_id)
        if (cfg.CONF.dhcp_agent_notification and subnet.get('gateway_ip')
                or action == 'delete_port'):
            dhcp_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
            dhcp_notifier.notify(context, {'subnet': subnet},
                                 'subnet.update.end')
예제 #22
0
 def _setup_rpc(self):
     self.conn = n_rpc.create_connection()
     self.topic = topics.PLUGIN
     self.notifier = AgentNotifierApi(topics.AGENT)
     # init dhcp agent support
     self._dhcp_agent_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
     self.agent_notifiers[const.AGENT_TYPE_DHCP] = (
         self._dhcp_agent_notifier
     )
     self.endpoints = [securitygroups_rpc.SecurityGroupServerRpcCallback(),
                       dhcp_rpc.DhcpRpcCallback(),
                       agents_db.AgentExtRpcCallback(),
                       metadata_rpc.MetadataRpcCallback()]
     self.conn.create_consumer(self.topic, self.endpoints,
                               fanout=False)
     # Consume from all consumers in threads
     self.conn.consume_in_threads()
예제 #23
0
 def _setup_rpc(self):
     # RPC support
     self.topic = topics.PLUGIN
     self.rpc_context = context.RequestContext('neutron',
                                               'neutron',
                                               is_admin=False)
     self.conn = rpc.create_connection(new=True)
     self.callbacks = BridgeRpcCallbacks()
     self.dispatcher = self.callbacks.create_rpc_dispatcher()
     self.conn.create_consumer(self.topic, self.dispatcher, fanout=False)
     # Consume from all consumers in a thread
     self.conn.consume_in_thread()
     self.notifier = AgentNotifierApi(topics.AGENT)
     self.agent_notifiers[q_const.AGENT_TYPE_DHCP] = (
         dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
     self.agent_notifiers[q_const.AGENT_TYPE_L3] = (
         l3_rpc_agent_api.L3AgentNotify)
예제 #24
0
 def _notify_dhcp_agent(self, context, resource_name, action, resources):
     # NOTE(kevinbenton): we should remove this whole method in Ocata and
     # make plugins emit the core resource events
     plugin = manager.NeutronManager.get_plugin_for_resource(resource_name)
     notifier_method = '%s.%s.end' % (resource_name, action)
     # use plugin's dhcp notifier, if this is already instantiated
     agent_notifiers = getattr(plugin, 'agent_notifiers', {})
     dhcp_agent_notifier = (agent_notifiers.get(constants.AGENT_TYPE_DHCP)
                            or dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
     native_map = getattr(dhcp_agent_notifier, 'uses_native_notifications',
                          {})
     if native_map.get(resource_name, {}).get(action):
         return
     # The DHCP Agent does not accept bulk notifications
     for resource in resources:
         item = {resource_name: resource}
         LOG.debug("Sending DHCP agent notification for: %s", item)
         dhcp_agent_notifier.notify(context, item, notifier_method)
예제 #25
0
 def setup_rpc(self):
     # RPC support
     self.service_topics = {svc_constants.CORE: topics.PLUGIN,
                            svc_constants.L3_ROUTER_NAT: topics.L3PLUGIN}
     self.conn = rpc.create_connection(new=True)
     self.notifier = AgentNotifierApi(topics.AGENT)
     self.agent_notifiers[q_const.AGENT_TYPE_DHCP] = (
         dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
     )
     self.agent_notifiers[q_const.AGENT_TYPE_L3] = (
         l3_rpc_agent_api.L3AgentNotify
     )
     self.callbacks = OVSRpcCallbacks(self.notifier, self.tunnel_type)
     self.dispatcher = self.callbacks.create_rpc_dispatcher()
     for svc_topic in self.service_topics.values():
         self.conn.create_consumer(svc_topic, self.dispatcher, fanout=False)
     # Consume from all consumers in a thread
     self.conn.consume_in_thread()
예제 #26
0
 def _destroy_metadata_access_network(self, context, router_id, ports):
     # This will still ensure atomicity on Neutron DB
     with context.session.begin(subtransactions=True):
         if ports:
             meta_port = self._find_metadata_port(context, ports)
             if not meta_port:
                 return
             meta_net_id = meta_port['network_id']
             self.remove_router_interface(
                 context, router_id, {'port_id': meta_port['id']})
             # Remove network (this will remove the subnet too)
             self.delete_network(context, meta_net_id)
             if cfg.CONF.dhcp_agent_notification:
                 # We need to send a notification to the dhcp agent in
                 # order to stop the metadata agent proxy
                 dhcp_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
                 dhcp_notifier.notify(context,
                                      {'network': {'id': meta_net_id}},
                                      'network.delete.end')
예제 #27
0
 def _setup_rpc(self):
     # RPC support
     self.service_topics = {
         svc_constants.CORE: topics.PLUGIN,
         svc_constants.L3_ROUTER_NAT: topics.L3PLUGIN
     }
     self.conn = n_rpc.create_connection(new=True)
     self.endpoints = [
         rpc_callbacks.MlnxRpcCallbacks(),
         agents_db.AgentExtRpcCallback()
     ]
     for svc_topic in self.service_topics.values():
         self.conn.create_consumer(svc_topic, self.endpoints, fanout=False)
     # Consume from all consumers in threads
     self.conn.consume_in_threads()
     self.notifier = agent_notify_api.AgentNotifierApi(topics.AGENT)
     self.agent_notifiers[q_const.AGENT_TYPE_DHCP] = (
         dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
     self.agent_notifiers[q_const.AGENT_TYPE_L3] = (
         l3_rpc_agent_api.L3AgentNotifyAPI())
예제 #28
0
    def setup_rpc(self):
        self.topic = topics.PLUGIN
        self.conn = rpc.create_connection(new=True)
        self.notifier = NECPluginV2AgentNotifierApi(topics.AGENT)
        self.agent_notifiers[q_const.AGENT_TYPE_DHCP] = (
            dhcp_rpc_agent_api.DhcpAgentNotifyAPI())
        self.agent_notifiers[q_const.AGENT_TYPE_L3] = (
            l3_rpc_agent_api.L3AgentNotify)

        # NOTE: callback_sg is referred to from the sg unit test.
        self.callback_sg = SecurityGroupServerRpcCallback()
        callbacks = [
            NECPluginV2RPCCallbacks(self),
            DhcpRpcCallback(),
            L3RpcCallback(), self.callback_sg,
            agents_db.AgentExtRpcCallback()
        ]
        self.dispatcher = q_rpc.PluginRpcDispatcher(callbacks)
        self.conn.create_consumer(self.topic, self.dispatcher, fanout=False)
        # Consume from all consumers in a thread
        self.conn.consume_in_thread()
예제 #29
0
 def _create_metadata_access_network(self, context, router_id):
     # This will still ensure atomicity on Neutron DB
     with context.session.begin(subtransactions=True):
         # Add network
         # Network name is likely to be truncated on NVP
         net_data = {'name': 'meta-%s' % router_id,
                     'tenant_id': '',  # intentionally not set
                     'admin_state_up': True,
                     'port_security_enabled': False,
                     'shared': False,
                     'status': constants.NET_STATUS_ACTIVE}
         meta_net = self.create_network(context,
                                        {'network': net_data})
         # Add subnet
         subnet_data = {'network_id': meta_net['id'],
                        'tenant_id': '',  # intentionally not set
                        'name': 'meta-%s' % router_id,
                        'ip_version': 4,
                        'shared': False,
                        'cidr': METADATA_SUBNET_CIDR,
                        'enable_dhcp': True,
                        # Ensure default allocation pool is generated
                        'allocation_pools': attributes.ATTR_NOT_SPECIFIED,
                        'gateway_ip': METADATA_GATEWAY_IP,
                        'dns_nameservers': [],
                        'host_routes': []}
         meta_sub = self.create_subnet(context,
                                       {'subnet': subnet_data})
         self.add_router_interface(context, router_id,
                                   {'subnet_id': meta_sub['id']})
         if cfg.CONF.dhcp_agent_notification:
             # We need to send a notification to the dhcp agent in
             # order to start the metadata agent proxy
             dhcp_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
             dhcp_notifier.notify(context, {'network': meta_net},
                                  'network.create.end')
예제 #30
0
파일: rpc.py 프로젝트: cernops/neutron
def _notify_rpc_agent(context, payload, event):
    if cfg.CONF.dhcp_agent_notification:
        dhcp_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
        dhcp_notifier.notify(context, payload, event)