Example #1
0
 def delete(self, id, daemon_url, fabric_version, consensus_plugin,
            cluster_size):
     return compose_clean(id, daemon_url, fabric_version,
                          consensus_plugin, cluster_size)
Example #2
0
 def delete(self, id, worker_api, config):
     return compose_clean(id, worker_api, config)
Example #3
0
 def delete(self, id, daemon_url, consensus_plugin):
     return compose_clean(id, daemon_url, consensus_plugin)
Example #4
0
 def delete(self, id, worker_api, config):
     return compose_clean(id, worker_api, config)
Example #5
0
    def delete(self, id, record=False, forced=False):
        """ Delete a cluster instance

        Clean containers, remove db entry. Only operate on active host.

        :param id: id of the cluster to delete
        :param record: Whether to record into the released collections
        :param forced: Whether to removing user-using cluster, for release
        :return:
        """
        logger.debug("Delete cluster: id={}, forced={}".format(id, forced))

        c = self.db_update_one({"id": id}, {"$set": {
            "user_id": SYS_DELETER
        }},
                               after=False)
        if not c:
            logger.warning("Cannot find cluster {}".format(id))
            return False
        # we are safe from occasional applying now
        user_id = c.get("user_id")  # original user_id
        if not forced and user_id != "" and not user_id.startswith(SYS_USER):
            # not forced, and chain is used by normal user, then no process
            logger.warning("Cannot delete cluster {} by "
                           "user {}".format(id, user_id))
            self.col_active.update_one({"id": id},
                                       {"$set": {
                                           "user_id": user_id
                                       }})
            return False

        #  0. forced
        #  1. user_id == SYS_DELETER or ""
        #  Then, add deleting flag to the db, and start deleting
        if not user_id.startswith(SYS_DELETER):
            self.col_active.update_one(
                {"id": id}, {"$set": {
                    "user_id": SYS_DELETER + user_id
                }})
        host_id, daemon_url, consensus_plugin = \
            c.get("host_id"), c.get("daemon_url"), \
            c.get("consensus_plugin", CONSENSUS_PLUGINS[0])
        # port = api_url.split(":")[-1] or CLUSTER_PORT_START

        if not self.host_handler.get_active_host_by_id(host_id):
            logger.warning("Host {} inactive".format(host_id))
            self.col_active.update_one({"id": id},
                                       {"$set": {
                                           "user_id": user_id
                                       }})
            return False

        if not compose_clean(id, daemon_url, consensus_plugin):
            logger.warning("Error to run compose clean work")
            self.col_active.update_one({"id": id},
                                       {"$set": {
                                           "user_id": user_id
                                       }})
            return False

        self.host_handler.db_update_one({"id": c.get("host_id")},
                                        {"$pull": {
                                            "clusters": id
                                        }})
        self.col_active.delete_one({"id": id})
        if record:  # record original c into release collection
            logger.debug("Record the cluster info into released collection")
            c["release_ts"] = datetime.datetime.now()
            c["duration"] = str(c["release_ts"] - c["apply_ts"])
            # seems mongo reject timedelta type
            if user_id.startswith(SYS_DELETER):
                c["user_id"] = user_id[len(SYS_DELETER):]
            self.col_released.insert_one(c)
        return True
Example #6
0
    def delete(self, id, record=False, forced=False):
        """ Delete a cluster instance

        Clean containers, remove db entry. Only operate on active host.

        :param id: id of the cluster to delete
        :param record: Whether to record into the released collections
        :param forced: Whether to removing user-using cluster, for release
        :return:
        """
        logger.debug("Delete cluster: id={}, forced={}".format(id, forced))

        c = self.db_update_one({"id": id}, {"$set": {"user_id": SYS_DELETER}},
                               after=False)
        if not c:
            logger.warning("Cannot find cluster {}".format(id))
            return False
        # we are safe from occasional applying now
        user_id = c.get("user_id")  # original user_id
        if not forced and user_id != "" and not user_id.startswith(SYS_USER):
            # not forced, and chain is used by normal user, then no process
            logger.warning("Cannot delete cluster {} by "
                           "user {}".format(id, user_id))
            self.col_active.update_one({"id": id},
                                       {"$set": {"user_id": user_id}})
            return False

        #  0. forced
        #  1. user_id == SYS_DELETER or ""
        #  Then, add deleting flag to the db, and start deleting
        if not user_id.startswith(SYS_DELETER):
            self.col_active.update_one(
                {"id": id},
                {"$set": {"user_id": SYS_DELETER + user_id}})
        host_id, daemon_url, consensus_plugin = \
            c.get("host_id"), c.get("daemon_url"), \
            c.get("consensus_plugin", CONSENSUS_PLUGINS[0])
        # port = api_url.split(":")[-1] or CLUSTER_PORT_START

        if not self.host_handler.get_active_host_by_id(host_id):
            logger.warning("Host {} inactive".format(host_id))
            self.col_active.update_one({"id": id},
                                       {"$set": {"user_id": user_id}})
            return False

        if not compose_clean(id, daemon_url, consensus_plugin):
            logger.warning("Error to run compose clean work")
            self.col_active.update_one({"id": id},
                                       {"$set": {"user_id": user_id}})
            return False

        self.host_handler.db_update_one({"id": c.get("host_id")},
                                        {"$pull": {"clusters": id}})
        self.col_active.delete_one({"id": id})
        if record:  # record original c into release collection
            logger.debug("Record the cluster info into released collection")
            c["release_ts"] = datetime.datetime.now()
            c["duration"] = str(c["release_ts"] - c["apply_ts"])
            # seems mongo reject timedelta type
            if user_id.startswith(SYS_DELETER):
                c["user_id"] = user_id[len(SYS_DELETER):]
            self.col_released.insert_one(c)
        return True