def __init__(self, config): if config is None: self._config = {} else: self._config = config try: self._vendor = self._config.get("vendor") self._language = self._config.get("language") self._server = None if self._language in ServerAdaptor.get_language_supported().get( self._vendor): module_name = self._vendor + "_" + self._language class_name = self._vendor.capitalize( ) + self._language.capitalize() module = __import__('%s.%s.%s.%s' % (_SOURCE_PACKAGE, _APP_PACKAGE, _ADAPTEE_PACKAGE, module_name), fromlist=[class_name]) server_adaptor = getattr(module, class_name) server_adapter_instance = server_adaptor(self._config) self._server = ServerAdaptor(server_adapter_instance) else: print("Given language and vendor are not supported") sys.exit(1) except Exception, e: logger.exception(message_traceback()) raise Exception("602")
def log(self): try: container = Container(self.get_config().get("id")) cmd_log = "tail -f /Logs/swagger.log" container.set_cmd(cmd_log) container.log() except Exception, e: logger.exception(message_traceback()) raise Exception("602")
def stop(self): try: c_id = self.get_config().get("id") if id: response = False container = Container(c_id) if container.stop(): response = True container.remove() return response except Exception, e: logger.exception(message_traceback()) raise Exception("602")
def log(self): """ Serves log command for clients :return: void """ try: container_id = None if self._id: container_id = self._id cmd_string = "docker exec %s %s"%(container_id, self.get_cmd()) exec_command = subprocess.Popen(cmd_string, shell=True) exec_command.wait() if exec_command.returncode != 0: raise Exception("601") return except Exception, e: logger.exception(e) raise
def is_running(self): """ To check if container is running. :return: Boolean """ container_id = None if self._id: container_id = self._id response = False cmd_string = "docker inspect --format='{{json .State}}' %s" % (container_id) out, err = self._exec(cmd_string) out = out.strip() if out: out = json.loads(out) try: running_status = out.get("Running") if running_status: response = True except Exception, e: logger.exception(message_traceback()) raise Exception("602")