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
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
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'))
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)
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'))
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 )
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)
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))
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)
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) )
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)
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))
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) )
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)
def _sendMonitorsList(self): mlist = srvdata.getListOfMonitors() strlist = '\n'.join(mlist) msg = helper.getOkMessage('Here goes the list', strlist) self.sock.sendall(msg)
def _sendMonitorsList(self): mlist = srvdata.getListOfMonitors() strlist = '\n'.join(mlist) msg = helper.getOkMessage('Here goes the list', strlist) self.sock.sendall( msg )