Exemplo n.º 1
0
def init_lb_list():
    lb_list = utils.send_request("GET", consts.URLS["get_lb"])
    for lb in lb_list:
        # lb_ft = get_lb_frontends(lb["name"])
        filename = utils.get_current_folder(
        ) + consts.Prefix["lb_name_prefix"] + lb["name"]
        utils.file_writer(filename, lb)
Exemplo n.º 2
0
def init_cm_handler(svc_detail):
    svc_name = svc_detail["service_name"].lower()
    svc_uuid = svc_detail["uuid"]
    mount_points = svc_detail["mount_points"]
    cm_data = {}
    cm_name_pre = utils.get_current_folder() + consts.Prefix["cm_name_prefix"]
    if svc_detail["app_name"]:
        cm_name_pre = cm_name_pre + consts.Prefix["app_cm_flag_file"]
    for mp in mount_points:
        print "init configMap for service {}".format(svc_name)
        cm_name = cm_name_pre + svc_uuid

        if mp["type"] == "config":
            value = mp["value"]
            key = value["key"]
            conf_file_name = value["name"]
            data = utils.send_request(
                "GET", consts.URLS["get_config_content"].format(
                    filename=conf_file_name))
            print "config file {} response is ".format(conf_file_name)
            print data
            if "content" in data:
                for item in data["content"]:
                    if item["key"] == key:
                        content = item["value"]
                        cm_data[key] = content
        elif mp["type"] == "raw" or mp["type"] == "text":
            key = "key" + mp["path"].replace("/", "-")
            content = mp["value"]
            cm_data[key] = content
        else:
            raise "Unknown config type " + mp["type"]
        utils.file_writer(cm_name, cm_data)
Exemplo n.º 3
0
def trans_app_data(app):
    app_data = {
        "resource": {
            "create_method": "UI"
        },
        "kubernetes": []
    }
    app_data["resource"]["name"] = consts.Prefix["app_name_prefix"] + app["app_name"].lower()

    app_namespace_name = app["app_name"] + "-" + app["space_name"] if app["space_name"] else "default"

    app_data["namespace"] = {
        "name": app_namespace_name,
        "uuid": namespaces.get_alauda_ns_by_name(app_namespace_name)["uid"]
    }
    app_data["cluster"] = {
        "name": app["region_name"],
        "uuid": app["region_uuid"]
    }
    for app_service in app["services"]:
        app_service_detail = get_app_service_detail(app_service["uuid"].lower())
        app_data["kubernetes"].extend(services.trans_pod_controller(app_service_detail))
        if len(app_service_detail["mount_points"]) > 0:
            app_data["resource"]["create_method"] = "yaml"
    app_create_data_file = utils.get_current_folder() + consts.Prefix["app_create_data_prefix"] + app["app_name"]
    utils.file_writer(app_create_data_file, app_data)
    return app_data
Exemplo n.º 4
0
def init_svc_lb():
    svc_list = services.get_service_list()
    get_lb_url = consts.URLS["get_lb"]
    for svc in svc_list:
        url = get_lb_url + "&service_id=" + svc["uuid"]
        svc_lb_data = utils.send_request("GET", url)
        filename = utils.get_current_folder(
        ) + consts.Prefix["lb_name_prefix"] + svc["service_name"].lower()
        utils.file_writer(filename, svc_lb_data)
Exemplo n.º 5
0
def init_app_svc_lb():
    app_list = applications.get_app_list()
    get_lb_url = consts.URLS["get_lb"]
    for app in app_list:
        for app_svc in app["services"]:
            url = get_lb_url + "&service_id=" + app_svc["uuid"]
            svc_lb_data = utils.send_request("GET", url)
            filename = utils.get_current_folder() + consts.Prefix[
                "lb_name_prefix"] + app_svc["service_name"].lower()
            utils.file_writer(filename, svc_lb_data)
Exemplo n.º 6
0
def init_pipeline():
    all_pips = get_all_pipelines_for_current_project()
    cache_task_types = ["update-service", "exec", "manual-control", ""]
    for pl in all_pips:
        pipeline = get_pipeline_detail(pl["uuid"])
        if "tasks" in pipeline["stages"][0]:
            tasks = pipeline["stages"][0]["tasks"]
            for task in tasks:
                if task["type"] in cache_task_types:
                    cache_pl_file = utils.get_current_folder() + consts.Prefix[
                        "pipeline_name_prefix"] + pipeline["name"]
                    utils.file_writer(cache_pl_file, pipeline)
Exemplo n.º 7
0
def svc_detail_handler(svc):
    current_folder = utils.get_current_folder()
    prefix = consts.Prefix["app_service_detail_file"] if svc[
        "app_name"] else consts.Prefix["service_detail_file"]
    file_name_id = current_folder + prefix + svc["uuid"]
    file_name_svc_name = current_folder + prefix + svc["service_name"].lower()
    svc_detail = utils.send_request(
        "GET",
        consts.URLS["get_or_delete_svc_detail"].format(service_id=svc["uuid"]))
    utils.file_writer(file_name_id, svc_detail)
    # detail for svc_name
    utils.file_writer(file_name_svc_name, svc_detail)
Exemplo n.º 8
0
def main():
    app_list = get_app_list()
    for app in app_list:
        app_name = app["app_name"].lower()
        app_status = app["current_status"]

        task_single_app = "trans_app_{app_id}_{app_name}".format(app_id=app["uuid"], app_name=app_name)
        if utils.no_task_record(task_single_app):
            # skipped excluded services in consts.ExcludedServiceNames
            if app_name in consts.ExcludedApps:
                print "skipped app {} because configed in consts.ExcludedApps".format(app_name)
                continue
            if app_status not in consts.IncludeAppStatus:
                raw_tips = "{app_name} status is {app_status}, input Yes/No for continue or skip ". \
                    format(app_name=app_name, app_status=app_status)
                answer = raw_input(raw_tips)
                if answer.lower() == "no":
                    print "skipped app {} because current_status is {}".format(app_name, app_status)
                    continue
            print "begin trans application data to new app data for application {}".format(app_name)
            app_data = trans_app_data(app)
            print "app data for application {}".format(app_name)
            print app_data
            print "\nbegin delete application old application {}".format(app_name)
            delete_old_application(app["uuid"])
            print "\nwaiting application {} for delete ".format(app_name)
            for count in range(50):
                time.sleep(3)
                v1_application_info = get_v1_app_by_api(app["uuid"])
                if isinstance(v1_application_info, dict) and "errors" in v1_application_info:
                    print "\n app {} delete done".format(app_name)
                    break

            print "\nbegin create app for application {} ".format(app_name)
            app_info = services.create_app(app_data)
            if isinstance(app_info, dict) and "errors" in app_info:
                search_apps = services.get_app_by_name(app_data["resource"]["name"])
                if len(search_apps) == 0:
                    exit("create app error!!!!")
                app_info = search_apps[0]
            is_running = True
            if app_status not in ["Running", "Warning"]:
                is_running = False
                content = "{}-{}-{}\n".format(utils.get_current_project(), app_name, app_status)
                utils.file_writer("not_running_app.list", content, "a+")
                print "app {} current status is {}, will not waiting for created done".format(app_name,app_status)
            if consts.Configs["wait_for_create_done"] and is_running:
                # print app_info
                print "\nwaiting new app {} for create ".format(app_name)
                create_done = False
                for count in range(50):
                    time.sleep(3)
                    app = services.get_app_by_api(app_info["resource"]["uuid"])
                    app_current_state = app["resource"]["status"]
                    if app_current_state == "Running":
                        print "\n app {} create done".format(app_name)
                        create_done = True
                        break
                    else:
                        print "\n app {} current status is {}, continue waiting...".format(app_name, app_current_state)
                if not create_done:
                    print "application create too slow , please check!"
                    # exit(1)
                if create_done and consts.Configs["update_app"]:
                    # begin update app for bind old tag
                    app = services.get_app_by_api(app_info["resource"]["uuid"])
                    update_done = False
                    services.update_app(app)
                    print "\nwaiting app {} for update ".format(app_name)
                    for count in range(50):
                        time.sleep(3)
                        app = services.get_app_by_api(app_info["resource"]["uuid"])
                        app_current_state = app["resource"]["status"]
                        if app_current_state == "Running":
                            print "\n app {} update done".format(app_name)
                            update_done = True
                            break
                        else:
                            print "\n app {} current status is {}, continue waiting...".format(app_name,
                                                                                               app_current_state)
                    if not update_done:
                        print "application update too slow , please check!"
                        # exit(1)
            else:
                time.sleep(3)
            # handle lb binding
            for app_service in app["services"]:
                if "resource" in app_service and "name" in app_service["resource"]:
                    lb.handle_lb_for_svc(app_service["resource"]["name"].lower())
                elif "service_name" in app_service:
                    lb.handle_lb_for_svc(app_service["service_name"].lower())
            # if service_status == "Stopped":
            #    app_id = app_info["resource"]["uuid"]
            #    utils.send_request("PUT", consts.URLS["stop_app"].format(app_id=app_id))
            utils.task_record(task_single_app)
            print "!!!!!Status Confirm: old app status is {}, " \
                  "please check if should change by hands".format(app_status)
            exit(1)
Exemplo n.º 9
0
def init_app_list():
    app_list = get_app_list_for_current_project(results=[])
    file_name = utils.get_current_folder() + consts.Prefix["app_list_file"]
    utils.file_writer(file_name, app_list)
Exemplo n.º 10
0
from fantz import *
from utils.utils import file_reader, file_writer

INPUT_FILE_LOCATION = 'data/fantz1.in'
OUTPUT_FILE_LOCATION = 'fantz.out'

if __name__ == '__main__':
    binary_number, decimal_number = file_reader(INPUT_FILE_LOCATION)
    result = fantz_launcher(str(binary_number), int(decimal_number))
    print(f'Binary number: {binary_number}  Decimal number: {decimal_number} \n'
          f'Replaces amount: {result}')
    file_writer(OUTPUT_FILE_LOCATION, result)
Exemplo n.º 11
0
def create_app(data):
    url = consts.URLS["create_app"]
    app_create_data_file = utils.get_current_folder(
    ) + consts.Prefix["app_create_data_prefix"] + data["resource"]["name"]
    utils.file_writer(app_create_data_file, data)
    return utils.send_request("POST", url, data)
Exemplo n.º 12
0
def init_svc_list():
    svc_list = get_svc_list_for_current_project(results=[])
    file_name = utils.get_current_folder() + consts.Prefix["service_list_file"]
    utils.file_writer(file_name, svc_list)