def create(self, worker_api): """ Create a new docker host node A docker host is potentially a single node or a swarm. Will full fill with clusters of given capacity. :param worker_api: worker_api of the host :return: True or False """ if check_daemon(worker_api): logger.warning("The worker_api is active:" + worker_api) else: logger.warning("The worker_api is inactive:" + worker_api) return False detected_type = detect_daemon_type(worker_api) if detected_type != self.host_type: logger.warning("Host type={} should be same with the initialized \ type={}".format(detected_type, self.host_type)) return False if detected_type not in ['docker', 'swarm']: logger.warning("Detected type={} is not docker or swarm".format( detected_type)) return False if setup_container_host(detected_type, worker_api): return True else: logger.warning( "Cannot setup Docker host worker_api={}".format(worker_api)) return False
def refresh_status(self, worker_api): """ Refresh the status of the host by detection :param worker_api: api to the worker :return: Updated host """ return check_daemon(worker_api)
def refresh_status(self, daemon_url): """ Refresh the status of the host by detection :param host: the host to update status :return: Updated host """ return check_daemon(daemon_url)
def refresh_status(self, worker_api): """ Refresh the status of the host :param worker_api: the host of vm :return: the status of the host """ return check_daemon(worker_api)
def refresh_status(self, worker_api): """ Refresh the status of the host by detection :param host: the host to update status :return: Updated host """ return check_daemon(worker_api)
def refresh_status(self, id): """ Refresh the status of the host by detection :param host: the host to update status :return: Updated host """ host = self.get_by_id(id) if not host: logger.warning("No host found with id=" + id) return False if not check_daemon(host.get("daemon_url")): logger.warning("Host {} is inactive".format(id)) self.db_set_by_id(id, status="inactive") return False else: self.db_set_by_id(id, status="active") return True
def create(self, worker_api): """ Create a new docker host node A docker host is potentially a single node or a swarm. Will full fill with clusters of given capacity. :param name: name of the node :param worker_api: worker_api of the host :param capacity: The number of clusters to hold :param log_type: type of the log :param log_level: level of the log :param log_server: server addr of the syslog :param autofill: Whether automatically fillup with chains :param schedulable: Whether can schedule cluster request to it :param serialization: whether to get serialized result or object :return: True or False """ if check_daemon(worker_api): logger.warning("The worker_api is active:" + worker_api) else: logger.warning("The worker_api is inactive:" + worker_api) return False detected_type = detect_daemon_type(worker_api) if detected_type != self.host_type: logger.warning("Host type={} should be same with the initialized \ type={}".format(detected_type, self.host_type)) return False if detected_type not in ['docker', 'swarm']: logger.warning("Detected type={} is not docker or swarm". format(detected_type)) return False if setup_container_host(detected_type, worker_api): return True else: logger.warning("Cannot setup Docker host worker_api={}" .format(worker_api)) return False
def create(self, worker_api): """ Create a new docker host node A docker host is potentially a single node or a swarm. Will full fill with clusters of given capacity. :param name: name of the node :param worker_api: worker_api of the host :param capacity: The number of clusters to hold :param log_type: type of the log :param log_level: level of the log :param log_server: server addr of the syslog :param autofill: Whether automatically fillup with chains :param schedulable: Whether can schedule cluster request to it :param serialization: whether to get serialized result or object :return: True or False """ if check_daemon(worker_api): logger.warning("The worker_api is active:" + worker_api) else: logger.warning("The worker_api is inactive:" + worker_api) return False detected_type = detect_daemon_type(worker_api) if detected_type != self.host_type: logger.warning("Host type={} should be same with the initialized \ type={}".format(detected_type, self.host_type)) return False if detected_type not in ['docker', 'swarm']: logger.warning("Detected type={} is not docker or swarm".format( detected_type)) return False if setup_container_host(detected_type, worker_api): return True else: logger.warning( "Cannot setup Docker host worker_api={}".format(worker_api)) return False
def create(self, name, daemon_url, capacity=1, log_level=CLUSTER_LOG_LEVEL[0], log_type=CLUSTER_LOG_TYPES[0], log_server="", autofill="false", schedulable="false", serialization=True): """ Create a new docker host node A docker host is potentially a single node or a swarm. Will full fill with clusters of given capacity. :param name: name of the node :param daemon_url: daemon_url of the host :param capacity: The number of clusters to hold :param log_type: type of the log :param log_level: level of the log :param log_server: server addr of the syslog :param autofill: Whether automatically fillup with chains :param schedulable: Whether can schedule cluster request to it :param serialization: whether to get serialized result or object :return: True or False """ logger.debug("Create host: name={}, daemon_url={}, capacity={}, " "log={}/{}, autofill={}, schedulable={}" .format(name, daemon_url, capacity, log_type, log_server, autofill, schedulable)) if not daemon_url.startswith("tcp://"): daemon_url = "tcp://" + daemon_url if self.col.find_one({"daemon_url": daemon_url}): logger.warning("{} already existed in db".format(daemon_url)) return {} if "://" not in log_server: log_server = "udp://" + log_server if log_type == CLUSTER_LOG_TYPES[0]: log_server = "" if check_daemon(daemon_url): logger.warning("The daemon_url is active:" + daemon_url) status = "active" else: logger.warning("The daemon_url is inactive:" + daemon_url) status = "inactive" detected_type = detect_daemon_type(daemon_url) if not setup_container_host(detected_type, daemon_url): logger.warning("{} cannot be setup".format(name)) return {} h = { 'id': '', 'name': name, 'daemon_url': daemon_url, 'create_ts': datetime.datetime.now(), 'capacity': capacity, 'status': status, 'clusters': [], 'type': detected_type, 'log_level': log_level, 'log_type': log_type, 'log_server': log_server, 'autofill': autofill, 'schedulable': schedulable } hid = self.col.insert_one(h).inserted_id # object type host = self.db_update_one( {"_id": hid}, {"$set": {"id": str(hid)}}) if capacity > 0 and autofill == "true": # should autofill it self.fillup(str(hid)) if serialization: return self._serialize(host) else: return host
def is_active(self, *args): return check_daemon(args[1])
def create(self, name, daemon_url, capacity=1, log_level=CLUSTER_LOG_LEVEL[0], log_type=CLUSTER_LOG_TYPES[0], log_server="", autofill="false", schedulable="false", serialization=True): """ Create a new docker host node A docker host is potentially a single node or a swarm. Will full fill with clusters of given capacity. :param name: name of the node :param daemon_url: daemon_url of the host :param capacity: The number of clusters to hold :param log_type: type of the log :param log_level: level of the log :param log_server: server addr of the syslog :param autofill: Whether automatically fillup with chains :param schedulable: Whether can schedule cluster request to it :param serialization: whether to get serialized result or object :return: True or False """ logger.debug("Create host: name={}, daemon_url={}, capacity={}, " "log={}/{}, autofill={}, schedulable={}".format( name, daemon_url, capacity, log_type, log_server, autofill, schedulable)) if not daemon_url.startswith("tcp://"): daemon_url = "tcp://" + daemon_url if self.col.find_one({"daemon_url": daemon_url}): logger.warning("{} already existed in db".format(daemon_url)) return {} if "://" not in log_server: log_server = "udp://" + log_server if log_type == CLUSTER_LOG_TYPES[0]: log_server = "" if check_daemon(daemon_url): logger.warning("The daemon_url is active:" + daemon_url) status = "active" else: logger.warning("The daemon_url is inactive:" + daemon_url) status = "inactive" detected_type = detect_daemon_type(daemon_url) if not setup_container_host(detected_type, daemon_url): logger.warning("{} cannot be setup".format(name)) return {} h = { 'id': '', 'name': name, 'daemon_url': daemon_url, 'create_ts': datetime.datetime.now(), 'capacity': capacity, 'status': status, 'clusters': [], 'type': detected_type, 'log_level': log_level, 'log_type': log_type, 'log_server': log_server, 'autofill': autofill, 'schedulable': schedulable } hid = self.col.insert_one(h).inserted_id # object type host = self.db_update_one({"_id": hid}, {"$set": {"id": str(hid)}}) if capacity > 0 and autofill == "true": # should autofill it self.fillup(str(hid)) if serialization: return self._serialize(host) else: return host