def initialize(manifest_fie): init = list() utils.log_info("Initialization....") key = utils.do_deploy_dir(manifest_fie) for stack in utils.initdir(key): for project in key["stack"][stack]: template = key["data"][stack][project]["template"] try: parameters = key["data"][stack][project]["parameters"] except: parameters = None url = False try: url = utils.repodata()[stack][template]["url"] branch = utils.repodata()[stack][template]["branch"] except: utils.log_err("template {} is not exist!".format(template)) exit() dest = "{}/{}/{}".format(key["deploy_dir"], stack, project) utils.log_info("Build {} {} template".format(project, stack)) if not utils.template_url(url, dest, branch): utils.log_err("Check your internet connection!") exit() utils.log_info("Done...") """ Stack init dict """ stack_init = {} stack_init["dir"] = dest stack_init["project"] = project stack_init["stack"] = stack stack_init["env_file"] = False if parameters: utils.log_info("Create {} {} environment file".format( project, stack)) utils.yaml_create("{}/env.yml".format(dest), {"parameters": parameters}) utils.log_info("Done...") stack_init["env_file"] = "{}/env.yml".format(dest) init.append(stack_init) """ Reformat squences deploy """ if utils.check_key(key["data"], "deploy"): if len(key["data"]["deploy"]) > 0: set_sequence = list() for deploy in key["data"]["deploy"]: set_deploy = deploy.split(".") set_stack = set_deploy[0] set_project = set_deploy[1] set_sequence.append([ new_init for new_init in init if (new_init["stack"] == set_stack) and ( new_init["project"] == set_project) ][0]) init = set_sequence utils.yaml_create("{}/deploy.yml".format(key["deploy_dir"]), init) return init
def initialize(manifest_fie): init = list() utils.log_info("Initialization....") key = utils.do_deploy_dir(manifest_fie) for stack in utils.initdir(key): for project in key["stack"][stack]: template = key["data"][stack][project]["template"] try: parameters = key["data"][stack][project]["parameters"] except: parameters = None url = False try: url = utils.repodata()[stack][template]["url"] except: utils.log_err("template {} is not exist!".format(template)) exit() dest = "{}/{}/{}".format(key["deploy_dir"], stack, project) utils.log_info("Build {} {} template".format(project, stack)) if not utils.template_url(url, dest): utils.log_err("Check your internet connection!") exit() utils.log_info("Done...") """ Stack init dict """ stack_init = {} stack_init["dir"] = dest stack_init["project"] = project stack_init["stack"] = stack stack_init["env_file"] = False if parameters: utils.log_info("Create {} {} environment file".format( project, stack)) utils.yaml_create("{}/env.yml".format(dest), { "parameters": parameters }) utils.log_info("Done...") stack_init["env_file"] = "{}/env.yml".format(dest) init.append(stack_init) """ Reformat squences deploy """ if utils.check_key(key["data"], "deploy"): if len(key["data"]["deploy"]) > 0: set_sequence = list() for deploy in key["data"]["deploy"]: set_deploy = deploy.split(".") set_stack = set_deploy[0] set_project = set_deploy[1] set_sequence.append([ new_init for new_init in init if (new_init["stack"] == set_stack) and ( new_init["project"] == set_project) ][0]) init = set_sequence utils.yaml_create("{}/deploy.yml".format(key["deploy_dir"]), init) return init
def setup_form(stack, project, parent=None): init = { "form": [{ "type": "TitleText", "name": "Name", "key": "name" }], "depend": [], "number": [], "stack": stack, "project": project, "parent": parent } if parent: init["parent"] = parent repo = utils.repodata()[stack][project] if utils.check_key(repo, "parameters"): param = repo["parameters"] param_index = utils.get_index(param) for index in param_index: prop = param[index] if not utils.check_key(prop, "default"): if not utils.check_key(prop, "dependences"): init["form"].append({ "type": "TitleText", "name": prop["label"], "key": index }) if prop["type"] == "number": init["number"].append(index) else: depend = prop["dependences"] if depend.split(":")[0] == "func": func_name = depend.split(":")[1] init["form"].append({ "type": "TitleSelectOne", "name": prop["label"], "key": index, "scroll_exit": True, "values": globals()[func_name](), "max_height": 7, "value": [ 0, ] }) if depend.split(":")[0] == "repo": repo_name = depend.split(":")[1] init["depend"].append({ "name": prop["label"], "key": index, "repo": repo_name }) return init
def setup_form(stack, project, parent=None): init = { "form": [{ "type": "TitleText", "name": "Name", "key": "name" }], "depend": [], "number": [], "stack": stack, "project": project, "parent": parent } if parent: init["parent"] = parent repo = utils.repodata()[stack][project] if utils.check_key(repo, "parameters"): param = repo["parameters"] param_index = utils.get_index(param) for index in param_index: prop = param[index] if not utils.check_key(prop, "default"): if not utils.check_key(prop, "dependences"): init["form"].append({ "type": "TitleText", "name": prop["label"], "key": index }) if prop["type"] == "number": init["number"].append(index) else: depend = prop["dependences"] if depend.split(":")[0] == "func": func_name = depend.split(":")[1] init["form"].append({ "type": "TitleSelectOne", "name": prop["label"], "key": index, "scroll_exit": True, "values": globals()[func_name](), "max_height": 7, "value": [ 0, ] }) if depend.split(":")[0] == "repo": repo_name = depend.split(":")[1] init["depend"].append({ "name": prop["label"], "key": index, "repo": repo_name }) return init
def get_stack(): try: d_stack = utils.get_index(utils.repodata()) f_stack = [{ "type": "TitleSelectOne", "name": "Select Stack ", "key": "stack", "values": d_stack, }] stack = utils.prompt_generator("", f_stack) return stack[f_stack[0]["key"]] except: return None
def get_project(templates): try: d_template = utils.get_index(utils.repodata()[templates]) f_template = [{ "type": "TitleSelectOne", "name": "-------------------", "key": "template", "values": d_template, }] template = utils.prompt_generator("Select Templates ", f_template) return template[f_template[0]["key"]] except: return None
def get_stack(): d_stack = utils.get_index(utils.repodata()) f_stack = [{ "type": "TitleSelectOne", "name": "Select Stack :", "key": "stack", "values": d_stack, }] stack = utils.form_generator("Stack list", f_stack) try: return d_stack[stack["stack"].value[0]] except: return None
def get_project(templates): d_template = utils.get_index(utils.repodata()[templates]) f_template = [{ "type": "TitleSelectOne", "name": "Select template :", "key": "template", "values": d_template, }] template = utils.form_generator("Templates", f_template) try: return d_template[template["template"].value[0]] except: return None
def get_project(templates): d_template = utils.get_index(utils.repodata()[templates]) f_template = [ { "type": "TitleSelectOne", "name": "Select template :", "key": "template", "values": d_template }, ] template = utils.form_generator("Templates", f_template) try: return (d_template[template["template"].value[0]]) except: return None
def get_stack(): d_stack = utils.get_index(utils.repodata()) f_stack = [ { "type": "TitleSelectOne", "name": "Select Stack :", "key": "stack", "values": d_stack }, ] stack = utils.form_generator("Stack list", f_stack) try: return d_stack[stack["stack"].value[0]] except: return None
def test_repodata_and_get_index(self): repodata = utils.repodata() indexes = utils.get_index(repodata) assert set(["clusters", "networks"]).issubset(indexes)
def setup_form(stack, project, parent=None): init = { "form": [], "depend": [], "number": [], "stack": stack, "project": project, "parent": parent, } if parent: init["parent"] = parent repo = utils.repodata()[stack][project] default_form_name = {"type": "TitleText", "name": "Name", "key": "name"} if utils.check_key(repo, "lists"): repo_lists = repo["lists"] """ if type of 'repo_list' is list """ if isinstance(repo_lists, list): init["form"].append({ "type": "TitleSelect", "name": "Name", "key": "name", "values": repo_lists, }) else: """ if type of 'repo_list' is string """ repo_lists = globals()[repo["lists"]]() if len(repo_lists) > 0: init["form"].append({ "type": "TitleSelect", "name": "Name", "key": "name", "values": repo_lists, }) else: init["form"].append(default_form_name) else: init["form"].append(default_form_name) if utils.check_key(repo, "parameters"): param = repo["parameters"] param_index = utils.get_index(param) for index in param_index: prop = param[index] if not utils.check_key(prop, "default"): if not utils.check_key(prop, "dependences"): init["form"].append({ "type": "TitleText", "name": prop["label"], "key": index }) if prop["type"] == "number": init["number"].append(index) else: depend = prop["dependences"] if depend.split(":")[0] == "func": func_name = depend.split(":")[1] init["form"].append({ "type": "TitleSelectOne", "name": prop["label"], "key": index, "scroll_exit": True, "values": globals()[func_name](), "max_height": 7, "value": [0], }) if depend.split(":")[0] == "repo": repo_name = depend.split(":")[1] init["depend"].append({ "name": prop["label"], "key": index, "repo": repo_name }) return init