def get_target_s3_zdb_config(target_name): zos = get_zos() for sol_dict in solutions.list_minio_solutions(): if sol_dict["Name"] != target_name: continue minio_wid = sol_dict["wids"][0] workload = zos.workloads.get(minio_wid) sol_uuid = solutions.get_solution_uuid(workload) if not sol_uuid: continue solution_workloads = solutions.get_workloads_by_uuid(sol_uuid) cluster_zdb_configs = [] for workload in solution_workloads: if workload.info.workload_type != WorkloadType.Zdb: continue # check the password # if no password, then it is old not supported # metadata is json serializable as the workload was identitified by solution_uuid metadata = serializers.json.loads( deployer.decrypt_metadata(workload.info.metadata)) password = metadata.get("password") if not password: j.logger.error( f"AUTO_TOPUP: zdb workload {workload.id} doesn't include password in metadata in s3 solution {sol_dict['Name']}" ) raise j.exceptions.Validation( f"AUTO_TOPUP: zdb workload {workload.id} doesn't include password in metadata in s3 solution {sol_dict['Name']}" ) zdb_url = deployer.get_zdb_url(workload.id, password, workload=workload) splits = zdb_url.split("@") zdb_dict = { "address": splits[1], "namespace": splits[0].split(":")[0], "password": password } cluster_zdb_configs.append(zdb_dict) if not cluster_zdb_configs: j.logger.error( f"AUTO_TOPUP: can't retrive zdb config of s3 solution {sol_dict['Name']} because of invalid zdb metadata" ) raise j.exceptions.Runtime( f"AUTO_TOPUP: can't retrive zdb config of s3 solution {sol_dict['Name']} because of invalid zdb metadata" ) return cluster_zdb_configs
def minio_name(self): self._deployment_start() valid = False while not valid: self.solution_name = deployer.ask_name(self) minio_solutions = solutions.list_minio_solutions(sync=False) valid = True for sol in minio_solutions: if sol["Name"] == self.solution_name: valid = False self.md_show( "The specified solution name already exists. please choose another name." ) break valid = True
def list_auto_top_up_config(): config = j.core.config.set_default( "S3_AUTO_TOP_SOLUTIONS", {"max_storage": 3 * 1024, "threshold": 0.7, "clear_threshold": 0.4, "targets": {}} ) if not isinstance(config, dict): j.logger.error("AUTO_TOPUP: S3_AUTO_TOP_SOLUTIONS config is not valid!") j.tools.alerthandler.alert_raise( app_name="s3_auto_topup", category="validation", message="AUTO_TOPUP: S3_AUTO_TOP_SOLUTIONS config is not valid!", alert_type="exception", ) return default_extension_size = config.get("extension_size", 10) default_max_storage = config.get("max_storage") default_threshold = config.get("threshold") default_clear_threshold = config.get("clear_threshold") default_farm_names = config.get("farm_names") defaults = [default_max_storage, default_threshold, default_clear_threshold, default_farm_names] if not all(defaults): j.logger.error("AUTO_TOPUP: S3_AUTO_TOP_SOLUTIONS config is not valid!") j.tools.alerthandler.alert_raise( app_name="s3_auto_topup", category="validation", message="AUTO_TOPUP: S3_AUTO_TOP_SOLUTIONS config is not valid!", alert_type="exception", ) return targets = config.get("targets", {}) if not isinstance(targets, dict): j.logger.error("AUTO_TOPUP: S3_AUTO_TOP_SOLUTIONS targets config is not valid!") j.tools.alerthandler.alert_raise( app_name="s3_auto_topup", category="validation", message="AUTO_TOPUP: S3_AUTO_TOP_SOLUTIONS targets config is not valid!", alert_type="exception", ) return zos = get_zos() minio_solutions = {sol["Name"]: sol for sol in solutions.list_minio_solutions()} for sol_name, sol_config in targets.items(): if sol_name not in minio_solutions: j.logger.warning(f"AUTO_TOPUP: solution {sol_name} is not a current s3 solution") continue minio_solution = minio_solutions[sol_name] minio_pool = zos.pools.get(minio_solution["Primary Pool"]) duration = minio_pool.empty_at - j.data.time.utcnow().timestamp workload = zos.workloads.get(minio_solution["wids"][0]) solution_uuid = solutions.get_solution_uuid(workload) if not isinstance(sol_config, dict) or not all( [key in sol_config for key in ["minio_api_url", "healing_url"]] ): j.logger.error(f"AUTO_TOPUP: target {sol_name} config is not valid!") j.tools.alerthandler.alert_raise( app_name="s3_auto_topup", category="validation", message=f"AUTO_TOPUP: target {sol_name} config is not valid!", alert_type="exception", ) continue yield { "name": sol_name, "solution_uuid": solution_uuid, "extension_size": sol_config.get("extension_size", default_extension_size), "minio_api_url": sol_config["minio_api_url"], "healing_url": sol_config["healing_url"], "max_storage": sol_config.get("max_storage", default_max_storage), "threshold": sol_config.get("threshold", default_threshold), "clear_threshold": sol_config.get("clear_threshold", default_clear_threshold), "duration": duration, "farm_names": sol_config.get("farm_names", default_farm_names), }