Example #1
0
def _updateFromSelf(sock,
                    instruction,
                    awakener,
                    sinfo,
                    client_id,
                    connection_type=''):
    try:
        if helper.isCmdUpdate(instruction):
            if not connection_type:
                sock.sendall(helper.getOkMessage())
            awakener.set()
            logging.debug('Requested update sent')

        elif not connection_type and helper.isCmdGet(instruction):

            sock.sendall(
                helper.getOkMessage(
                    '', '%c %s %c %s %c' % (gdata.SOH, client_id, gdata.ETX,
                                            buildXML(sinfo), gdata.ETX)))

            logging.debug('Requested get sent')

        else:
            sock.send(helper.getUnknownCmdError('Unknown command'))
            logging.debug('Request error sent')

    except socket.error, e:
        pass
Example #2
0
File: cli.py Project: jponf/dremo
def _updateFromSelf(sock, instruction, awakener, sinfo, client_id, connection_type=''):
    try:
        if helper.isCmdUpdate(instruction):
                if not connection_type:
                    sock.sendall(helper.getOkMessage())
                awakener.set()
                logging.debug('Requested update sent')

        elif not connection_type and helper.isCmdGet(instruction):
        	  
            sock.sendall(helper.getOkMessage('', '%c %s %c %s %c' % (gdata.SOH, client_id, 
            									gdata.ETX, buildXML(sinfo), gdata.ETX)))

            logging.debug('Requested get sent')

        else:
            sock.send(helper.getUnknownCmdError('Unknown command'))
            logging.debug('Request error sent')

    except socket.error, e:
        pass
Example #3
0
    def _sendUpdateAll(self):
        logging.debug("Sending update to the mulsticast group %s:%d" %
                      (self.mg_ip, self.mg_port))

        msg = "%s\n" % gdata.CMD_UPDATE

        snt = self.m_sock.sendto(msg, (self.mg_ip, self.mg_port))

        if snt == len(msg):
            self.sock.sendall(helper.getOkMessage('Update all sent'))
        else:
            self.sock.sendall(
                helper.getGenericError('Error sending to Multicast group'))
Example #4
0
    def _sendGetAll(self):
        mlist = srvdata.getAllMonitorsData()
        xmlbuilder = common.SysInfoXMLBuilder()

        data = []
        for sinfodao, ip, port in mlist:
            xmlbuilder.setXMLData(sinfodao)
            data.append("IP: %s\nPORT: %s\n%s" %
                        (ip, port, xmlbuilder.getAsString()))

        strdata = '\n'.join(data)
        msg = helper.getOkMessage('Here goes the data', strdata)
        self.sock.sendall(msg)
Example #5
0
    def _sendUpdateAll(self):
        logging.debug("Sending update to the mulsticast group %s:%d" 
                        % (self.mg_ip, self.mg_port))

        msg = "%s\n" % gdata.CMD_UPDATE

        snt = self.m_sock.sendto(msg, (self.mg_ip, self.mg_port) )

        if snt == len(msg):
            self.sock.sendall( helper.getOkMessage('Update all sent') )
        else:
            self.sock.sendall( helper.getGenericError(
                                'Error sending to Multicast group'))
Example #6
0
    def _sendGetAll(self):
        mlist = srvdata.getAllMonitorsData()
        xmlbuilder = common.SysInfoXMLBuilder()

        data = []
        for sinfodao, ip, port in mlist:
            xmlbuilder.setXMLData(sinfodao)
            data.append("IP: %s\nPORT: %s\n%s"
                        % (ip, port, xmlbuilder.getAsString()) )

        strdata = '\n'.join(data)
        msg = helper.getOkMessage('Here goes the data', strdata)
        self.sock.sendall( msg )
Example #7
0
    def _sendUpdateToMonitor(self, ip, port):
        # Send Update to monitor and get response
        s = socket.create_connection((ip, port), self.timeout)
        s.sendall("%s\n" % gdata.CMD_UPDATE)

        ret = common.recvEnd(s, '\n').strip()
        code, sep, desc = ret.partition(' ')

        # Send result to client
        msg = None
        if code == gdata.K_OK:
            msg = helper.getOkMessage(desc)
        else:
            msg = helper.getGenericError("Received error: %s" % ret)

        self.sock.sendall(msg)
Example #8
0
    def _handleGet(self, mid):

        if srvdata.existsMonitorData(mid):
            sinfodao, ip, port = srvdata.getMonitorData(mid)
            xmlbuilder = common.SysInfoXMLBuilder()
            xmlbuilder.setXMLData(sinfodao)

            data = "IP: %s\nPORT: %s\n%s" % (ip, port,
                                             xmlbuilder.getAsString())

            msg = helper.getOkMessage('Data of %s' % mid, data)
            self.sock.sendall(msg)
        else:
            self.sock.sendall(
                helper.getMonitorNotFoundError("Monitor %s is not registered" %
                                               mid))
Example #9
0
    def _sendUpdateToMonitor(self, ip, port):
        # Send Update to monitor and get response
        s = socket.create_connection( (ip, port), self.timeout )
        s.sendall("%s\n" % gdata.CMD_UPDATE)

        ret = common.recvEnd(s, '\n').strip()
        code, sep, desc = ret.partition(' ')

        # Send result to client
        msg = None
        if code == gdata.K_OK:
            msg = helper.getOkMessage(desc)
        else:
            msg = helper.getGenericError("Received error: %s" % ret)

        self.sock.sendall(msg)
Example #10
0
    def _handleGet(self, mid):

        if srvdata.existsMonitorData(mid):
            sinfodao, ip, port = srvdata.getMonitorData(mid)
            xmlbuilder = common.SysInfoXMLBuilder()
            xmlbuilder.setXMLData(sinfodao)

            data = "IP: %s\nPORT: %s\n%s" % (ip, port, xmlbuilder.getAsString())

            msg = helper.getOkMessage('Data of %s' % mid, data)
            self.sock.sendall( msg )
        else:
            self.sock.sendall( 
                helper.getMonitorNotFoundError(
                    "Monitor %s is not registered" % mid)
                )
Example #11
0
    def _newMonitor(self, port):

        iport = int(port)
        if iport < gdata.SOCK_MIN_PORT or iport > gdata.SOCK_MAX_PORT:
            raise ValueError("Port value (%d) out of range [%d-%d]" %
                             (iport, gdata.SOCK_MIN_PORT, gdata.SOCK_MAX_PORT))

        mid = srvdata.initializeNewMonitorData(self.addr[0], port)

        opt = gdata.getCommandLineOptions()
        msg = helper.getOkMessage(
            "",
            "%s %s %d" % (mid, opt.multicast_group, opt.multicast_group_port))

        self.sock.sendall(msg)

        self._updateMonitor(mid)
Example #12
0
    def _updateMonitor(self, mid):

        if srvdata.existsMonitorData(mid):
            srvdata.keepAliveMonitor(mid)

            data = common.recvEnd(self.sock, gdata.ETX).strip()
            #logging.debug("%s:%d Data:\n%s" % (self.addr[0], self.addr[1], data))

            infoparser = common.SysInfoXMLParser()
            infoparser.parseXML(data)
            infodao = infoparser.getSysInfoData()
            srvdata.updateMonitorData(mid, infodao)
            self.sock.sendall(helper.getOkMessage("Update successful"))
            logging.debug("Update %s successful" % mid)
        else:
            self.sock.sendall(
                helper.getMonitorNotFoundError(
                    "There isn't any monitor with id: %s" % mid))
Example #13
0
    def _updateMonitor(self, mid):
        
        if srvdata.existsMonitorData(mid):
            srvdata.keepAliveMonitor(mid)

            data = common.recvEnd(self.sock, gdata.ETX).strip()
            #logging.debug("%s:%d Data:\n%s" % (self.addr[0], self.addr[1], data))

            infoparser = common.SysInfoXMLParser()
            infoparser.parseXML(data)
            infodao = infoparser.getSysInfoData()
            srvdata.updateMonitorData(mid, infodao)
            self.sock.sendall( helper.getOkMessage("Update successful") )                   
            logging.debug("Update %s successful" % mid)
        else:
            self.sock.sendall( 
                helper.getMonitorNotFoundError(
                    "There isn't any monitor with id: %s" % mid)
                )
Example #14
0
    def _newMonitor(self, port):
        
        iport = int(port)
        if iport < gdata.SOCK_MIN_PORT or iport > gdata.SOCK_MAX_PORT:
            raise ValueError("Port value (%d) out of range [%d-%d]" 
                % (iport, gdata.SOCK_MIN_PORT, gdata.SOCK_MAX_PORT))

        mid = srvdata.initializeNewMonitorData(self.addr[0], port)

        opt = gdata.getCommandLineOptions()
        msg = helper.getOkMessage(
                "",
                "%s %s %d" 
                % (mid, opt.multicast_group, opt.multicast_group_port)
            )

        self.sock.sendall(msg)

        self._updateMonitor(mid)
Example #15
0
 def _sendMonitorsList(self):
     mlist = srvdata.getListOfMonitors()
     strlist = '\n'.join(mlist)
     msg = helper.getOkMessage('Here goes the list', strlist)
     self.sock.sendall(msg)
Example #16
0
 def _sendMonitorsList(self):
     mlist = srvdata.getListOfMonitors()
     strlist = '\n'.join(mlist)
     msg = helper.getOkMessage('Here goes the list', strlist)
     self.sock.sendall( msg )