Пример #1
0
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
Пример #2
0
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
Пример #3
0
def get_img():
    img_file = "/tmp/.images.yml"
    if os.path.exists(img_file):
        imgs = utils.yaml_parser(img_file)["data"]
    else:
        imgs = list(reversed([img.name for img in list(image.get_list())]))
        utils.yaml_create(img_file, {"data": imgs})
    return imgs
Пример #4
0
def get_img():
    # utils.log_info("Get images data...")
    img_file = "/tmp/.images.yml"
    if os.path.exists(img_file):
        imgs = utils.yaml_parser(img_file)["data"]
    else:
        imgs = list(reversed([img.name for img in list(image.get_list())]))
        utils.yaml_create(img_file, {"data": imgs})
    return imgs
Пример #5
0
def get_img():
    temp = utils.tmp_dir()
    img_file = os.path.join(temp, "images.yml")
    if os.path.exists(img_file):
        imgs = utils.yaml_parser(img_file)["data"]
    else:
        imgs = list(reversed([img.name for img in list(image.get_list())]))
        utils.yaml_create(img_file, {"data": imgs})
    return imgs
Пример #6
0
def get_flavor():
    flavor_file = "/tmp/.flavor.yml"
    if os.path.exists(flavor_file):
        flavors = utils.yaml_parser(flavor_file)["data"]
    else:
        flavors = list(
            reversed(sorted([flavor.name for flavor in list(vm.get_flavor())]))
        )
        utils.yaml_create(flavor_file, {"data": flavors})
    return flavors
Пример #7
0
def get_flavor():
    # utils.log_info("Get flavors data...")
    flavor_file = "/tmp/.flavor.yml"
    if os.path.exists(flavor_file):
        flavors = utils.yaml_parser(flavor_file)["data"]
    else:
        flavors = list(
            reversed(
                sorted([flavor.name for flavor in list(vm.get_flavor())])))
        utils.yaml_create(flavor_file, {"data": flavors})
    return flavors
Пример #8
0
def init(stack=None, project=None):
    select_stack = stack
    while not select_stack:
        select_stack = get_stack()

    select_project = project
    while not select_project:
        select_project = get_project(select_stack)

    fields = exec_form(select_stack, select_project)

    data = list()

    for field in fields["init"]:
        f_field = eval(str(field["form"]))
        validate = False
        while not validate:
            f_form = eval(str(field["form"]))
            form = utils.form_generator("Setup {}".format(field["project"]),
                                        f_form)
            for k, v in form.items():
                if isinstance(v.value, list):
                    for role in f_field:
                        if role["key"] == k:
                            form[k] = role["values"][v.value[0]]
                else:
                    form[k] = v.value

            if field["parent"]:
                form["parent"] = field["parent"]
            else:
                form["parent"] = None
            form["stack"] = field["stack"]
            form["template"] = field["project"]
            """ Check if data is null """
            null_data = 0
            for k_data, v_data in form.items():
                if v_data == "":
                    null_data += 1
                if len(field["number"]) > 0:
                    if k_data in field["number"]:
                        if utils.isint(v_data):
                            form[k_data] = int(v_data)
                        elif utils.isfloat(v_data):
                            form[k_data] = float(v_data)
                        else:
                            null_data += 1

            if null_data == 0:
                validate = True
                data.append(form)

    utils.yaml_create("neo.yml", dump(data))
    return utils.read_file("neo.yml")
Пример #9
0
def init(stack=None, project=None):
    select_stack = stack
    while not select_stack:
        select_stack = get_stack()

    select_project = project
    while not select_project:
        select_project = get_project(select_stack)

    fields = exec_form(select_stack, select_project)

    data = list()

    for field in fields["init"]:
        f_field = eval(str(field["form"]))
        validate = False
        while not validate:
            f_form = eval(str(field["form"]))
            form = utils.form_generator("Setup {}".format(field["project"]),
                                        f_form)
            for k, v in form.items():
                if isinstance(v.value, list):
                    for role in f_field:
                        if role["key"] == k:
                            form[k] = role["values"][v.value[0]]
                else:
                    form[k] = v.value

            if field["parent"]:
                form["parent"] = field["parent"]
            else:
                form["parent"] = None
            form["stack"] = field["stack"]
            form["template"] = field["project"]
            """ Check if data is null """
            null_data = 0
            for k_data, v_data in form.items():
                if v_data == "":
                    null_data += 1
                if len(field["number"]) > 0:
                    if k_data in field["number"]:
                        if utils.isint(v_data):
                            form[k_data] = int(v_data)
                        elif utils.isfloat(v_data):
                            form[k_data] = float(v_data)
                        else:
                            null_data += 1

            if null_data == 0:
                validate = True
                data.append(form)

    utils.yaml_create("neo.yml", dump(data))
    return utils.read_file("neo.yml")
Пример #10
0
def get_flavor():
    temp = utils.tmp_dir()
    flavor_file = os.path.join(temp, "flavor.yml")
    if os.path.exists(flavor_file):
        flavors = utils.yaml_parser(flavor_file)["data"]
    else:
        flavors = list(
            reversed(sorted([flavor.name
                             for flavor in list(vm.get_flavor())])))
        utils.yaml_create(flavor_file, {"data": flavors})
    return flavors
Пример #11
0
def init(stack=None, project=None):
    select_stack = stack
    if not select_stack:
        select_stack = get_stack()

    select_project = project
    if not select_project:
        select_project = get_project(select_stack)

    fields = exec_form(select_stack, select_project)

    data = list()

    for field in fields["init"]:
        validate = False
        while not validate:
            f_form = eval(str(field["form"]))
            name_type = f_form[0]
            """
                Generate form if just_child_val is False
            """
            if name_type["type"] == "TitleSelect":
                name_values = name_type["values"]
                form = utils.prompt_generator(
                    "Setup {}".format(field["project"]), [name_type])
                if form["name"] in name_values:
                    form["just_child_val"] = True
                    validate = True
                else:
                    new_form = eval(str(field["form"]))
                    del new_form[0]
                    new_form_val = utils.prompt_generator(
                        "Setup {}".format(field["project"]), new_form)
                    form.update(new_form_val)
                    form["just_child_val"] = False
            else:
                form = utils.prompt_generator(
                    "Setup {}".format(field["project"]), f_form)
                form["just_child_val"] = False

            if field["parent"]:
                form["parent"] = field["parent"]
            else:
                form["parent"] = None

            if not form["just_child_val"]:
                form["stack"] = field["stack"]
                form["template"] = field["project"]
                """ Check if data is null """
                null_data = 0
                for k_data, v_data in form.items():
                    if v_data == "":
                        null_data += 1
                    if len(field["number"]) > 0:
                        if k_data in field["number"]:
                            if utils.isint(v_data):
                                form[k_data] = int(v_data)
                            elif utils.isfloat(v_data):
                                form[k_data] = float(v_data)
                            else:
                                null_data += 1

                if null_data == 0:
                    validate = True

            if validate:
                data.append(form)

    if os.name == "nt":
        os.system("cls")
    else:
        os.system("clear")
    utils.yaml_create("neo.yml", dump(data))
    return utils.read_file("neo.yml")