Ejemplo n.º 1
0
def check_dir(path, filename, info_list = [1,0,0,0], fp = ""):
    #パスとファイルの存在確認
    path, filename = check_dir_existence(path = path, filename = filename, info_list = info_list, fp = fp)
    
    #パスのアクセス確認
    while(True):
        index_1 = os.access(path,os.R_OK)
        index_2 = os.access(path,os.W_OK)
        index_3 = os.access(path,os.X_OK)
        
        if(index_1 == False or index_2 == False or index_3 == False):
            logger.error('PermissionError: the specified directory cannot be accessed')
            _ = printout("PermissionError: the specified directory cannot be accessed.", info_type = 0, info_list = info_list, fp = fp)
            out_path = printout("Please specify the other directory >>>", info_type = 1, info_list = info_list, fp = fp)
            if((".js" in out_path.split("/")[-1]) or (".json" in out_path.split("/")[-1])):
                filename = os.path.basename(out_path)
                out_path = os.path.dirname(out_path)
                logger.debug('New directory and filename are set')
                
            else:
                filename = "config.json"
                path = out_path
                logger.debug('New directory is set')
                logger.debug('The config filename is automatically set to config.json')
                
            #パスとファイルの存在確認
            path, filename = check_dir_existence(path = path, filename = filename, info_list = info_list, fp = fp)
               
        else:
            return path, filename
Ejemplo n.º 2
0
def config_loading_main(ext_info, in_path = "", info_list = [1,0,0,0], fp = ""):
    logger.debug('loading config params')
    _ = printout("loading config params ...", info_list = info_list, fp = fp)
    
    while(True):
        _, ext = os.path.splitext(in_path)
            
        if(os.path.isfile(in_path) == True and (ext == ".json" or ext == ".js")):
            try:
                with open(in_path, 'r') as f:
                    json_f = json.load(f)
                break
                
            except PermissionError as e:
                logger.error('PermissionError: the specified path cannot be accessed')
                _ = printout("PermissionError: the specified path cannot be accessed.", info_type = 0, info_list = info_list, fp = fp)
                #while(True):
                logger.debug('request new path')
                in_path = printout("New path >>", info_type = 1, info_list = info_list, fp = fp)
                   
        else:
            logger.error('FileImportError: the file did not load properly')
            _ = printout("FileImportError: config params can not be loaded. Please specify the json file.", info_list = info_list, fp = fp)
            in_path = printout("New path >>", info_type = 1, info_list = info_list, fp = fp)

    logger.debug('Start checking the config param')
    config_param = config_validation(ext_info, json_f, info_list = info_list, fp = fp)

    return config_param
Ejemplo n.º 3
0
def prior_ps(args):
    if (args.verbose == True):
        logger.debug('Change log level to debag')
        file_handler.setLevel(logging.DEBUG)
        logger.addHandler(file_handler)

    if (args.output == True):
        logger.debug('Create a file for standard output')
        dt_now = datetime.datetime.now()
        fp_filename = dt_now.strftime('%Y_%m_%d_%H_%M_%S.txt')
        #os.
        f = open(home_path + "/res/" + fp_filename, "w")
        info_list = [1, 0, 0, 1]
    else:
        f = ""
        info_list = [1, 0, 0, 0]

    ps_main(args.dryrun, f, info_list)

    if (args.output == True):
        printout("Processes for building the cluster were completed",
                 info_type=0,
                 info_list=[1, 0, 0, 1],
                 fp=f)
        logger.debug('Close a file for standard output')
        f.close()
Ejemplo n.º 4
0
def make_dirs(path, filename, info_list = [1,0,0,0], fp = ""):
    
    while(True):
        #ディレクトリの作成
        try:
            logger.debug('Making directories to save config file')
            _ = printout("Making a directory to save config file...", info_type = 0, info_list = info_list, fp = fp)
            os.makedirs(path, exist_ok = True)
            break
            
        #ディレクトリにアクセスできない場合(認証設定がされている場合)
        except PermissionError as e:
            logger.error('PermissionError: the specified directory cannot be accessed')
            _ = printout("PermissionError: the specified directory cannot be accessed.", info_type = 0, info_list = info_list, fp = fp)
            
            #再度pathを要求
            logger.debug('re-difine the path to output config params')
            out_path = printout("Please specify the other directory >>>", info_type = 1, info_list = info_list, fp = fp)
            
            #config fileの拡張子を確認
            logger.debug('Checking the extension of the config file')
            #パス内にファイル名が含まれている場合
            if((".js" in out_path.split("/")[-1]) or (".json" in out_path.split("/")[-1])):
                filename = os.path.basename(out_path)
                path = os.path.dirname(out_path)
                logger.debug('Directory and filename are set')
            #パス内にファイル名が含まれていない場合
            else:
                filename = "config.json"
                path = out_path
                logger.debug('New directory is set')
                logger.debug('The config filename is automatically set to config.json')
               
    return path, filename
Ejemplo n.º 5
0
def config_validation(ext_info, config_param, info_list = [1,0,0,0], fp = ""):
    logger.debug('load config checker')
    checker = load_config_checker(info_list = info_list, fp = fp)
    all_zone = list(ext_info["Zone"].keys())
    main_checker = checker["main checker"]
    
    main_checker["properties"]["NFS"]["properties"]["NFS zone"]["properties"] = dict(zip(all_zone, [checker["NFS_zone_checker"] for i in range(len(all_zone))]))
    main_checker["properties"]["Zone"]["properties"]["Zone"]["properties"] = dict(zip(all_zone, [checker["Zone_checker"] for i in range(len(all_zone))]))
    main_checker["properties"]["Compute"]["properties"]["Compute node"]["properties"]["OS"]["properties"]["OSPlan"]["properties"] = dict(zip(all_zone, [checker["OS_checker"] for i in range(len(all_zone))]))
    main_checker["properties"]["Head"]["properties"]["OS"]["properties"]["OSPlan"]["properties"] = dict(zip(all_zone, [checker["OS_checker"] for i in range(len(all_zone))]))
    
    try:
        logger.debug('Checking config params')
        _ = printout("Checking config params ...", info_type = 0, info_list = info_list, fp = fp)
        logger.debug('Checking the type and existence of config params')
        validate(config_param, main_checker)
        logger.debug('Checking details of config params')
        checking_config_details(ext_info, config_param, info_list = info_list, fp = fp)
        
        
    except ValidationError as e:
        logger.error('ConfigError: definition of config parameters is wrong')
        logger.error(e.message)
        
        _ = printout("ConfigError: definition of config parameters is wrong", info_type = 0, info_list = info_list, fp = fp)
        _ = printout(e.message, info_type = 0, info_list = info_list, fp = fp)
        
        config_param = redefine_config(ext_info, info_list = info_list, fp = fp)
    
    return config_param
Ejemplo n.º 6
0
def conf_pattern_4(comment,
                   min_val,
                   max_val,
                   default,
                   info_list=[1, 0, 0, 1],
                   fp=""):
    while (True):
        val = printout("[" + str(comment) + " {" + str(min_val) + "~" +
                       str(max_val) + "}, (default: " + str(default) +
                       ")] >> ",
                       info_type=1,
                       info_list=info_list,
                       fp=fp).replace(" ", "")

        if (val == ""):
            return default

        elif (val.isdecimal() == False):
            _ = printout("Warning: " + comment + " must be number from " +
                         str(min_val) + " to " + str(max_val),
                         info_type=0,
                         info_list=info_list,
                         fp=fp)

        elif (min_val <= int(val) <= max_val):
            return int(val)

        else:
            _ = printout("Warning: " + comment + " must be number from " +
                         str(min_val) + " to " + str(max_val),
                         info_type=0,
                         info_list=info_list,
                         fp=fp)
Ejemplo n.º 7
0
def check_filename(path, filename, info_list = [1,0,0,0], fp = ""):
    index = 0
    file_list = os.listdir(path)
    
    logger.debug('Checking filename')
    printout("Checking filename...", info_type = 0, info_list = info_list, fp = fp)
    if(filename in file_list):
        if(filename != "config.json"):
            index = 1
            filename = "config.json"
            logger.warining("the specified filename exists in the directory")
            _ = printout("Warning: the specified filename exists in the directory.", info_type = 0, info_list = info_list, fp = fp)
            
        count = 2
        while(True):
            if(filename not in file_list):
                break
            filename = "config_" + str(count) + ".json"
            count += 1
        
        if(index == 1):
            logger.info("filename changed to " + filename)
            _ = printout("INFO:filename change to " + filename, info_type = 0, info_list = info_list, fp = fp)
            
    return path, filename
Ejemplo n.º 8
0
def redefine_monitor_token(token_name, info_list=[1, 0, 0, 0], fp=""):
    while (True):
        res = printout(
            "Would you like to request a resend of the authorization code? (yes or no) >>",
            info_type=1,
            info_list=info_list,
            fp=fp)
        if (res == "yes" or res == "no" or res == "y" or res == "n"):
            break
        else:
            logger.warning(
                'Warning: response is wrong (selection is yes or no)')
            res = printout("Warning: Please select yes (y) or no (n).",
                           info_type=0,
                           info_list=info_list,
                           fp=fp)

    if (res == "yes" or res == "y"):
        logger.debug('resend authorization code')
        return "", True
    else:
        newer = str(
            printout("Please input new " + token_name + " >>",
                     info_type=1,
                     info_list=info_list,
                     fp=fp))
        logger.debug('Specify a new monitor space')
        return newer, False
Ejemplo n.º 9
0
def conf_pattern_2(comment,
                   candidates,
                   default,
                   info_list=[1, 0, 0, 1],
                   fp=""):
    while (True):
        val = printout("[" + str(comment) + " {" + ",".join(candidates) +
                       "}, (default: " + str(default) + ")] >> ",
                       info_type=1,
                       info_list=info_list,
                       fp=fp).replace(" ", "")

        if (val == ""):
            return default

        else:
            if (val in candidates):
                return val

            else:
                _ = printout("Warning: " + comment +
                             " must be selected one from " +
                             ",".join(candidates),
                             info_type=0,
                             info_list=info_list,
                             fp=fp)
Ejemplo n.º 10
0
def load_config_checker(info_list = [1,0,0,0], fp = ""):
    _ = printout("loading config checker ...", info_type = 0, info_list = info_list, fp = fp)
    try:
        with open(path + "/lib/.Ex_info/config_checker.json", "r") as f:
            data = json.load(f)
    
    except FileNotFoundError as e:
        _ = printout("EnvironmentalError: config_checker.json does not exist under sacluster/lib/.Ex_info\nYou should install sacluster from url", info_type = 0, info_list = info_list, fp = fp)
        sys.exit()
        
    return data
Ejemplo n.º 11
0
    def shutdown_peripheral_zone(self, zone):
        logger.debug("Shutdown " + zone + " zone")

        compute_node_id_list = []
        for i in self.cluster_info["clusterparams"]["server"][zone][
                "compute"].keys():
            if self.cluster_info["clusterparams"]["server"][zone]["compute"][
                    i]["node"]["state"] == "up":
                compute_node_id_list.append(
                    self.cluster_info["clusterparams"]["server"][zone]
                    ["compute"][i]["node"]["id"])

        #compute_node_id_list =  [self.cluster_info[self.cluster_id[0]]["cluster_params"]["server"][zone]["compute"][i]["node"]["id"] for i in self.cluster_info[self.cluster_id[0]]["cluster_params"]["server"][zone]["compute"].keys()]

        if not compute_node_id_list == []:
            with futures.ThreadPoolExecutor(
                    max_workers=self.max_workers,
                    thread_name_prefix="thread") as executor:
                for compute_node_id in compute_node_id_list:
                    #executor.submit(MulHelper(self, "build_one_compute_node"), kwargs={"zone": zone, "i": i})
                    printout("Shutdown compute zone(" + zone +
                             ") : compute node(" + str(compute_node_id) + ")",
                             info_type=0,
                             info_list=self.info_list,
                             fp=self.fp,
                             overwrite=True)
                    executor.submit(self.shutdown_server, zone,
                                    compute_node_id)
                    self.progress_bar(25 / 1 + len(compute_node_id_list))
            '''
            for compute_node_id in compute_node_id_list:
                printout("Shutdown compute zone(" + zone + ") : compute node(" + str(compute_node_id) + ")", info_type = 0, info_list = self.info_list, fp = self.fp, overwrite = True)
                self.shutdown_server(zone,compute_node_id)
                self.progress_bar(25/1+len(compute_node_id_list))
        '''

        if zone in self.nfs_zones:
            if (self.cluster_info["clusterparams"]["nfs"][zone] != None):
                if self.cluster_info["clusterparams"]["nfs"][zone][
                        "state"] == "up":
                    nfs_id = self.cluster_info["clusterparams"]["nfs"][zone][
                        "id"]
                    printout("Shutdown compute zone(" + zone + ") : NFS(" +
                             str(nfs_id) + ")",
                             info_type=0,
                             info_list=self.info_list,
                             fp=self.fp,
                             overwrite=True)
                    self.shutdown_nfs(zone, nfs_id)
                    self.progress_bar(10)
Ejemplo n.º 12
0
def prior_build(args):

    if (args.verbose == True):
        logger.debug('Change log level to debag')
        file_handler.setLevel(logging.DEBUG)
        logger.addHandler(file_handler)

    if (args.parents == True and args.dir == None):
        logger.error('--parents option [-p] requires --input option [-d]')
        print("error: --parents option [-p] requires --input option [-d] ")
        sys.exit()

    if (args.output == True):
        logger.debug('Create a file for standard output')
        dt_now = datetime.datetime.now()
        fp_filename = dt_now.strftime('%Y_%m_%d_%H_%M_%S.txt')
        #os.
        f = open(home_path + "/res/" + fp_filename, "w")
        info_list = [1, 0, 0, 1]
    else:
        f = ""
        info_list = [1, 0, 0, 0]

    if (args.input == None):
        args.input = ""
        logger.debug('Set config input path to None')
    else:
        logger.debug('Set config input path to ' + args.input)

    if (args.dir == None):
        args.dir = ""
        logger.debug('Set config output path to None')
    else:
        logger.debug('Set config output path to ' + args.dir)

    build_main(args.input, args.dir, args.parents, args.dryrun, f, info_list,
               args.auto, int(args.thread))

    if (args.output == True):
        printout("Processes for building the cluster were completed",
                 info_type=0,
                 info_list=[1, 0, 0, 1],
                 fp=f)
        logger.debug('Close a file for standard output')
        f.close()
    else:
        printout("All processes were completed",
                 info_type=0,
                 info_list=[1, 0, 0, 0],
                 fp="")
Ejemplo n.º 13
0
def redefine_config(ext_info, info_list = [1,0,0,0], fp = ""):
    while(True):
        res = printout("Do you want to redefine new config params (yes or no) >>", info_type = 1, info_list = info_list, fp = fp)
        if(res == "yes" or res == "no" or res == "y" or res == "n"):
            break
        else:
            res = printout("Warning: Please select yes (y) or no (n).", info_type = 0, info_list = info_list, fp = fp)
    
    if(res == "yes" or res == "y"):
        out_path = printout("Output path >>", info_type = 1, info_list = info_list, fp = fp)
        config_param = config_making_main(ext_info, out_path = out_path, info_list = info_list, fp = fp)
        return config_param
    else:
        _ = printout("ConfigError: config params cannot be loaded.", info_type = 0, info_list = info_list, fp = fp)
        sys.exit()
Ejemplo n.º 14
0
def conf_pattern_1(comment, info_list=[1, 0, 0, 1], fp=""):
    val = printout("[" + str(comment) + "] >> ",
                   info_type=1,
                   info_list=info_list,
                   fp=fp).replace(" ", "")

    return val
Ejemplo n.º 15
0
 def build_error(self):
     logger.debug("decision of repeating to request")
     while(True):
         conf = printout("Try again??(yes/no):", info_type = 2,info_list = self.info_list, fp = self.fp)
         #atexit.register(self.call_delete(self.all_id_dict,self.auth_res,self.max_workers,self.fp,self.info_list,self.api_index))
         if conf == "yes":
             break
         elif conf == "no":
             self.printout_cluster("Stop processing.", cls_monitor_level = 1)
             #sys.exit()
             
             self.call_delete(self.all_id_dict,self.auth_res,self.max_workers,self.fp,self.info_list,self.api_index)
             sys.exit()
                 
         else:
             _ = printout("Please answer yes or no.",info_list = self.info_list,fp = self.fp) 
def input_username(s, info_list=[1, 0, 0, 0], f=""):
    re_alnum = re.compile(r'^[a-z]{1}[-a-z0-9]{0,30}$')

    while (True):
        username = conf_pattern_1("username", info_list=info_list, fp=f)
        ans = re.search(re_alnum, username)

        if (ans != None):
            return username

        else:
            logger.debug('The username is wrong')
            printout(
                'The username is wrong. Username must be 32 characters long and consist of numbers, lowercase letters, and hyphens (Initial is a lowercase letter).',
                info_type=0,
                info_list=info_list,
                fp=f)
Ejemplo n.º 17
0
def stop_main(api_index, f, info_list,max_workers):
    logger.debug('Setting authentication info')
    auth_info = authentication_cli(fp = f, info_list  = info_list, api_index = api_index)
    
    logger.debug('loading external data')
    ext_info = external_data(auth_info, info_list = info_list, fp = f)
    
    logger.debug('Getting cluster information')
    params = get_params.get_params(ext_info, auth_info, info_list = info_list, f = f, api_index = api_index)
    params()
    params.show_cluster_info()
    
    index, cluster_id = get_cluster_id.get_cluster_id(params.cluster_info_all, info_list, f, api_index)
    
    if(index == True):
        logger.debug("Start stopping the cluster : " + str(cluster_id))
        printout("Start stopping the cluster : " + str(cluster_id), info_type = 0, info_list = info_list, fp = f)
        stop_obj = stop_class.stop_sacluster(params.cluster_info_all[cluster_id], auth_info, max_workers,fp = f, info_list = info_list, api_index = api_index)
        stop_obj()
        logger.debug("Finished stopping the cluster : " + str(cluster_id))
        printout("Finished stopping the cluster : " + str(cluster_id), info_type = 0, info_list = info_list, fp = f)
        
    else:
        logger.debug('There are no clusters to stop')
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
Ejemplo n.º 18
0
 def delete_error(self):
     logger.debug("decision of repeating to request")
     while (True):
         conf = printout("Try again??(yes/no):",
                         info_type=2,
                         info_list=self.info_list,
                         fp=self.fp)
         if conf == "yes":
             break
         elif conf == "no":
             printout("Stop processing.",
                      info_type=0,
                      info_list=self.info_list,
                      fp=self.fp)
             sys.exit()
         else:
             printout("Please answer yes or no.",
                      info_list=self.info_list,
                      fp=self.fp)
Ejemplo n.º 19
0
def def_config_name(fp="", info_list=[1, 0, 0, 0]):
    logger.debug('Start to define config name')
    while (True):
        config_name = conf_pattern_1(
            "Config name (Within 20 characters, default:config params)",
            info_list=info_list,
            fp=fp)
        if (config_name == ""):
            logger.debug('automatically config name is set to config prams')
            return "config params"
        elif (len(config_name) <= 20):
            logger.debug('config name is set')
            return config_name
        else:
            logger.debug('Character count over')
            printout("Warning: Please specify up to 20 characters.",
                     info_type=0,
                     info_list=info_list,
                     fp=fp)
Ejemplo n.º 20
0
def define_auth_info(path, info_list, api_index=True, fp=""):

    while (True):
        token = printout('[access token] >> ',
                         info_type=2,
                         info_list=info_list,
                         fp=fp)
        token_secret = printout('[access token secret] >> ',
                                info_type=2,
                                info_list=info_list,
                                fp=fp)
        logger.debug('Redifined authentication information')

        basic_user_and_pasword = base64.b64encode('{}:{}'.format(
            token, token_secret).encode('utf-8'))

        if (api_index == True):
            _ = printout("Checking the authentication information ...",
                         info_list=info_list,
                         fp=fp)
            logger.debug('Checking the authentication information')
            res = get(url + "/auth-status", basic_user_and_pasword)

            if ("Account" in res):
                break
            else:
                _ = printout("AuthenticationError: cannot access",
                             info_list=info_list,
                             fp=fp)
                logger.error('AuthenticationError: cannot access')
        else:
            break

    auth_res = basic_user_and_pasword
    _ = printout("Saving Setting.json ...", info_list=info_list, fp=fp)
    logger.debug('Saving the authentication information to Setting.json')
    json_output({
        "access token": token,
        "access token secret": token_secret
    }, path)

    return auth_res
Ejemplo n.º 21
0
def config_making_main(ext_info, out_path = "", make_dir_index = False, info_list = [1,0,0,0], fp = ""):
    
    if(out_path != ""):
        #configファイルの拡張子の確認
        logger.debug('Checking the extension of the config file')
        if((".js" in out_path.split("/")[-1]) or (".json" in out_path.split("/")[-1])):
            filename = os.path.basename(out_path)
            out_path = os.path.dirname(out_path)
            
            if(out_path == ""):
                logger.debug('The directory to be saved is automatically set to /config')
                out_path = common_path + "/config"
        else:
            logger.debug('The config filename was automatically set to config.json')
            filename = "config.json"
        
        #config file出力のためのディレクトリの作成
        if(make_dir_index == True):
            out_path, filename = make_dirs(out_path, filename, info_list = info_list, fp = fp)
        out_path, filename = check_dir(out_path, filename, info_list = info_list, fp = fp)
        out_path, filename = check_filename(out_path, filename, info_list = info_list, fp = fp)
        
    else:
        filename = "config.json"
        out_path = home_path + "/config"
        out_path, filename = check_filename(out_path, filename, info_list = info_list, fp = fp)
        
    _ = printout("Out directory:: " + str(out_path), info_type = 0, info_list = info_list, fp = fp)
    _ = printout("Out filename :: " + str(filename), info_type = 0, info_list = info_list, fp = fp)
    logger.debug('Out directory:: ' + str(out_path))
    logger.debug('Out filename ::' + str(filename))
    
    config_param = def_config_main(ext_info, fp = fp, info_list = info_list)
        
    logger.debug('save config params')
    out_config(filename, out_path, config_param)
        
    return config_param
Ejemplo n.º 22
0
def check_dir_existence(path, filename, info_list = [1,0,0,0], fp = ""):
    while(True):
        logger.debug('Checking the output directory')
        _ = printout("Checking the output directory...", info_type = 0, info_list = info_list, fp = fp)
        #ディレクトリの存在を確認
        index = os.path.exists(path)
        #ディレクトリが存在しない場合
        if(index == False):
            logger.error('DirNotFoundError: the specified directory cannot be found')
            _ = printout("DirNotFoundError: the specified directory cannot be found.", info_type = 0, info_list = info_list, fp = fp)
            temp = conf_pattern_2("Do you want to change the directory?? (if you choose no, the specified directory will be created)", ["yes", "no"], "no", info_list = info_list, fp = fp)
            
            #パスの再定義
            if(temp == "yes"):
                out_path = printout("Please specify the other directory >>>", info_type = 1, info_list = info_list, fp = fp)
                logger.debug('New Path was entered')
                logger.debug('Checking the extension of the config file')
                
                #パス内にファイル名が含まれている場合
                if((".js" in out_path.split("/")[-1]) or (".json" in out_path.split("/")[-1])):
                    filename = os.path.basename(out_path)
                    path = os.path.dirname(out_path)
                    logger.debug('New directory and filename are set')
                    
                #パス内にファイル名が含まれていない場合
                else:
                    filename = "config.json"
                    path = out_path 
                    logger.debug('New directory is set')
                    logger.debug('The config filename is automatically set to config.json')
               
            #ディレクトリを生成
            else:
                path, filename = make_dirs(path, filename, info_list = info_list, fp = fp)
        #ディレクトリが存在する場合
        else:
            logger.debug('Existence of specified file has been confirmed')
            return path, filename
Ejemplo n.º 23
0
def get_cluster_id(params, info_list, f, api_index=True):
    if (len(params) != 0):
        while (True):
            cluster_id = printout('[id] >>',
                                  info_type=1,
                                  info_list=info_list,
                                  fp=f)
            if (cluster_id in params):
                index = True
                break
            if (api_index == False):
                index = False
                break
            else:
                printout('InputError: the specified cluster id does not exist',
                         info_type=0,
                         info_list=info_list,
                         fp=f)
    else:
        cluster_id = ""
        index = False

    return index, cluster_id
Ejemplo n.º 24
0
def external_data(auth_info, info_list=[1, 0, 0, 0], fp=""):

    _ = printout("loading external information ...",
                 info_type=0,
                 info_list=info_list,
                 fp=fp)
    logger.debug('loading external information')

    try:
        with open(path + "/lib/.Ex_info/External_info.json", "r") as f:
            data = json.load(f)

    except FileNotFoundError as e:
        _ = printout(
            "EnvironmentalError: External_info.json does not exist under sacluster/lib/.Ex_info",
            info_type=0,
            info_list=info_list,
            fp=fp)
        logger.critical(
            'EnvironmentalError: External_info.json does not exist under sacluster/lib/.Ex_info'
        )
        sys.exit()

    return data
Ejemplo n.º 25
0
    def __call__(self):
        #progress barの設定
        self.bar = tqdm(total=100)
        self.bar.set_description('Progress rate')
        self.progress_sum = 0

        #2つ以上のゾーンを持つ時,ブリッジとスイッチの接続を切断
        #if len(self.zone_list) >= 2:
        if self.contents_bool["bridge"] == True and self.contents_bool[
                "switch"] == True:
            #if self.cluster_info["clusterparams"]["bridge"]["front"] != None:
            for zone in self.zone_list:
                connect_bool = self.get_bridge_info(zone, self.bridge_front_id)
                if connect_bool == True:
                    printout("Disconnect bridge and switch : " + zone +
                             " zone",
                             info_type=0,
                             info_list=self.info_list,
                             fp=self.fp,
                             overwrite=True)
                    self.disconnect_bridge_switch(
                        zone, self.front_switch_id_list[zone])
                    if self.bridge_back_id != None:
                        connect_bool = self.get_bridge_info(
                            zone, self.bridge_back_id)
                        if connect_bool == True:
                            self.disconnect_bridge_switch(
                                zone, self.back_switch_id_list[zone])
                    self.progress_bar(int(20 / len(self.zone_list)))

        if self.contents_bool["bridge"] == True:
            printout("Delete bridge: " + str(self.bridge_front_id),
                     info_type=0,
                     info_list=self.info_list,
                     fp=self.fp,
                     overwrite=True)
            self.delete_bridge(self.zone_list[0], self.bridge_front_id)
            if self.bridge_back_id != None:
                printout("Delete bridge: " + str(self.bridge_back_id),
                         info_type=0,
                         info_list=self.info_list,
                         fp=self.fp,
                         overwrite=True)
                self.delete_bridge(self.zone_list[0], self.bridge_back_id)
            self.progress_bar(10)

        #peripheral zone 削除
        for zone in self.zone_list:
            if zone != self.head_zone:
                self.delete_peripheral_zone(zone)

        if self.head_zone != None:
            self.delete_head_zone(self.head_zone)

        self.bar.update(100 - self.progress_sum)
        self.bar.close()
Ejemplo n.º 26
0
def set_parm(param_name, set_param, info_list=[1, 0, 0, 1], fp=""):
    if (isinstance(set_param, list) == True):
        _ = printout("Set " + str(param_name) + " to " + ",".join(set_param),
                     info_type=0,
                     info_list=info_list,
                     fp=fp)
        printout("", info_type=0, info_list=info_list, fp=fp)
    else:
        _ = printout("Set " + str(param_name) + " to " + set_param,
                     info_type=0,
                     info_list=info_list,
                     fp=fp)
        printout("", info_type=0, info_list=info_list, fp=fp)
Ejemplo n.º 27
0
def conf_stop_process(info_list, f):
    while (True):
        printout("INFO: instruments are not stopped",
                 info_type=0,
                 info_list=info_list,
                 fp=f)
        val = printout("[Can instruments be stopped? {yes(y) / no(n)}] >> ",
                       info_type=1,
                       info_list=info_list,
                       fp=f).replace(" ", "")
        if (val == "yes" or val == "y"):
            return True
        elif (val == "no" or val == "n"):
            printout(
                "Warning: instruments must be stopped. This process is stopped.",
                info_type=0,
                info_list=info_list,
                fp=f)
            sys.exit()
        else:
            printout("Warning: The input is an unexpected value",
                     info_type=0,
                     info_list=info_list,
                     fp=f)
Ejemplo n.º 28
0
    def res_check(self, res, met):
        met_dict = {
            "get": "is_ok",
            "post": "is_ok",
            "put": "Success",
            "delete": "Success"
        }
        index = met_dict[met]

        logger.debug("confirm API request(" + str(met) + ")")
        if (index in res.keys()):
            if res[index] == True:
                logger.debug("API processing succeeded")
                check = True
                return check
            else:
                logger.warning("API processing failed")
                printout("Error:",
                         info_type=0,
                         info_list=self.info_list,
                         fp=self.fp)
                check = False
                return check

        elif ("is_fatal" in res.keys()):
            logger.warning("API processing failed")
            printout("Status:" + res["status"],
                     info_type=0,
                     info_list=self.info_list,
                     fp=self.fp)
            printout("Error:" + res["error_msg"],
                     info_type=0,
                     info_list=self.info_list,
                     fp=self.fp)
            check = False
            return check
Ejemplo n.º 29
0
def conf_pattern_3(comment, candidate, default, info_list=[1, 0, 0, 1], fp=""):
    pos_index = 5
    if (len(candidate) <= pos_index):
        while (True):
            printout("[[" + str(comment) + "]]",
                     info_type=0,
                     info_list=info_list,
                     fp=fp)
            printout(str(0) + ": " + str(candidate[0]) + " (default)",
                     info_type=0,
                     info_list=info_list,
                     fp=fp)
            for i in range(1, len(candidate)):
                printout(str(i) + ": " + str(candidate[i]),
                         info_type=0,
                         info_list=info_list,
                         fp=fp)

            val = printout(">>>", info_type=1, info_list=info_list, fp=fp)
            printout("", info_type=0, info_list=info_list, fp=fp)
            if (val == ""):
                return 0
            elif (val.isdigit() != True):
                printout("Warning: Please specify in the index",
                         info_type=0,
                         info_list=info_list,
                         fp=fp)
            elif ((int(val) < 0) or (int(val) >= len(candidate))):
                printout("Warning: An unexpected value",
                         info_type=0,
                         info_list=info_list,
                         fp=fp)
            else:
                return int(val)

    else:
        while (True):
            printout("[[" + str(comment) + "]]",
                     info_type=0,
                     info_list=info_list,
                     fp=fp)
            printout(str(0) + ": " + str(candidate[0]) + " (default)",
                     info_type=0,
                     info_list=info_list,
                     fp=fp)
            for i in range(1, pos_index):
                printout(str(i) + ": " + str(candidate[i]),
                         info_type=0,
                         info_list=info_list,
                         fp=fp)

            if (pos_index < len(candidate)):
                printout(str(pos_index) + ": others",
                         info_type=0,
                         info_list=info_list,
                         fp=fp)

            val = printout(">>>", info_type=1, info_list=info_list, fp=fp)
            printout("", info_type=0, info_list=info_list, fp=fp)

            if (val == ""):
                return 0
            elif (val.isdigit() != True):
                printout("Warning: Please specify in the index",
                         info_type=0,
                         info_list=info_list,
                         fp=fp)
            elif (int(val) == pos_index):
                pos_index = len(candidate)
            elif ((pos_index < len(candidate))
                  and ((int(val) < 0) or (int(val) > pos_index))):
                printout("Warning: An unexpected value",
                         info_type=0,
                         info_list=info_list,
                         fp=fp)
            elif ((pos_index == len(candidate))
                  and ((int(val) < 0) or (int(val) >= pos_index))):
                printout("Warning: An unexpected value",
                         info_type=0,
                         info_list=info_list,
                         fp=fp)
            else:
                return int(val)
Ejemplo n.º 30
0
def conf_pattern_main(comment, candidate, info_list=[1, 0, 0, 1], fp=""):
    while (True):
        printout(str(comment), info_type=0, info_list=info_list, fp=fp)
        for i in range(len(candidate)):
            printout(str(i) + ": " + str(candidate[i]),
                     info_type=0,
                     info_list=info_list,
                     fp=fp)

        val = printout(">>>", info_type=1, info_list=info_list, fp=fp)
        printout("==========================================",
                 info_type=0,
                 info_list=info_list,
                 fp=fp)

        if (val.isdigit() != True):
            printout("Warning: Please specify in the index",
                     info_type=0,
                     info_list=info_list,
                     fp=fp)
        elif ((int(val) < 0) or (int(val) >= len(candidate))):
            printout("Warning: An unexpected specification",
                     info_type=0,
                     info_list=info_list,
                     fp=fp)
        else:
            return candidate[int(val)]