コード例 #1
0
ファイル: consoledaemon.py プロジェクト: benroeder/HEN
    def __init__(self, configFilePath='/usr/local/hen/etc/configs/config'):
        Daemon.__init__(self)

        self.__version = "Console Daemon v0.2 (dumb)"
        self.__terminalServerConnections = {}
        self.__terminalServerSockets = []
        self.__configFilePath = configFilePath
        self.__configFile = ConfigParser.ConfigParser()
        self.__configFile.read(configFilePath)
        self.__henPhysicalTopology = self.__configFile.get('MAIN','PHYSICAL_TOPOLOGY')
        self.__henLogPath = self.__configFile.get('MAIN', 'LOG_PATH')
        self.__parser = HenParser(self.__henPhysicalTopology, \
                                  None, \
                                  None, \
                                  self.__henLogPath, \
                                  None,
                                  None,
                                  None, \
                                  None)

        self.__controlProtocol = None

        # Create instances for all terminal servers in the testbed
        self.__terminalServerNodes = {}
        for terminalServerNode in self.__parser.getNodes("serial", "all").values():
            self.__terminalServerNodes[terminalServerNode.getNodeID()] = terminalServerNode.getInstance()
        self.__computerNodes = self.__parser.getNodes("computer", "all")
                                
        self.__registerMethods()
コード例 #2
0
    def __init__(self,
                 configFilePath='/usr/local/hen/etc/configs/testbed.conf'):
        """\brief Initializes the class and the logger
        \param configFilePath (\c string) The path to the config file for the testbed. Default: /usr/local/hen/etc/configs/config
        """
        self.__configFile = ConfigParser.ConfigParser()
        self.__configFile.read(configFilePath)

        self.__henRoot = self.__configFile.get('DEFAULT', 'ROOT')
        self.__pythonBin = self.__configFile.get('MAIN', 'PYTHON_BIN')
        self.__henRoot = self.__configFile.get('MAIN', 'ROOT')
        self.__henBinPath = self.__configFile.get('MAIN', 'BIN_PATH')
        self.__henEtcPath = self.__configFile.get('MAIN', 'ETC_PATH')
        self.__henVarPath = self.__configFile.get('MAIN', 'VAR_PATH')
        self.__henExperimentalBaseAddress = self.__configFile.get(
            'MAIN', 'EXPERIMENTAL_BASE_ADDRESS')
        self.__henInfrastructureBaseAddress = self.__configFile.get(
            'MAIN', 'INFRASTRUCTURE_BASE_ADDRESS')
        self.__henExportPath = self.__configFile.get('MAIN', 'EXPORT_PATH')
        self.__henLogPath = self.__configFile.get('MAIN', 'LOG_PATH')
        self.__henPhysicalTopology = self.__configFile.get(
            'MAIN', 'PHYSICAL_TOPOLOGY')
        self.__henExperimentTopology = self.__configFile.get(
            'MAIN', 'EXPERIMENTAL_TOPOLOGY')
        self.__userLogFile = "%s%s-%s-%s" % (self.__henLogPath, "/log",
                                             auxiliary.hen.getUserName(),
                                             auxiliary.hen.getTime())
        self.__henManager = self.__configFile.get('MAIN', 'MANAGER')
        self.__physicalPath = self.__configFile.get('MAIN', 'PHYSICAL_PATH')
        self.__testbedGroup = self.__configFile.get('NETBOOT', 'GROUP')
        self.__experimentPath = self.__configFile.get('MAIN',
                                                      'EXPERIMENTAL_PATH')
        self.__configFilesPath = self.__configFile.get('MAIN', 'CONF_PATH')

        self.__hmDaemonConfig = self.__configFile.get(
            'CONFIG_FILES', 'HM_DAEMON_CONFIG_FILENAME')
        self.__powerDaemonConfig = self.__configFile.get(
            'CONFIG_FILES', 'POWER_DAEMON_CONFIG_FILENAME')
        self.__switchDaemonConfig = self.__configFile.get(
            'CONFIG_FILES', 'SWITCH_DAEMON_CONFIG_FILENAME')
        self.__consoleDaemonConfig = self.__configFile.get(
            'CONFIG_FILES', 'CONSOLE_DAEMON_CONFIG_FILENAME')
        self.__moteDaemonConfig = self.__configFile.get(
            'CONFIG_FILES', 'MOTE_DAEMON_CONFIG_FILENAME')
        self.__monitorDaemonConfig = self.__configFile.get(
            'CONFIG_FILES', 'MONITOR_DAEMON_CONFIG_FILENAME')

        self.__dhcpServerControlScript = self.__configFile.get(
            'DHCP', 'SERVER_CONTROL_SCRIPT')
        self.__namedConfPath = self.__configFile.get('DNS', 'NAMED_CONF_PATH')

        self.__running = None
        self.__log = None

        self.__configNetboot = ConfigNetboot(NetbootInfo(self.__configFile.get('NETBOOT', 'AUTODETECT_LOADER'), \
                                             self.__configFile.get('NETBOOT', 'AUTODETECT_FILESYSTEM'), \
                                             self.__configFile.get('NETBOOT', 'AUTODETECT_KERNEL')), \
                                             self.__testbedGroup, \
                                             self.__configFile.get('NETBOOT', 'NFS_ROOT'), \
                                             self.__configFile.get('NETBOOT', 'SERIAL_SPEED'), \
                                             self.__configFile.get('NETBOOT', 'PXE_LINUX_DIRECTORY'), \
                                             self.__configFile.get('NETBOOT', 'PXE_LINUX_FILE'), \
                                             self.__configFile.get('NETBOOT', 'STARTUP_FILE'), \
                                             self.__configFile.get('NETBOOT', 'INTERFACE_CONFIG_SCRIPT'), \
                                             self.__configFile.get('NETBOOT', 'CONSOLE'), \
                                             self.__henExportPath, \
                                             self.__pythonBin)

        self.initLogging()
        self.__parser = HenParser(self.__henPhysicalTopology, self.__henExperimentTopology, \
                                       self.__log, self.__physicalPath, self.__experimentPath, self.__configFile.get('MAIN', 'CURRENT_EXPERIMENTS'), self.__testbedGroup)
コード例 #3
0
    def __init__(self, configFilePath='/usr/local/hen/etc/configs/config'):
        Daemon.__init__(self)

        self.__version = "System Daemon v0.2 (dumb)"

        # Initialize testbed config file
        self.__configFilePath = configFilePath
        self.__configFile = ConfigParser.ConfigParser()
        self.__configFile.read(configFilePath)

        # Initialize parser
        self.__henPhysicalTopology = self.__configFile.get(
            'MAIN', 'PHYSICAL_TOPOLOGY')
        self.__henLogPath = self.__configFile.get('MAIN', 'LOG_PATH')
        self.__parser = HenParser(self.__henPhysicalTopology, \
                                  None, \
                                  None, \
                                  self.__henLogPath, \
                                  None,
                                  None,
                                  None, \
                                  None)

        # Initialize DNS writer
        self.__testbedGroup = self.__configFile.get('NETBOOT', 'GROUP')
        configInfo = DNSConfigInfo(self.__configFile.get('DNS', 'TTL'), \
                                   self.__configFile.get('DNS', 'CONTACT'), \
                                   self.__configFile.get('DNS', 'REFRESH_TIME'), \
                                   self.__configFile.get('DNS', 'RETRY_TIME'), \
                                   self.__configFile.get('DNS', 'EXPIRY_TIME'), \
                                   self.__configFile.get('DNS', 'MINIMUM_TIME'), \
                                   self.__configFile.get('MAIN', 'EXPERIMENTAL_BASE_ADDRESS'), \
                                   self.__configFile.get('DNS', 'EXPERIMENTAL_DOMAIN_NAME'), \
                                   self.__configFile.get('DNS', 'EXPERIMENTAL_SERVER_ADDRESS'), \
                                   self.__configFile.get('MAIN', 'INFRASTRUCTURE_BASE_ADDRESS'), \
                                   self.__configFile.get('DNS', 'INFRASTRUCTURE_DOMAIN_NAME'), \
                                   self.__configFile.get('DNS', 'INFRASTRUCTURE_SERVER_ADDRESS'), \
                                   self.__configFile.get('MAIN', 'VIRTUAL_BASE_ADDRESS'), \
                                   self.__configFile.get('DNS', 'VIRTUAL_DOMAIN_NAME'), \
                                   self.__configFile.get('DNS', 'VIRTUAL_SERVER_ADDRESS'))
        self.__dnsWriter = DNSConfigWriter(configInfo, \
                                           self.__configFile.get('DNS', 'CONFIG_FILES_PATH'), \
                                           self.__testbedGroup,
                                           self.__parser)

        # Initialize DHCP writer
        expSubnet = DHCPConfigSubnetInfo(self.__configFile.get('DHCP', 'EXPERIMENTAL_NET'), \
                                         self.__configFile.get('DHCP', 'EXPERIMENTAL_NET_NETMASK'), \
                                         self.__configFile.get('DHCP', 'EXPERIMENTAL_USE_HOST_DECL_NAMES'), \
                                         self.__configFile.get('DHCP', 'EXPERIMENTAL_NET_NETMASK'), \
                                         self.__configFile.get('DHCP', 'EXPERIMENTAL_NET_BROADCAST_ADDRESS'), \
                                         self.__configFile.get('DHCP', 'EXPERIMENTAL_DOMAIN_NAME'), \
                                         self.__configFile.get('DHCP', 'EXPERIMENTAL_ROUTERS'), \
                                         self.__configFile.get('DHCP', 'EXPERIMENTAL_NEXT_SERVER'), \
                                         "experimental")
        infraSubnet = DHCPConfigSubnetInfo(self.__configFile.get('DHCP', 'INFRASTRUCTURE_NET'), \
                                           self.__configFile.get('DHCP', 'INFRASTRUCTURE_NET_NETMASK'), \
                                           self.__configFile.get('DHCP', 'INFRASTRUCTURE_USE_HOST_DECL_NAMES'), \
                                           self.__configFile.get('DHCP', 'INFRASTRUCTURE_NET_NETMASK'), \
                                           self.__configFile.get('DHCP', 'INFRASTRUCTURE_NET_BROADCAST_ADDRESS'), \
                                           self.__configFile.get('DHCP', 'INFRASTRUCTURE_DOMAIN_NAME'), \
                                           self.__configFile.get('DHCP', 'INFRASTRUCTURE_ROUTERS'), \
                                           self.__configFile.get('DHCP', 'INFRASTRUCTURE_NEXT_SERVER'), \
                                           "infrastructure")
        virtualSubnet = DHCPConfigSubnetInfo(self.__configFile.get('DHCP', 'VIRTUAL_NET'), \
                                             self.__configFile.get('DHCP', 'VIRTUAL_NET_NETMASK'), \
                                             self.__configFile.get('DHCP', 'VIRTUAL_USE_HOST_DECL_NAMES'), \
                                             self.__configFile.get('DHCP', 'VIRTUAL_NET_NETMASK'), \
                                             self.__configFile.get('DHCP', 'VIRTUAL_NET_BROADCAST_ADDRESS'), \
                                             self.__configFile.get('DHCP', 'VIRTUAL_DOMAIN_NAME'), \
                                             self.__configFile.get('DHCP', 'VIRTUAL_ROUTERS'), \
                                             self.__configFile.get('DHCP', 'VIRTUAL_NEXT_SERVER'), \
                                             "virtual")
        subnetList = []
        subnetList.append(expSubnet)
        subnetList.append(infraSubnet)
        subnetList.append(virtualSubnet)
        configInfo = DHCPConfigInfo(self.__configFile.get('DHCP', 'DOMAIN_NAME'), \
                                    self.__configFile.get('DHCP', 'DOMAIN_NAME_SERVERS'), \
                                    self.__configFile.get('DHCP', 'DEFAULT_LEASE_TIME'), \
                                    self.__configFile.get('DHCP', 'MAXIMUM_LEASE_TIME'), \
                                    self.__configFile.get('DHCP', 'AUTHORITATIVE'), \
                                    self.__configFile.get('DHCP', 'DDNS_UPDATE_STYLE'), \
                                    self.__configFile.get('DHCP', 'LOG_FACILITY'), \
                                    subnetList)
        self.__henExportPath = self.__configFile.get('MAIN', 'EXPORT_PATH')
        self.__dhcpWriter = DHCPConfigWriter(configInfo, self.__configFile.get('DHCP', 'CONFIG_FILE_PATH'), \
                                             self.__henExportPath,  self.__testbedGroup, self.__parser)

        # Export methods
        self.__registerMethods()
コード例 #4
0
ファイル: consoledaemon.py プロジェクト: benroeder/HEN
class ConsoleControl(Daemon):
    """\brief Implements basic console daemon functionality.
    """
    def __init__(self, configFilePath='/usr/local/hen/etc/configs/config'):
        Daemon.__init__(self)

        self.__version = "Console Daemon v0.2 (dumb)"
        self.__terminalServerConnections = {}
        self.__terminalServerSockets = []
        self.__configFilePath = configFilePath
        self.__configFile = ConfigParser.ConfigParser()
        self.__configFile.read(configFilePath)
        self.__henPhysicalTopology = self.__configFile.get('MAIN','PHYSICAL_TOPOLOGY')
        self.__henLogPath = self.__configFile.get('MAIN', 'LOG_PATH')
        self.__parser = HenParser(self.__henPhysicalTopology, \
                                  None, \
                                  None, \
                                  self.__henLogPath, \
                                  None,
                                  None,
                                  None, \
                                  None)

        self.__controlProtocol = None

        # Create instances for all terminal servers in the testbed
        self.__terminalServerNodes = {}
        for terminalServerNode in self.__parser.getNodes("serial", "all").values():
            self.__terminalServerNodes[terminalServerNode.getNodeID()] = terminalServerNode.getInstance()
        self.__computerNodes = self.__parser.getNodes("computer", "all")
                                
        self.__registerMethods()

    def __registerMethods(self):
        self.registerMethodHandler("console", self.console)

    def __getPort(self, nodeID):
        return (self.__computerNodes[nodeID].getSerialNodeID(), self.__computerNodes[nodeID].getSerialNodePort())
        
    def console(self,prot,seq,ln,payload):
        print "in console"
        if (self.__controlProtocol == None):
            self.__controlProtocol = Protocol(None)        
            self.__controlProtocol.open(DaemonLocations.controlDaemon[0], DaemonLocations.controlDaemon[1])        
        (action, username, nodeID, consoleInput) = pickle.loads(payload)
        print action, username, nodeID, consoleInput


        (serialID, serialPort) = self.__getPort(nodeID)
        # Replies are needed by doSynchronous call in control daemon
        if (action == "open"):
            terminalServerConnection = TerminalServerConnection(username, serialPort, self.__terminalServerNodes[serialID])
            self.__terminalServerConnections[terminalServerConnection.getSocket()] = terminalServerConnection
            self.__terminalServerSockets.append(terminalServerConnection.getSocket())
            self.sock_list.append(terminalServerConnection.getSocket())
            prot.sendReply(200, seq, "")
            return
        elif (action == "close"):
            for connection in self.__terminalServerConnections.values():
                if (connection.getUserID() == username):
                    connection.close()
                    self.sock_list.remove(connection.getSocket())
                    self.__terminalServerSockets.remove(connection.getSocket())
                    del self.__terminalServerConnections[connection.getSocket()]
                    break            
            prot.sendReply(200, seq, "")
            return
        elif (action == "forward"):
            for connection in self.__terminalServerConnections.values():
                if (connection.getUserID() == username):
                    connection.send(consoleInput)
        else:
            print "unrecognized action:", action

    def processTerminalServerData(self, sock):
        connection = self.__terminalServerConnections[sock]
        if (connection.recv()):
            self.__controlProtocol.sendRequest("console", \
                                               pickle.dumps((connection.getUserID(), \
                                                             connection.getAndDeleteBuffer(), \
                                                             ["console_output"])), \
                                               self.terminalServerDataReplyHandler)

    def terminalServerDataReplyHandler(self, code, seq, sz, payload):
        pass
    
    def stopDaemon(self,prot,seq,ln,payload):
        """\brief Stops the daemon and all threads
        This method will first stop any more incoming queries, then wait for
        any update tasks to complete, before stopping itself.
        """
        log.info("stopDaemon called.")
        prot.sendReply(200, seq, "Accepted stop request.")
        log.debug("Sending stopDaemon() response")
        self.acceptConnections(False)
        log.info("Stopping ConsoleDaemon (self)")
        self.stop()

    def run(self):
        """\brief Main daemon loop
        Waits for messages from clients and processes them. Only sleeps for two
        seconds, to accept new clients also.
        """
        while not self.isStopped:
            #select sockets
            (read,write,exc) = select.select(self.sock_list,[],self.sock_list,2)
            for i in read:
                s = None

                if (i in self.__terminalServerSockets):
                    self.processTerminalServerData(i)
                    continue

                # Process regular socket
                try:
                    s = i.recv(1000000,0)
                # Process SSL socket
                except:
                    try:
                        s = i.read(1000000)
                    except:
                        s = []
                try:
                    #log.debug("Read from socket:"+s.replace("\r","\\r"))

                    if (len(s)==0):
                        #log.debug("removing")
                        idx = self.sock_list.index(i)
                        del self.sock_list[idx]
                        del self.protocol_list[idx]
                    else:
                        self.protocol_list[self.sock_list.index(i)].processPacket(s)
                except Exception,e:
                    idx = self.sock_list.index(i)
                    del self.sock_list[idx]
                    del self.protocol_list[idx]
                    traceback.print_exc()
            for i in exc:
                log.debug ("exc",i)