Esempio n. 1
0
 def update_region_config(self):
     region_data = self.generate_region_config()
     try:
         config_service.get_by_key("REGION_SERVICE_API")
         config_service.update_config("REGION_SERVICE_API", region_data)
     except ConsoleSysConfig.DoesNotExist:
         config_service.add_config("REGION_SERVICE_API", region_data, 'json', "数据中心配置")
    def list_base_tasks(self, eid):
        cfg = config_service.get_config_by_key(eid)
        if not cfg:
            # init base tasks
            logger.info("Enterprise id: {}; initialize basic tasks information".format(eid))
            data = self.init_base_task()
            # TODO: handle error
            config_service.add_config_without_reload(key=eid, default_value=json.dumps(data), type="json")
        else:
            data = json.loads(cfg)
        need_update = False
        for index in range(len(data)):
            if data[index] is not None and data[index]["key"] == "install_mysql_from_market":
                del data[index]
                config_service.update_config(eid, json.dumps(data))
                break

        for item in data:
            if not item["status"]:
                ctx = BaseTaskStatusContext(eid, item["key"])
                status = ctx.confirm_status()
                if status:
                    logger.info("Enterprise id: {0}; Task: {1}; Original status: False; "
                                "update status.".format(eid, item["key"]))
                    item["status"] = status
                    need_update = True

        if need_update:
            # TODO: handle error
            config_service.update_config(eid, json.dumps(data))

        return data