Esempio n. 1
0
 def doPyHouseLogin(self, p_client, p_pyhouse_obj):
     """Login to PyHouse via MQTT
     """
     self.m_client = p_client
     l_name = p_pyhouse_obj.Computer.Name
     try:
         l_node = copy.deepcopy(p_pyhouse_obj.Computer.Nodes[l_name])
     except (KeyError, TypeError):
         l_node = NodeData()
     l_node.NodeInterfaces = {}
Esempio n. 2
0
 def doPyHouseLogin(self, p_client, p_pyhouse_obj):
     """Login to PyHouse via MQTT
     """
     self.m_client = p_client
     try:
         l_node = copy.deepcopy(p_pyhouse_obj.Computer.Nodes[p_pyhouse_obj.Computer.Name])
     except KeyError:
         l_node = NodeData()
     l_node.NodeInterfaces = {}
     self.MqttPublish('computer/startup', l_node)
Esempio n. 3
0
 def send_who_is_there(p_pyhouse_obj):
     l_topic = "computer/node/whoisthere"
     l_uuid = p_pyhouse_obj.Computer.UUID
     try:
         l_node = p_pyhouse_obj.Computer.Nodes[l_uuid]
     except KeyError as e_err:
         LOG.error('No such node {}'.format(e_err))
         l_node = NodeData()
     l_node.NodeInterfaces = None
     p_pyhouse_obj.APIs.Computer.MqttAPI.MqttPublish(
         l_topic, l_node)  # /computer/node/whoisthere
     _l_runID = p_pyhouse_obj.Twisted.Reactor.callLater(
         REPEAT_DELAY, Util.send_who_is_there, p_pyhouse_obj)
Esempio n. 4
0
 def _read_one_node_xml(p_node_xml):
     """
     Read the existing XML file (if it exists) and get the node info.
     """
     l_node_obj = NodeData()
     XmlConfigTools.read_base_object_xml(l_node_obj, p_node_xml)
     l_node_obj.ConnectionAddr_IPv4 = PutGetXML.get_text_from_xml(p_node_xml, 'ConnectionAddressV4')
     l_node_obj.ConnectionAddr_IPv6 = PutGetXML.get_text_from_xml(p_node_xml, 'ConnectionAddressV6')
     l_node_obj.NodeRole = PutGetXML.get_int_from_xml(p_node_xml, 'NodeRole')
     try:
         l_node_obj.NodeInterfaces = Xml._read_interfaces_xml(p_node_xml.find('InterfaceSection'))
     except AttributeError as e_err:
         LOG.error('ERROR OneNodeRead error {}'.format(e_err))
     return l_node_obj
Esempio n. 5
0
    def send_who_is_there(p_pyhouse_obj):
        l_topic = TOPIC + "whoisthere"
        l_uuid = p_pyhouse_obj.Computer.UUID
        try:
            l_node = p_pyhouse_obj.Computer.Nodes[l_uuid]
        except KeyError as e_err:
            LOG.error('No such node {}'.format(e_err))
            l_node = NodeData()
        l_node.NodeInterfaces = None
        p_pyhouse_obj.APIs.Computer.MqttAPI.MqttPublish(l_topic, l_node)  # /computer/node/whoisthere

        l_topic = 'login/initial'
        l_message = {}
        p_pyhouse_obj.APIs.Computer.MqttAPI.MqttPublish(l_topic, l_message)  # /login/initial

        _l_runID = p_pyhouse_obj.Twisted.Reactor.callLater(REPEAT_DELAY, Util.send_who_is_there, p_pyhouse_obj)
Esempio n. 6
0
 def saveNodeData(self, p_json):
     """A new/changed/deleted node is returned.  Process it and update the internal data.
     """
     l_json = json_tools.decode_json_unicode(p_json)
     l_ix = int(l_json['Key'])
     l_delete = l_json['Delete']
     if l_delete:
         try:
             del self.m_pyhouse_obj.Computer.Nodes[l_ix]
         except AttributeError:
             LOG.error("web_nodes - Failed to delete - JSON: {}".format(l_json))
         return
     try:
         l_obj = self.m_pyhouse_obj.Computer.Nodes[l_ix]
     except KeyError:
         l_obj = NodeData()
     l_obj.Name = l_json['Name']
     l_obj.Active = l_json['Active']
     l_obj.Key = l_ix
     l_obj.Comment = l_json['Comment']
     self.m_pyhouse_obj.Computer.Nodes[l_ix] = l_obj
Esempio n. 7
0
 def _get_node_base(p_pyhouse_obj):
     l_node = NodeData()
     l_node.Name = platform.node()
     l_node.Key = 0
     l_node.Active = True
     l_node.UUID = p_pyhouse_obj.Computer.UUID
     return l_node
Esempio n. 8
0
    def _read_one_node_xml(p_node_xml):
        """
        Use the passed in xml to create a node entry.

        @param p_node_xml: is the element in the Xml config file that describes a node.
        @return: a node object filled in.
        """
        l_node_obj = NodeData()
        XmlConfigTools.read_base_UUID_object_xml(l_node_obj, p_node_xml)
        l_node_obj.ConnectionAddr_IPv4 = PutGetXML.get_text_from_xml(p_node_xml, 'ConnectionAddressV4')
        l_node_obj.ConnectionAddr_IPv6 = PutGetXML.get_text_from_xml(p_node_xml, 'ConnectionAddressV6')
        l_node_obj.NodeRole = PutGetXML.get_int_from_xml(p_node_xml, 'NodeRole')
        try:
            l_node_obj.LastUpdate = PutGetXML.get_date_time_from_xml(p_node_xml, 'LastUpdate')
        except AttributeError:
            l_node_obj.LastUpdate = datetime.datetime.now()
        try:
            l_node_obj.NodeInterfaces = Xml._read_interfaces_xml(p_node_xml.find('InterfaceSection'))
        except AttributeError as e_err:
            LOG.error('ERROR OneNodeRead error {}'.format(e_err))
        return l_node_obj
 def setUp(self):
     self.m_pyhouse_obj.Xml.XmlRoot = ET.fromstring(xml_data.XML_LONG)
     self.m_pyhouse_obj.Services = CoreServicesInformation()
     self.m_pyhouse_obj.Computer.Nodes[self.m_pyhouse_obj.Computer.Name] = NodeData()
     self.m_api = node_local.API()
Esempio n. 10
0
 def _get_node_info():
     l_node = NodeData()
     l_node.Name = platform.node()
     l_node.Key = 0
     l_node.Active = True
     return l_node
Esempio n. 11
0
 def _extract_node(self, p_message):
     l_node = NodeData()
     l_node.Name = self._get_field(p_message, 'Name')
     l_node.Key = l_node.Name
     l_node.Active = True
     l_node.Comment = ''
     l_node.ConnectionAddr_IPv4 = self._get_field(p_message, 'ConnectionAddr_IPv4')
     l_node.ConnectionAddr_IPv6 = self._get_field(p_message, 'ConnectionAddr_IPv6')
     l_node.ControllerCount = self._get_field(p_message, 'ControllerCount')
     l_node.ControllerTypes = self._get_field(p_message, 'ControllerTypes')
     l_node.NodeId = self._get_field(p_message, 'NodeId')
     l_node.NodeRole = self._get_field(p_message, 'NodeRole')
Esempio n. 12
0
 def test_06_AllInterfaces(self):
     l_node = NodeData()
     l_if, _l_v4, _l_v6 = Interfaces._get_all_interfaces()
     l_node.NodeInterfaces = l_if
Esempio n. 13
0
 def _extract_node(self, p_message):
     l_node = NodeData()
     l_node.Name = self._get_field(p_message, 'Name')
     l_node.Key = l_node.Name
     l_node.Active = True
     l_node.Comment = ''
     l_node.ConnectionAddr_IPv4 = self._get_field(p_message,
                                                  'ConnectionAddr_IPv4')
     l_node.ConnectionAddr_IPv6 = self._get_field(p_message,
                                                  'ConnectionAddr_IPv6')
     l_node.ControllerCount = self._get_field(p_message, 'ControllerCount')
     l_node.ControllerTypes = self._get_field(p_message, 'ControllerTypes')
     l_node.NodeId = self._get_field(p_message, 'NodeId')
     l_node.NodeRole = self._get_field(p_message, 'NodeRole')
Esempio n. 14
0
 def test_05_AllInterfaces(self):
     l_node = NodeData()
     l_if, _l_v4, _l_v6 = Interfaces._get_all_interfaces()
     l_node.NodeInterfaces = l_if
Esempio n. 15
0
 def setUp(self):
     SetupMixin.setUp(self, ET.fromstring(xml_data.XML_LONG))
     self.m_pyhouse_obj.Computer.Nodes = nodes_xml.Xml.read_all_nodes_xml(self.m_pyhouse_obj)
     self.m_node = NodeData()
     self.m_iface_api = Interfaces()
Esempio n. 16
0
 def add_node(p_pyhouse_obj, p_message_obj):
     """ Add node (or update if alreeady present).
     @param p_message_obj: is a decoded json message containing node information
     """
     l_nodes = p_pyhouse_obj.Computer.Nodes
     l_uuid = p_message_obj['UUID']
     l_name = p_message_obj['Name']
     l_now = datetime.datetime.now()
     if l_uuid in l_nodes:
         LOG.info('Node already present {} '.format(l_name))
         p_pyhouse_obj.Computer.Nodes[l_uuid].LastUpdate = l_now
     else:
         LOG.info('Node not present - Adding. {}  {}'.format(
             l_uuid, l_name))
         l_obj = NodeData()
         l_obj.Name = l_name
         l_obj.Key = l_uuid
         l_obj.Active = p_message_obj['Active']
         l_obj.Comment = p_message_obj['Comment']
         l_obj.ConnectionAddr_IPv4 = p_message_obj['ConnectionAddr_IPv4']
         l_obj.ConnectionAddr_IPv6 = p_message_obj['ConnectionAddr_IPv6']
         l_obj.ControllerCount = p_message_obj['ControllerCount']
         l_obj.ControllerTypes = p_message_obj['ControllerTypes']
         l_obj.NodeId = p_message_obj['NodeId']
         l_obj.NodeRole = p_message_obj['NodeRole']
         l_obj.LastUpdate = l_now
         l_obj.UUID = l_uuid
         p_pyhouse_obj.Computer.Nodes[l_uuid] = l_obj
     LOG.info('Contains {} Nodes'.format(len(p_pyhouse_obj.Computer.Nodes)))
Esempio n. 17
0
 def test_05_AllInterfaces(self):
     l_node = NodeData()
     l_node.NodeInterfaces = Interfaces._get_all_interfaces()
     print(PrettyFormatAny.form(l_node.NodeInterfaces, 'Node Interfaces'))
Esempio n. 18
0
 def initialize_node(self, p_addr_v4, p_addr_v6):
     l_node = NodeData()
     l_node.ConnectionAddr_IPv4 = p_addr_v4
     l_node.ConnectionAddr_IPv6 = p_addr_v6
     return l_node
Esempio n. 19
0
 def add_node(p_pyhouse_obj, p_message_obj):
     """ Add node (or update if alreeady present).
     @param p_message_obj: is a decoded json message containing node information
     """
     l_nodes = p_pyhouse_obj.Computer.Nodes
     l_uuid = p_message_obj['UUID']
     l_name = p_message_obj['Name']
     l_now = datetime.datetime.now()
     if l_uuid in l_nodes:
         LOG.info('Node already present {} '.format(l_name))
         p_pyhouse_obj.Computer.Nodes[l_uuid].LastUpdate = l_now
     else:
         LOG.info('Node not present - Adding. {}  {}'.format(l_uuid, l_name))
         l_obj = NodeData()
         l_obj.Name = l_name
         l_obj.Key = l_uuid
         l_obj.Active = p_message_obj['Active']
         l_obj.Comment = p_message_obj['Comment']
         l_obj.ConnectionAddr_IPv4 = p_message_obj['ConnectionAddr_IPv4']
         l_obj.ConnectionAddr_IPv6 = p_message_obj['ConnectionAddr_IPv6']
         l_obj.ControllerCount = p_message_obj['ControllerCount']
         l_obj.ControllerTypes = p_message_obj['ControllerTypes']
         l_obj.NodeId = p_message_obj['NodeId']
         l_obj.NodeRole = p_message_obj['NodeRole']
         l_obj.LastUpdate = l_now
         l_obj.UUID = l_uuid
         p_pyhouse_obj.Computer.Nodes[l_uuid] = l_obj
     LOG.info('Contains {} Nodes'.format(len(p_pyhouse_obj.Computer.Nodes)))
Esempio n. 20
0
 def setUp(self):
     SetupMixin.setUp(self, ET.fromstring(XML_LONG))
     self.m_interface_obj = NodeInterfaceData()
     self.m_node_obj = NodeData()