def _register_agent_states(self, lbaas_agents=False): """Register two L3 agents and two DHCP agents.""" l3_hosta = { 'binary': 'neutron-l3-agent', 'host': L3_HOSTA, 'topic': topics.L3_AGENT, 'configurations': {'use_namespaces': True, 'router_id': None, 'handle_internal_only_routers': True, 'gateway_external_network_id': None, 'interface_driver': 'interface_driver', }, 'agent_type': constants.AGENT_TYPE_L3} l3_hostb = copy.deepcopy(l3_hosta) l3_hostb['host'] = L3_HOSTB dhcp_hosta = { 'binary': 'neutron-dhcp-agent', 'host': DHCP_HOSTA, 'topic': 'DHCP_AGENT', 'configurations': {'dhcp_driver': 'dhcp_driver', 'use_namespaces': True, }, 'agent_type': constants.AGENT_TYPE_DHCP} dhcp_hostc = copy.deepcopy(dhcp_hosta) dhcp_hostc['host'] = DHCP_HOSTC lbaas_hosta = { 'binary': 'neutron-loadbalancer-agent', 'host': LBAAS_HOSTA, 'topic': 'LOADBALANCER_AGENT', 'configurations': {'device_drivers': ['haproxy_ns']}, 'agent_type': constants.AGENT_TYPE_LOADBALANCER} lbaas_hostb = copy.deepcopy(lbaas_hosta) lbaas_hostb['host'] = LBAAS_HOSTB callback = agents_db.AgentExtRpcCallback() callback.report_state(self.adminContext, agent_state={'agent_state': l3_hosta}, time=timeutils.strtime()) callback.report_state(self.adminContext, agent_state={'agent_state': l3_hostb}, time=timeutils.strtime()) callback.report_state(self.adminContext, agent_state={'agent_state': dhcp_hosta}, time=timeutils.strtime()) callback.report_state(self.adminContext, agent_state={'agent_state': dhcp_hostc}, time=timeutils.strtime()) res = [l3_hosta, l3_hostb, dhcp_hosta, dhcp_hostc] if lbaas_agents: callback.report_state(self.adminContext, agent_state={'agent_state': lbaas_hosta}, time=timeutils.strtime()) callback.report_state(self.adminContext, agent_state={'agent_state': lbaas_hostb}, time=timeutils.strtime()) res += [lbaas_hosta, lbaas_hostb] return res
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()
def test_scheduler_equal_distribution(self): cfg.CONF.set_override('dhcp_agents_per_network', 1) self._save_networks(['1111', '2222', '3333']) agents = self._get_agents(['host-c', 'host-d']) self._save_agents(agents) callback = agents_db.AgentExtRpcCallback() callback.report_state(self.ctx, agent_state={'agent_state': self.hostc}, time=timeutils.strtime()) callback.report_state(self.ctx, agent_state={'agent_state': self.hostd}, time=timeutils.strtime()) self.plugin.network_scheduler.schedule(self.plugin, self.ctx, {'id': '1111'}) agent1 = self.plugin.get_dhcp_agents_hosting_networks(self.ctx, ['1111']) self.hostd['configurations']['networks'] = 2 callback.report_state(self.ctx, agent_state={'agent_state': self.hostd}, time=timeutils.strtime()) self.plugin.network_scheduler.schedule(self.plugin, self.ctx, {'id': '2222'}) agent2 = self.plugin.get_dhcp_agents_hosting_networks(self.ctx, ['2222']) self.hostc['configurations']['networks'] = 4 callback.report_state(self.ctx, agent_state={'agent_state': self.hostc}, time=timeutils.strtime()) self.plugin.network_scheduler.schedule(self.plugin, self.ctx, {'id': '3333'}) agent3 = self.plugin.get_dhcp_agents_hosting_networks(self.ctx, ['3333']) self.assertEqual('host-c', agent1[0]['host']) self.assertEqual('host-c', agent2[0]['host']) self.assertEqual('host-d', agent3[0]['host'])
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()
def __init__(self, plugin=None, driver=None): """Driver initialization.""" if not plugin or not driver: LOG.error('Required LBaaS Driver and Core Driver Missing') sys.exit(1) self.plugin = plugin self.conn = None self.loadbalancer = LoadBalancerManager(self) self.listener = ListenerManager(self) self.pool = PoolManager(self) self.member = MemberManager(self) self.healthmonitor = HealthMonitorManager(self) self.l7policy = L7PolicyManager(self) self.l7rule = L7RuleManager(self) # what scheduler to use for pool selection self.scheduler = importutils.import_object( cfg.CONF.loadbalancer_scheduler_driver) self.agent_rpc = agent_rpc.LBaaSv2AgentRPC(self) self.agent_endpoints = [ plugin_rpc.ArrayLoadBalancerCallbacks(driver), agents_db.AgentExtRpcCallback(self.plugin.db) ] self.plugin.agent_notifiers.update( {lb_const.AGENT_TYPE_LOADBALANCER: self.agent_rpc}) self.start_rpc_listeners()
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())
def _register_agent_states(self, lbaas_agents=False): res = super(LBaaSAgentSchedulerTestCase, self)._register_agent_states(lbaas_agents=lbaas_agents) if lbaas_agents: lbaas_hosta = { 'binary': 'neutron-loadbalancer-agent', 'host': test_agent.LBAAS_HOSTA, 'topic': 'LOADBALANCER_AGENT', 'configurations': { 'device_drivers': [plugin_driver.HaproxyOnHostPluginDriver.device_driver] }, 'agent_type': lb_const.AGENT_TYPE_LOADBALANCERV2 } lbaas_hostb = copy.deepcopy(lbaas_hosta) lbaas_hostb['host'] = test_agent.LBAAS_HOSTB callback = agents_db.AgentExtRpcCallback() callback.report_state(self.adminContext, agent_state={'agent_state': lbaas_hosta}, time=datetime.utcnow().isoformat()) callback.report_state(self.adminContext, agent_state={'agent_state': lbaas_hostb}, time=datetime.utcnow().isoformat()) res += [lbaas_hosta, lbaas_hostb] return res
def create_rpc_dispatcher(self): '''Get the rpc dispatcher for this manager. If a manager would like to set an rpc API version, or support more than one class as the target of rpc messages, override this method. ''' return q_rpc.PluginRpcDispatcher( [self, agents_db.AgentExtRpcCallback()])
def _setup_rpc(self): self.endpoints = [l3_rpc.L3RpcCallback(), agents_db.AgentExtRpcCallback(), metadata_rpc.MetadataRpcCallback()] if cfg.CONF.df.use_centralized_ipv6_DHCP: self.endpoints.append(dhcp_rpc.DhcpRpcCallback())
def __init__(self, plugin): super(AgentDriverBase, self).__init__(plugin) if not self.device_driver: raise DriverNotSpecified() self.load_balancer = LoadBalancerManager(self) self.listener = ListenerManager(self) self.pool = PoolManager(self) self.member = MemberManager(self) self.health_monitor = HealthMonitorManager(self) self.agent_rpc = LoadBalancerAgentApi(lb_const.LOADBALANCER_AGENTV2) self.agent_endpoints = [ agent_callbacks.LoadBalancerCallbacks(self.plugin), agents_db.AgentExtRpcCallback(self.plugin.db) ] self.conn = None # Setting this on the db because the plugin no longer inherts from # database classes, the db does. self.plugin.db.agent_notifiers.update( {lb_const.AGENT_TYPE_LOADBALANCERV2: self.agent_rpc}) lb_sched_driver = provconf.get_provider_driver_class( cfg.CONF.loadbalancer_scheduler_driver, LB_SCHEDULERS) self.loadbalancer_scheduler = importutils.import_object( lb_sched_driver)
def _register_cfg_agent(self): callback = agents_db.AgentExtRpcCallback() callback.report_state(self.adminContext, agent_state={'agent_state': FIRST_CFG_AGENT}, time=timeutils.strtime()) agent_db = self.core_plugin.get_agents_db(self.adminContext, filters={'host': [HOST]}) self.agent_id1 = agent_db[0].id
def _register_l3_agent(self, hostname): agent = copy.deepcopy(L3_AGENT_TEMPLATE) agent['host'] = hostname callback = agents_db.AgentExtRpcCallback() callback.report_state(self.adminContext, agent_state={'agent_state': agent}, time=timeutils.utcnow().isoformat()) self._l3_agents[hostname] = FakeAgent(**agent)
def start_rpc_listeners(self): self.endpoints = [ rpc.RpcCallbacks(self.notifier, self.type_manager), agents_db.AgentExtRpcCallback() ] self.topic = topics.PLUGIN self.conn = n_rpc.create_connection(new=True) self.conn.create_consumer(self.topic, self.endpoints, fanout=False) return self.conn.consume_in_threads()
def __init__(self): self.db = wan_qos_db.WanTcDb() rpc_callback = importutils.import_object( 'wan_qos.services.plugin.PluginRpcCallback', self) endpoints = ([rpc_callback, agents_db.AgentExtRpcCallback()]) self.agent_rpc = api.TcAgentApi(cfg.CONF.host) self.conn = n_rpc.create_connection() self.conn.create_consumer(topics.TC_PLUGIN, endpoints, fanout=False) self.conn.consume_in_threads()
def _setup_rpc_dhcp_metadata(self, notifier=None): self.topic = topics.PLUGIN self.conn = n_rpc.Connection() self.endpoints = [SynchronizedDhcpRpcCallback(), agents_db.AgentExtRpcCallback(), metadata_rpc.MetadataRpcCallback()] self.conn.create_consumer(self.topic, self.endpoints, fanout=False) self.conn.create_consumer(topics.REPORTS, [agents_db.AgentExtRpcCallback()], 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'])
def setUp(self): super(TestAgentExtRpcCallback, self).setUp() self.callback = agents_db.AgentExtRpcCallback(self.plugin) self.callback.server_versions_rpc = mock.Mock() self.versions_rpc = self.callback.server_versions_rpc self.callback.START_TIME = datetime.datetime(datetime.MINYEAR, 1, 1) self.update_versions = mock.patch( 'neutron.api.rpc.callbacks.version_manager.' 'update_versions').start() self.agent_state = {'agent_state': dict(AGENT_STATUS)}
def start_rpc_listeners(self): self._setup_rpc() self.conn = n_rpc.create_connection(new=True) self.conn.create_consumer(topics.PLUGIN, self.endpoints, fanout=False) self.conn.create_consumer(topics.L3PLUGIN, self.endpoints, fanout=False) self.conn.create_consumer(topics.REPORTS, [agents_db.AgentExtRpcCallback()], fanout=False) return self.conn.consume_in_threads()
def create_rpc_dispatcher(self): """Get the rpc dispatcher for this manager. This a basic implementation that will call the plugin like get_ports and handle basic events If a manager would like to set an rpc API version, or support more than one class as the target of rpc messages, override this method. """ return n_rpc.PluginRpcDispatcher([self, agents_db.AgentExtRpcCallback()])
def create_rpc_listener(self): topic = constants.TOPIC_LBAASV2_BIGIQ_DRIVER self.conn = neutron_rpc.create_connection() self.conn.create_consumer( topic, [self, agents_db.AgentExtRpcCallback(self.driver.plugin.db)], fanout=False) self.conn.consume_in_threads()
def create_rpc_listener(self): topic = constants.TOPIC_PROCESS_ON_HOST_V2 if self.driver.env: topic = topic + "_" + self.driver.env self.conn = neutron_rpc.create_connection(new=True) self.conn.create_consumer( topic, [self, agents_db.AgentExtRpcCallback(self.driver.plugin.db)], fanout=False) self.conn.consume_in_threads()
def start_rpc_listeners(self): self.endpoints = [rpc.RpcCallbacks(), securitygroups_rpc.SecurityGroupServerRpcCallback(), dvr_rpc.DVRServerRpcCallback(), dhcp_rpc.DhcpRpcCallback(), agents_db.AgentExtRpcCallback()] self.topic = topics.PLUGIN self.conn = n_rpc.create_connection(new=True) self.conn.create_consumer(self.topic, self.endpoints, fanout=False) return self.conn.consume_in_threads()
def setup_rpc(self): # RPC support self.topic = topics.PLUGIN self.conn = n_rpc.create_connection(new=True) self.endpoints = [ dhcp_rpc.DhcpRpcCallback(), agents_db.AgentExtRpcCallback() ] self.conn.create_consumer(self.topic, self.endpoints, fanout=False) # Consume from all consumers in a thread self.conn.consume_in_threads()
def create_rpc_conn(self): self.endpoints = [ NFPIPsecVPNDriverCallBack(self), agents_db.AgentExtRpcCallback(VPNPluginExt())] self.conn = n_rpc.create_connection(new=True) self.conn.create_consumer( topics.VPN_NFP_PLUGIN_TOPIC, self.endpoints, fanout=False) self.conn.consume_in_threads() self.agent_rpc = NFPIPsecVpnAgentApi( topics.VPN_NFP_CONFIGAGENT_TOPIC, BASE_VPN_VERSION, self)
def _register_ml2_agents(self): callback = agents_db.AgentExtRpcCallback() callback.report_state(self.adminContext, agent_state={'agent_state': L2_AGENT}, time=timeutils.strtime()) callback.report_state(self.adminContext, agent_state={'agent_state': L2_AGENT_2}, time=timeutils.strtime()) callback.report_state(self.adminContext, agent_state={'agent_state': L2_AGENT_3}, time=timeutils.strtime())
def setup_rpc(self): # RPC support self.topic = topics.PLUGIN self.conn = n_rpc.create_connection(new=True) self.notifier = AgentNotifierApi(topics.AGENT) self.endpoints = [SdnveRpcCallbacks(self.notifier), agents_db.AgentExtRpcCallback()] self.conn.create_consumer(self.topic, self.endpoints, fanout=False) # Consume from all consumers in threads self.conn.consume_in_threads()
def __init__(self): super(AgentRpcMGMTDriver, self).__init__() self.topic = n_topics.SVMDEVICE_DRIVER_TOPIC self.notifier = ServiceVMAgentNotifyApi(topics.SERVICEVM) self.endpoints = [ ServiceVMPluginRpcCallbacks(self, self.notifier), agents_db.AgentExtRpcCallback() ] self.conn = n_rpc.create_connection(new=True) self.conn.create_consumer(self.topic, self.endpoints, fanout=False) self.conn.consume_in_threads()
def _register_cfg_agent_states(self, host_a_active=True, host_b_active=False, host_c_active=False): """Register zero, one, two, or three L3 config agents.""" l3_cfg_host_a = { 'binary': 'neutron-cisco-cfg-agent', 'host': L3_CFG_HOST_A, 'topic': cisco_constants.CFG_AGENT, 'configurations': { 'service_agents': [cisco_constants.AGENT_TYPE_L3_CFG], 'total routers': 0, 'total ex_gw_ports': 0, 'total interfaces': 0, 'total floating_ips': 0, 'hosting_devices': 0, 'non_responding_hosting_devices': {} }, 'local_time': str(timeutils.utcnow()), 'agent_type': cisco_constants.AGENT_TYPE_CFG } agent_callback = agents_db.AgentExtRpcCallback() dev_mgr_callback = devices_cfgagent_rpc_cb.DeviceMgrCfgRpcCallback( manager.NeutronManager.get_service_plugins()[ cisco_constants.DEVICE_MANAGER]) if host_a_active is True: agent_callback.report_state( self.adminContext, agent_state={'agent_state': l3_cfg_host_a}, time=datetime.utcnow().strftime(ISO8601_TIME_FORMAT)) dev_mgr_callback.register_for_duty(self.adminContext, L3_CFG_HOST_A) if host_b_active is True: l3_cfg_host_b = copy.deepcopy(l3_cfg_host_a) l3_cfg_host_b['host'] = L3_CFG_HOST_B l3_cfg_host_b['local_time'] = str(timeutils.utcnow()), agent_callback.report_state( self.adminContext, agent_state={'agent_state': l3_cfg_host_b}, time=datetime.utcnow().strftime(ISO8601_TIME_FORMAT)) dev_mgr_callback.register_for_duty(self.adminContext, L3_CFG_HOST_B) if host_c_active is True: l3_cfg_host_c = copy.deepcopy(l3_cfg_host_a) l3_cfg_host_c['host'] = L3_CFG_HOST_C l3_cfg_host_c['local_time'] = str(timeutils.utcnow()), agent_callback.report_state( self.adminContext, agent_state={'agent_state': l3_cfg_host_c}, time=datetime.utcnow().strftime(ISO8601_TIME_FORMAT)) dev_mgr_callback.register_for_duty(self.adminContext, L3_CFG_HOST_B)
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.notifier = agent_notifier_api.AgentNotifierApi( topics.AGENT) self.endpoints = [rpc_callbacks.HyperVRpcCallbacks(self.notifier), 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()
def __init__(self, service_plugin): super(GRETunnelDriver, self).__init__(service_plugin) self.endpoints = [ GRETunnelDriverCallBack(self), agents_db.AgentExtRpcCallback(self.service_plugin) ] self.conn = n_rpc.create_connection(new=True) self.conn.create_consumer(topics.GRE_DRIVER_TOPIC, self.endpoints, fanout=False) self.conn.consume_in_threads() self.agent_rpc = GRETunnelAgentApi(topics.GRE_AGENT_TOPIC, BASE_GRE_VERSION, self)
def _register_l3_agent(self, host): agent = { 'binary': 'neutron-l3-agent', 'host': host, 'topic': topics.L3_AGENT, 'configurations': {}, 'agent_type': n_constants.AGENT_TYPE_L3, 'start_flag': True } callback = agents_db.AgentExtRpcCallback() callback.report_state(self.adminContext, agent_state={'agent_state': agent}, time=timeutils.strtime())