def cluster_id_def(self, zone): #APIを使用する場合 if (self.api_index == True): while (True): #クラウド上の全てのクラスタIDの取得 logger.debug("loading all cluster IDs") get_cluster_id_info = get(self.url_list[zone] + self.sub_url[0], self.auth_res) check,msg = self.res_check(get_cluster_id_info, "get") if check == True: logger.debug("assign cluster ID") cluster_id_info = get_cluster_id_info["Servers"] cluster_id_list = [d.get('Tags') for d in cluster_id_info] while (True): cluster_id_temp = random.randint(100000,999999) if not cluster_id_temp in cluster_id_list: self.cluster_id = "cluster ID: " + str(cluster_id_temp) logger.info("cluster ID: " + str(self.cluster_id) + "-Success") break else: self.printout_cluster("Duplication of cluster ID.", cls_monitor_level = 3) self.printout_cluster("Reissuing cluster ID.", cls_monitor_level = 3) break else: self.build_error() else: get_cluster_id_info = "API is not used." self.cluster_id = "cluster ID:" + str(random.randint(100000,999999))
def check_cloud_state(ext_info, auth_info, info_list=[1, 0, 0, 0], fp="", api_index=True, func_type=""): if (api_index == True): all_zone = list(ext_info["Zone"].keys()) for zone in all_zone: logger.debug('Checking the state in ' + zone) url = "https://secure.sakura.ad.jp/cloud/zone/" + zone + "/api/cloud/1.1" while (True): exist_server_all = get(url + "/server", auth_info) if ("is_ok" in exist_server_all.keys()): if exist_server_all["is_ok"] == True: break logger.debug( 'Calculating the number of nodes that can be installed in ' + zone) exist_server_all = exist_server_all["Count"] ext_info["Zone"][zone]["maximum"] = ext_info["Zone"][zone][ "maximum"] - exist_server_all if (ext_info["Zone"][zone]["maximum"] <= ext_info["Zone"][zone]["minimum"] and func_type == "build"): logger.info("nodes cannot install in " + zone) logger.info(zone + " was deleted from external info") ext_info["Zone"].pop(zone) return ext_info else: return ext_info
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
def get_bridge_info(self, zone, bridge_id): if (self.api_index == True): while (True): get_res = get( self.url_list[zone] + self.sub_url[4] + "/" + str(bridge_id), self.auth_res) check = self.res_check(get_res, "get") if (check == True): logger.debug("Get bridge infomation(bridge ID): " + str(bridge_id)) if get_res["Bridge"]["Info"] != None: if "Switches" in get_res["Bridge"]["Info"].keys(): connect_bool = True else: connect_bool = False else: connect_bool = False return connect_bool else: self.delete_error() else: connect_bool = False return connect_bool
def authentication_cli(fp="", info_list=[1, 0, 0, 1], api_index=True): filename = "Setting.json" if (os.path.exists(home_path + "/setting/" + filename) == True): #<--windowsでは変更あり #認証情報をSetting.jsonから読み出し _ = printout("loading Setting.json ...", info_list=info_list, fp=fp) logger.debug('loading Setting.json') setting_info = json_input(home_path + "/setting/" + filename) #Setting.jsonの確認 _ = printout("Checking the contents in Setting.json ...", info_list=info_list, fp=fp) logger.debug('Checking the contents in Setting.json') res, e_message = check_json_file(setting_info, jsa_auth) if (res == True): auth_res = base64.b64encode('{}:{}'.format( setting_info["access token"], setting_info["access 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", auth_res) if ("Account" not in res): _ = printout("AuthenticationError: cannot access", info_list=info_list, fp=fp) logger.error('AuthenticationError: cannot access') auth_res = define_auth_info(home_path + "/setting/Setting.json", info_list=info_list, api_index=api_index, fp=fp) else: _ = printout( "AuthenticationError: Elements in Setting.json are wrong", info_list=info_list, fp=fp) logger.error( 'AuthenticationError: Elements in Setting.json are wrong \n' + e_message) auth_res = define_auth_info(home_path + "/setting/Setting.json", info_list=info_list, api_index=api_index, fp=fp) else: _ = printout( "AuthenticationError: Setting.json does not exist in sacluster/setting", info_list=info_list, fp=fp) logger.error( 'AuthenticationError: Setting.json does not exist in sacluster/setting' ) auth_res = define_auth_info(home_path + "/setting/Setting.json", info_list=info_list, api_index=api_index, fp=fp) _ = printout("Certified authentication information", info_list=info_list, fp=fp) logger.debug('Certified authentication information') return auth_res