def _egg_remotepath(self, egg_name): log.debug("_egg_remotepath: %s", egg_name) if not REPO_BASE: raise ServerError("REPO_BASE is %s'%s'" % (type(REPO_BASE), REPO_BASE)) elif not egg_name: raise ServerError("egg_name for remotepath is %s'%s'" % (type(egg_name), egg_name)) return REPO_BASE + "/" + egg_name
def _egg_path(self, egg_name): log.debug("_egg_path") if not CACHE_DIR: raise ServerError("CACHE_DIR is %s'%s'" % (type(CACHE_DIR), CACHE_DIR)) elif not egg_name: raise ServerError("egg_name for path is %s'%s'" % (type(egg_name), egg_name)) return CACHE_DIR + "/" + egg_name
def add_endpoint(self, endpoint): """ Adds a managed listening endpoint to this service/process. The service/process must be running inside of an IonProcessThread, or this method will raise an error. A managed listening endpoint will report failures up to the process, then to the container's process manager. """ if self._process is None: raise ServerError("No attached IonProcessThread") self._process.add_endpoint(endpoint)
def __init__(self, input_callback=None, ip_address=None): log.debug("TcpServer.__init__(): IP address = %s" %ip_address) # save callback if specified if not input_callback: log.warning("TcpServer.__init__(): callback not specified") raise ServerError("TcpServer.__init__(): callback not specified") self.parent_input_callback = input_callback # save ip address if specified if not ip_address: log.warning("TcpServer.__init__(): IP address not specified") raise ServerError("TcpServer.__init__(): IP address not specified") self.ip_address = ip_address # search for an available port self.port = self.PORT_RANGE_LOWER # create a TCP socket self.server_socket = gevent.socket.socket() self.server_socket.allow_reuse_address = True while True: try: log.debug("trying to bind to port %s on %s" %(str(self.port), self.ip_address)) self.server_socket.bind((self.ip_address, self.port)) break except Exception as ex: log.debug("exception caught for socket bind:" + str(ex)) self.port = self.port + 1 if self.port > self.PORT_RANGE_UPPER: log.warning("TcpServer.__init__(): no available ports for server") raise ServerError("TcpServer.__init__(): no available ports") # create token for login verification of telnet self.token = str(uuid.uuid4()).upper() log.debug("TcpServer.__init__(): starting server greenlet") self.server = gevent.spawn(self._server_greenlet)
def remove_endpoint(self, endpoint): """ Removes an endpoint from being managed by this service/process. The service/process must be running inside of an IonProcessThread, or this method will raise an error. It will also raise an error if the endpoint is not currently managed. Errors raised in the endpoint will no longer be reported to the process or process manager. """ if self._process is None: raise ServerError("No attached IonProcessThread") self._process.remove_endpoint(endpoint)
def _get_port_from_file(self, filename): """ Read the driver port from a status file. The driver process writes two status files containing the port number for events and commands. @param filename path to the port file @return port port number read from the file @raise ServerError if file not read w/in 10sec """ maxWait = 10 # try for up to 10sec waitInterval = 0.5 # repeating every 1/2 sec log.debug("about to read port from file %s", filename) for n in xrange(int(maxWait / waitInterval)): try: with open(filename, 'r') as f: port = int(f.read().strip()) log.debug("read port %d from file %s", port, filename) return port except: pass time.sleep(waitInterval) raise ServerError('process PID file was not found: ' + filename)
def __init__(self, direct_access_type=None, input_callback=None, ip_address=None, session_timeout=None, inactivity_timeout=None): log.debug("DirectAccessServer.__init__()") if not direct_access_type: log.warning("DirectAccessServer.__init__(): direct access type not specified") raise ServerError("DirectAccessServer.__init__(): direct access type not specified") if not input_callback: log.warning("DirectAccessServer.__init__(): callback not specified") raise ServerError("DirectAccessServer.__init__(): callback not specified") if not ip_address: log.warning("DirectAccessServer.__init__(): IP address not specified") raise ServerError("DirectAccessServer.__init__(): IP address not specified") if not session_timeout: log.warning("DirectAccessServer.__init__(): session timeout not specified") raise ServerError("DirectAccessServer.__init__(): session timeout not specified") if not inactivity_timeout: log.warning("DirectAccessServer.__init__(): inactivity timeout not specified") raise ServerError("DirectAccessServer.__init__(): inactivity timeout not specified") # start the correct server based on direct_access_type if direct_access_type == DirectAccessTypes.telnet: self.server = TelnetServer(input_callback, ip_address) elif direct_access_type == DirectAccessTypes.vsp: self.server = SerialServer(input_callback, ip_address) else: raise ServerError("DirectAccessServer.__init__(): Unsupported direct access type") log.debug("DirectAccessServer.__init__(): starting timer greenlet") self.timer = gevent.spawn(self._timer_greenlet, session_timeout=session_timeout, inactivity_timeout=inactivity_timeout)