Example #1
0
 def add_server(self, port, protocol, endpoint, namespace=None):
     """
     Run a Server in a given namespace
     :param port: port on which server will listen
     :type port: int
     :param protocol: protocol on which server will listen
     :type protocol: str
     :param namespace: namespace name
     :type namespace: str
     :return: None
     """
     ns_list = [namespace] if namespace else self._ns_list
     for ns in ns_list:
         ns_mngr = NamespaceServerManager(ns) if not \
             self.mngrs_map.get(ns) else self.mngrs_map.get(ns)
         interfaces = self._ns_iterface_map.get(ns)
         interface = [
             iface for iface in interfaces
             for prefix in axon_config.NAMESPACE_INTERFACE_NAME_PREFIXES
             if prefix in iface.name
         ]
         if not interface:
             continue
         src = interface[0].address
         ns_mngr.start_server(protocol, port, src)
         self.connected_state.create_or_update_connected_state(
             src, [(protocol, port)])
         self.mngrs_map[ns] = ns_mngr
Example #2
0
 def start_servers(self, namespace=None):
     """
     Start a set of default server in given namespace
     :param namespace: namespace name
     :type namespace: str
     :return: None
     """
     ns_list = [namespace] if namespace else self._ns_list
     for ns in ns_list:
         interfaces = self._ns_iterface_map.get(ns)
         interface = [
             iface for iface in interfaces
             for prefix in axon_config.NAMESPACE_INTERFACE_NAME_PREFIXES
             if prefix in iface.name
         ]
         if not interface:
             continue
         src = interface[0].address
         servers = self.connected_state.get_servers(src)
         if not servers:
             continue
         ns_mngr = NamespaceServerManager(ns) if not \
             self.mngrs_map.get(ns) else self.mngrs_map.get(ns)
         for proto, port in servers:
             ns_mngr.start_server(proto, port, src)
         self.mngrs_map[ns] = ns_mngr
Example #3
0
 def start_servers(self, namespace=None):
     """
     Start a set of default server in given namespace
     :param namespace: namespace name
     :type namespace: str
     :return: None
     """
     ns_list = [namespace] if namespace else self._ns_list
     for ns in ns_list:
         interfaces = self._ns_iterface_map.get(ns)
         interfaces = [
             iface for iface in interfaces
             for prefix in axon_config.NAMESPACE_INTERFACE_NAME_PREFIXES
             if prefix in iface.name
         ]
         if not interfaces:
             continue
         _servers = []
         for iface in interfaces:
             if _is_valid_ip(iface.address):
                 src = iface.address
                 _servers.append(
                     (src, self.connected_state.get_servers(src)))
         if not _servers:
             continue
         for src, proto_port in _servers:
             if not proto_port:
                 continue
             ns_mngr = self.mngrs_map.get((ns, src),
                                          NamespaceServerManager(ns))
             for proto, port in proto_port:
                 ns_mngr.start_server(proto, port, src)
             self.mngrs_map[(ns, src)] = ns_mngr
Example #4
0
 def add_server(self, port, protocol, endpoint, namespace=None):
     """
     Run a Server in a given namespace
     :param port: port on which server will listen
     :type port: int
     :param protocol: protocol on which server will listen
     :type protocol: str
     :param namespace: namespace name
     :type namespace: str
     :return: None
     """
     ns_list = [namespace] if namespace else self._ns_list
     for ns in ns_list:
         interfaces = self._ns_iterface_map.get(ns)
         interfaces = [
             iface for iface in interfaces
             for prefix in axon_config.NAMESPACE_INTERFACE_NAME_PREFIXES
             if prefix in iface.name
         ]
         interfaces = [x for x in interfaces if x.address == endpoint]
         if not interfaces:
             continue
         src = endpoint
         ns_mngr = self.mngrs_map.get((ns, src), NamespaceServerManager(ns))
         ns_mngr.start_server(protocol, port, src)
         self.connected_state.create_or_update_connected_state(
             src, [(protocol, port)], [])
         self.mngrs_map[(ns, src)] = ns_mngr
         break
     else:
         self.log.error("Unable to add server since"
                        "there is no matching IP %s found in namespace %s" %
                        (endpoint, namespace))
Example #5
0
    def local_setup(self, mock_conn_state, mock_if_mngr, mock_ns_mngr):
        self.connected_state = mock_conn_state.return_value
        self.interface_manager = mock_if_mngr.return_value
        self.namespace_manager = mock_ns_mngr.return_value

        self.connected_state.get_connected_state.return_value =\
            CONNECTED_STATE
        self.connected_state.get_servers.return_value =\
            CONNECTED_STATE[0]['servers']

        self.interface_manager.get_interface_by_ip.side_effect =\
            'fake-interface'

        self.namespace_manager.get_all_namespaces.return_value = ['root']
        self.namespace_manager.get_namespace_interface_map = {
            'root': [INTERFACE]}

        from axon.traffic.agents import AxonNameSpaceServerAgent
        self.server_agent = AxonNameSpaceServerAgent(
            ns_list=['root'], ns_interface_map={'root': [INTERFACE]})
        self.server_agent.mngrs_map = {
            'root': NamespaceServerManager(namespace='root')}