Пример #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 = NodeInformation()
     l_node.NodeInterfaces = {}
Пример #2
0
 def test_06_AllInterfaces(self):
     l_node = NodeInformation()
     l_if, _l_v4, _l_v6 = Interfaces()._get_all_interfaces()
     l_node.NodeInterfaces = l_if
     # print(PrettyFormatAny.form(l_node.NodeInterfaces, 'B2-06-A - Node Interfaces'))
     self.assertEqual(len(l_node.NodeInterfaces), 4)
     # print(PrettyFormatAny.form(l_node.NodeInterfaces[0], 'B2-06-B - Node Interfaces'))
     self.assertEqual(l_node.NodeInterfaces[0].Name, 'lo')
     # print(PrettyFormatAny.form(l_node.NodeInterfaces[1], 'B2-06-C - Node Interfaces'))
     self.assertEqual(l_node.NodeInterfaces[1].Name, 'enp3s0')
     # print(PrettyFormatAny.form(l_node.NodeInterfaces[2], 'B2-06-D - Node Interfaces'))
     self.assertEqual(l_node.NodeInterfaces[2].Name, 'wlp2s0')
     # print(PrettyFormatAny.form(l_node.NodeInterfaces[3], 'B2-06-E - Node Interfaces'))
     self.assertEqual(l_node.NodeInterfaces[3].Name, 'docker0')
Пример #3
0
    def send_who_is_there(p_pyhouse_obj):
        l_topic = "computer/node/sync/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 = NodeInformation()
        l_node.NodeInterfaces = None
        p_pyhouse_obj._APIs.Core.MqttAPI.MqttPublish(l_topic, l_node)

        # l_topic = 'computer/login/initial'
        # l_message = {}
        # p_pyhouse_obj._APIs.Core.MqttAPI.MqttPublish(l_topic, l_message)

        p_pyhouse_obj._Twisted.Reactor.callLater(REPEAT_DELAY,
                                                 Util.send_who_is_there,
                                                 p_pyhouse_obj)
Пример #4
0
 def create_local_node(self):
     """ Create the local node info structure
     """
     l_node = NodeInformation()
     l_node.Name = self.m_pyhouse_obj.Computer.Name
     l_node.Key = 0
     # l_node.Active = True
     l_node.UUID = self.m_pyhouse_obj.Computer.UUID
     Interfaces().add_interfaces(l_node)
     Devices().find_devices(l_node)
     l_node.NodeRole = Util.find_node_role()
     l_node.LastUpdate = datetime.now()
     # l_topic = 'computer/local'
     # self.m_pyhouse_obj._APIs.Core.MqttAPI.MqttPublish(l_topic, l_node)
     return l_node
Пример #5
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 = NodeInformation()
     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
Пример #6
0
 def setUp(self):
     SetupMixin.setUp(self, ET.fromstring(XML_LONG))
     self.m_interface_obj = NodeInterfaceData()
     self.m_node_obj = NodeInformation()
Пример #7
0
 def setUp(self):
     self.m_pyhouse_obj._Config.XmlRoot = ET.fromstring(XML_LONG)
     self.m_pyhouse_obj.Services = CoreServicesInformation()
     self.m_pyhouse_obj.Computer.Nodes[
         self.m_pyhouse_obj.Computer.Name] = NodeInformation()
     self.m_api = node_local.API()
Пример #8
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 = NodeInformation()
         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
     l_list = ''
     for l_node in p_pyhouse_obj.Computer.Nodes:
         l_list += l_node + '\n\t'
     pass
     LOG.info('Contains {} Nodes - {}'.format(
         len(p_pyhouse_obj.Computer.Nodes), l_list))
Пример #9
0
 def setUp(self):
     SetupMixin.setUp(self, ET.fromstring(XML_LONG))
     self.m_pyhouse_obj.Computer.Nodes = nodes_xml.Xml.read_all_nodes_xml(self.m_pyhouse_obj)
     self.m_node = NodeInformation()
     self.m_iface_api = Interfaces()