def post_argocd_sync(workspace_id, app_name): """post argocd sync - ArgoCD同期処理 Args: workspace_id (int): workspace id app_name (str): app name (same environment name) Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug('CALL {} workspace_id[{}] app_name[{}]'.format( inspect.currentframe().f_code.co_name, workspace_id, app_name)) globals.logger.debug('#' * 50) # ワークスペースアクセス情報取得 Get workspace access information access_data = get_access_info(workspace_id) argo_host = 'argocd-server.epoch-ws-{}.svc'.format(workspace_id) argo_id = access_data['ARGOCD_USER'] argo_password = access_data['ARGOCD_PASSWORD'] # # argocd login # globals.logger.debug("argocd login :"******"argocd", "login", argo_host, "--insecure", "--username", argo_id, "--password", argo_password ], stderr=subprocess.STDOUT) # globals.logger.debug(stdout_cd.decode('utf-8')) # # app sync # globals.logger.debug("argocd app sync :") try: stdout_cd = subprocess.check_output( ["argocd", "app", "sync", app_name], stderr=subprocess.STDOUT) # globals.logger.debug(stdout_cd.decode('utf-8')) except subprocess.CalledProcessError as e: globals.logger.debug( "command '{}' return with error (code {}): {}".format( e.cmd, e.returncode, e.output)) ret_status = 200 # 正常終了 normal end return jsonify({"result": ret_status}), ret_status except common.UserException as e: return common.server_error(e) except Exception as e: return common.server_error(e)
def get_argocd_app(workspace_id, app_name): """get argocd info - ArgoCD情報取得 Args: workspace_id (int): workspace id app_name (str): argocd app name Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug('CALL {}'.format( inspect.currentframe().f_code.co_name)) globals.logger.debug('#' * 50) # ワークスペースアクセス情報取得 Get workspace access information access_data = get_access_info(workspace_id) argo_host = 'argocd-server.epoch-ws-{}.svc'.format(workspace_id) argo_id = access_data['ARGOCD_USER'] argo_password = access_data['ARGOCD_PASSWORD'] # # argocd login # globals.logger.debug("argocd login :"******"argocd", "login", argo_host, "--insecure", "--username", argo_id, "--password", argo_password ], stderr=subprocess.STDOUT) # globals.logger.debug(stdout_cd.decode('utf-8')) # # argocd app get # globals.logger.debug("argocd app get :") stdout_cd = subprocess.check_output( ["argocd", "app", "get", app_name, "-o", "json"], stderr=subprocess.STDOUT) # globals.logger.debug(stdout_cd.decode('utf-8')) # globals.logger.debug(stdout_cd) ret_status = 200 result = json.loads(stdout_cd) # 戻り値をそのまま返却 return jsonify({"result": ret_status, "result": result}), ret_status except common.UserException as e: return common.server_error(e) except Exception as e: return common.server_error(e)
def get_git_deliveries(hook_id): """git commits branch 情報の取得 Get git commits branch information Args: hook_id (str): hook id Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug('CALL {} hook_id[{}]'.format( inspect.currentframe().f_code.co_name, hook_id)) globals.logger.debug('#' * 50) # ヘッダ情報 header info. request_headers = { 'Authorization': 'token ' + request.headers["private-token"], 'Accept': 'application/vnd.github.v3+json', } # git_url (str): git url if request.args.get('git_url') is not None: git_url = urllib.parse.unquote(request.args.get('git_url')) else: raise Exception("gir_url parameter not found") git_repos = re.sub('\\.git$', '', re.sub('^https?://[^/][^/]*/', '', git_url)) # github repo commits get call api_url = "{}{}/hooks/{}/deliveries".format(github_webhook_base_url, git_repos, hook_id) response = requests.get(api_url, headers=request_headers) globals.logger.debug("api_url:[{}]".format(api_url)) ret_status = response.status_code if response.status_code == 200: rows = json.loads(response.text) globals.logger.debug("rows:[{}]".format(rows)) else: rows = None globals.logger.debug( "git hooks deliveries get error:[{}] text:[{}]".format( response.status_code, response.text)) # 取得したGit commit branch情報を返却 Return the acquired Git commit branch information return jsonify({"result": ret_status, "rows": rows}), ret_status except common.UserException as e: return common.server_error(e) except Exception as e: return common.server_error(e)
def call_ita_cd_result_logs(workspace_id, conductor_id): """workspace/workspace_id/it-automation/cd/result/logs call Args: workspace_id (int): workspace id conductor_id (str): conductor id Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug( 'CALL {}:from[{}] workspace_id[{}] conductor_id[{}]'.format( inspect.currentframe().f_code.co_name, request.method, workspace_id, conductor_id)) globals.logger.debug('#' * 50) if request.method == 'GET': # it-automation cd result logs get return api_ita_cd.cd_result_logs_get(workspace_id, conductor_id) else: # Error raise Exception("method not support!") except Exception as e: return common.server_error(e)
def call_ita_settings(workspace_id): """workspace/workspace_id/it-automation/settings call Args: workspace_id (int): workspace id Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug('CALL {}:from[{}] workspace_id[{}]'.format( inspect.currentframe().f_code.co_name, request.method, workspace_id)) globals.logger.debug('#' * 50) if request.method == 'POST': # it-automation setting return settings_ita(workspace_id) else: # Error raise Exception("method not support!") except Exception as e: return common.server_error(e)
def call_github_webhooks(workspace_id): """workspace/workspace_id/github/wehbooks 呼び出し Args: workspace_id (int): ワークスペースID Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug('CALL {}:from[{}] workspace_id[{}]'.format( inspect.currentframe().f_code.co_name, request.method, workspace_id)) globals.logger.debug('#' * 50) if request.method == 'POST': # webhooks 生成 return create_github_webhooks(workspace_id) else: # webhooks 取得 return get_github_webhooks(workspace_id) except Exception as e: return common.server_error(e)
def cd_result_insert(workspace_id, cd_result_id, username): """CD結果登録 cd result insert Args: workspace_id (int): workspace id cd_result_id (int): cd-result id username (str): username Returns: response: HTTP Respose """ try: globals.logger.debug( 'CALL {}:from[{}] workspace_id[{}] member[{}]'.format( inspect.currentframe().f_code.co_name, request.method, workspace_id, username)) with dbconnector() as db, dbcursor(db) as cursor: # Requestからcontentsを設定 Set contents from Request contents = request.json.copy() # cd-result insert実行 lastrowid = da_cd_result.insert_cd_result(cursor, workspace_id, cd_result_id, username, contents) globals.logger.debug('insert lastrowid:{}'.format(lastrowid)) return jsonify({"result": "200", "lastrowid": lastrowid}), 200 except Exception as e: return common.server_error( e, "{} error".format(inspect.currentframe().f_code.co_name))
def call_cd_result_member(workspace_id, username, cd_result_id): """メンバーによるCD結果の呼び出し口 CD result call by members Args: workspace_id (int): workspace id username (str): username cd_result_id (str): cd-result id Returns: response: HTTP Respose """ try: globals.logger.debug('=' * 50) globals.logger.debug( 'CALL {}:from[{}] workspace_id[{}] member[{}] cd_result_id[{}]'. format(inspect.currentframe().f_code.co_name, request.method, workspace_id, username, cd_result_id)) globals.logger.debug('=' * 50) if request.method == 'POST': # cd execute (post) return cd_result_insert(workspace_id, cd_result_id, username) elif request.method == 'GET': # cd execute (get) return cd_result_list(workspace_id=workspace_id, cd_result_id=cd_result_id, username=username) else: # Error raise Exception("method not support!") except Exception as e: return common.server_error( e, "{} error".format(inspect.currentframe().f_code.co_name))
def call_argocd_app(workspace_id, app_name): """Call workspace/workspace_id/argocd/app Args: workspace_id (int): workspace id app_name (str): app name (same environment name) Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug( 'CALL {}:from[{}] workspace_id[{}] app_name[{}]'.format( inspect.currentframe().f_code.co_name, request.method, workspace_id, app_name)) globals.logger.debug('#' * 50) if request.method == 'GET': # argocd app情報取得 argocd app information get return get_argocd_app(workspace_id, app_name) else: # エラー raise Exception("method not support!") except Exception as e: return common.server_error(e)
def call_argocd(workspace_id): """Call workspace/workspace_id/argocd Args: workspace_id (int): workspace id Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug('CALL {}:from[{}] workspace_id[{}]'.format( inspect.currentframe().f_code.co_name, request.method, workspace_id)) globals.logger.debug('#' * 50) if request.method == 'POST': # argocd pod 生成 return create_argocd(workspace_id) else: # エラー raise Exception("method not support!") except Exception as e: return common.server_error(e)
def call_cd_result(workspace_id): """CD結果の呼び出し口 CD result call Args: workspace_id (int): workspace id Returns: response: HTTP Respose """ try: globals.logger.debug('=' * 50) globals.logger.debug('CALL {}:from[{}] workspace_id[{}]'.format( inspect.currentframe().f_code.co_name, request.method, workspace_id)) globals.logger.debug('=' * 50) if request.method == 'GET': # cd execute (get) return cd_result_list(workspace_id=workspace_id) else: # Error raise Exception("method not support!") except Exception as e: return common.server_error( e, "{} error".format(inspect.currentframe().f_code.co_name))
def cd_result_list(workspace_id=None, cd_result_id=None, username=None, latest=False): """CD結果取得 cd result list Args: workspace_id (int): workspace id cd_result_id (string): cd-result id username (str): username latest (Bool): latest True or False Returns: response: HTTP Respose """ try: globals.logger.debug( 'CALL {}:from[{}] workspace_id[{}] cd_result_id[{}] username[{}] latest[{}]' .format(inspect.currentframe().f_code.co_name, request.method, workspace_id, cd_result_id, username, latest)) globals.logger.debug('CALL {}:args[{}]'.format( inspect.currentframe().f_code.co_name, request.args)) # latest (bool): 最新のみ if request.args.get('latest') is not None: latest = request.args.get('latest') == "True" else: latest = False # cd_status_in (str): 最新のみ if request.args.get('cd_status_in') is not None: cd_status_in = request.args.get('cd_status_in').split(".") else: cd_status_in = [] with dbconnector() as db, dbcursor(db) as cursor: # CD結果履歴の取得 Get CD result history fetch_rows = da_cd_result.select_cd_result(cursor, workspace_id, cd_result_id, cd_status_in, username, latest) return jsonify({"result": "200", "rows": fetch_rows}) except Exception as e: return common.server_error( e, "{} error".format(inspect.currentframe().f_code.co_name))
def call_github_branches_root(): """/branches 呼び出し Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug('CALL {}:from[{}]'.format( inspect.currentframe().f_code.co_name, request.method)) globals.logger.debug('#' * 50) if request.method == 'GET': # git branches get return get_git_branches() else: # エラー raise Exception("method not support!") except Exception as e: return common.server_error(e)
def cd_result_update(workspace_id, cd_result_id): """CD結果更新 cd result update Args: workspace_id (int): workspace id cd_result_id (int): cd-result id Returns: response: HTTP Respose """ try: globals.logger.debug( 'CALL {}:from[{}] workspace_id[{}] cd_result_id[{}]'.format( inspect.currentframe().f_code.co_name, request.method, workspace_id, cd_result_id)) with dbconnector() as db, dbcursor(db) as cursor: # Requestからcontentsを設定 Set contents from Request update_contents_items = request.json.copy() # cd-result update実行 upd_cnt = da_cd_result.update_cd_result(cursor, workspace_id, cd_result_id, update_contents_items) if upd_cnt == 0: # データがないときは404応答 db.rollback() return jsonify({"result": "404"}), 404 globals.logger.debug('update cd_result_id:{}'.format(cd_result_id)) return jsonify({"result": "200"}), 200 except Exception as e: return common.server_error( e, "{} error".format(inspect.currentframe().f_code.co_name))
def call_cd_result_root(): """CD結果の呼び出し口 条件なし CD result call not conditons Returns: response: HTTP Respose """ try: globals.logger.debug('=' * 50) globals.logger.debug('CALL {}:from[{}]'.format( inspect.currentframe().f_code.co_name, request.method)) globals.logger.debug('=' * 50) if request.method == 'GET': # cd execute (get) return cd_result_list() else: # Error raise Exception("method not support!") except Exception as e: return common.server_error( e, "{} error".format(inspect.currentframe().f_code.co_name))
def call_github_hook_deliveries(hook_id): """/hooks/deliveries 呼び出し Args: hook_id (str): hook id Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug('CALL {}:from[{}] hook_id[{}]'.format( inspect.currentframe().f_code.co_name, request.method, hook_id)) globals.logger.debug('#' * 50) if request.method == 'GET': # git deliveries get return get_git_deliveries(hook_id) else: # エラー raise Exception("method not support!") except Exception as e: return common.server_error(e)
def call_github_commits_branch(revision): """/commits/branches-where-head 呼び出し Args: revision (str): revision Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug('CALL {}:from[{}] revision[{}]'.format( inspect.currentframe().f_code.co_name, request.method, revision)) globals.logger.debug('#' * 50) if request.method == 'GET': # git commits branch get return get_git_commits_branch(revision) else: # エラー raise Exception("method not support!") except Exception as e: return common.server_error(e)
def cd_execute_cancel(workspace_id, conductor_id): """CD実行取り消し cd execute cancel Args: workspace_id (int): workspace id conductor_id (str): conductor id Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug('CALL {}'.format( inspect.currentframe().f_code.co_name)) globals.logger.debug('#' * 50) # ワークスペースアクセス情報取得 get workspace access info. access_info = api_access_info.get_access_info(workspace_id) # namespaceの取得 get namespace namespace = common.get_namespace_name(workspace_id) ita_restapi_endpoint = "http://{}.{}.svc:{}/default/menu/07_rest_api_ver1.php".format( EPOCH_ITA_HOST, namespace, EPOCH_ITA_PORT) ita_user = access_info['ITA_USER'] ita_pass = access_info['ITA_PASSWORD'] # HTTPヘッダの生成 HTTP header generation filter_headers = { 'host': EPOCH_ITA_HOST + ':' + EPOCH_ITA_PORT, 'Content-Type': 'application/json', 'Authorization': base64.b64encode( (ita_user + ':' + ita_pass).encode()), 'X-Command': 'CANCEL', } # 実行パラメータ設定 Execution parameter setting data = {"CONDUCTOR_INSTANCE_ID": conductor_id} # json文字列に変換("utf-8"形式に自動エンコードされる) Convert to json string (automatically encoded in "utf-8" format) json_data = json.dumps(data) # リクエスト送信 response = requests.post(ita_restapi_endpoint + '?no=' + ite_menu_conductor_cancel, headers=filter_headers, data=json_data) globals.logger.debug(response.text) resp_data = json.loads(response.text) # Even if it fails, "status" is returned as "SUCCEED", so the error is judged by "RESULTCODE" (success: 0, failure: 2). # 失敗時も"status"は"SUCCEED"で返ってくるため、"RESULTCODE"(成功:0, 失敗:2)でエラーを判断 if resp_data["resultdata"]["RESULTCODE"] == "002": globals.logger.error("no={} status:{}".format( ite_menu_conductor_cancel, resp_data["status"])) error_detail = multi_lang.get_text( "EP034-0004", "CD予約取り消しの呼び出しに失敗しました ita-status:{0} resultdata:{1}".format( resp_data["status"], resp_data["resultdata"]), resp_data["status"], resp_data["resultdata"]) raise common.UserException(error_detail) # 正常終了 Successful completion ret_status = 200 # 戻り値をそのまま返却 Return the return value as it is return jsonify({"result": ret_status}), ret_status except common.UserException as e: return common.server_error(e) except Exception as e: return common.server_error(e)
def cd_result_logs_get(workspace_id, conductor_id): """CD実行結果ログ取得 cd result logs get Args: workspace_id (int): workspace id conductor_id (str): conductor id Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug( 'CALL {} workspace_id[{}] conductor_id[{}]'.format( inspect.currentframe().f_code.co_name, workspace_id, conductor_id)) globals.logger.debug('#' * 50) # ワークスペースアクセス情報取得 get workspace access info. access_info = api_access_info.get_access_info(workspace_id) # namespaceの取得 get namespace namespace = common.get_namespace_name(workspace_id) ita_restapi_endpoint = "http://{}.{}.svc:{}/default/menu/07_rest_api_ver1.php".format( EPOCH_ITA_HOST, namespace, EPOCH_ITA_PORT) ita_user = access_info['ITA_USER'] ita_pass = access_info['ITA_PASSWORD'] # POST送信する post sender # HTTPヘッダの生成 HTTP header generation filter_headers = { 'host': EPOCH_ITA_HOST + ':' + EPOCH_ITA_PORT, 'Content-Type': 'application/json', 'Authorization': base64.b64encode( (ita_user + ':' + ita_pass).encode()), 'X-Command': 'DOWNLOAD', } # 実行パラメータ設定 parameter setting data = {"CONDUCTOR_INSTANCE_NO": [str(int(conductor_id) + 1)]} # json文字列に変換 json convert json_data = json.dumps(data) # リクエスト送信 request post exec_response = requests.post(ita_restapi_endpoint + '?no=' + ite_menu_conductor_download, headers=filter_headers, data=json_data) if exec_response.status_code != 200: globals.logger.error(exec_response.text) error_detail = multi_lang.get_text( "EP034-0007", "実行結果ログ取得の呼び出しに失敗しました status:{0}".format( exec_response.status_code), exec_response.status_code) raise common.UserException(error_detail) # globals.logger.debug("-------------------------") # globals.logger.debug("response:") # globals.logger.debug(exec_response) # globals.logger.debug("response_text:") # globals.logger.debug(exec_response.text) # globals.logger.debug("-------------------------") # 戻り値用の器設定 Device setting for return value rows = { "manifest_embedding": {}, "manifest_commit_push": {}, } # 実行してすぐは読込ができない状況があるのでチェックする # Check because there are situations where it cannot be read immediately after execution. if not common.is_json_format(exec_response.text): # 実行途中の正常終了として返す Returns as normal termination during execution globals.logger.debug("not start!") ret_status = 404 # 実行前なので404を返却 Return 404 because it is before execution return jsonify({"result": ret_status, "rows": rows}), ret_status resp_data = json.loads(exec_response.text) # globals.logger.debug(f"resp_data:{resp_data}") if resp_data["status"] != "SUCCEED": globals.logger.error("no={} status:{}".format( ite_menu_conductor_exec, resp_data["status"])) error_detail = multi_lang.get_text( "EP034-0008", "実行結果ログ取得の呼び出しに失敗しました ita-status:{0} resultdata:{1}".format( eresp_data["status"], eresp_data["resultdata"]), eresp_data["status"], eresp_data["resultdata"]) raise common.UserException(error_detail) body_cnt = 0 for body in resp_data["resultdata"]["CONTENTS"]["BODY"]: # download_input_key = body["INPUT_DATA"] # base64_input_log_zip = resp_data["resultdata"]["CONTENTS"]["DOWNLOAD"][download_key] download_result_key = body["RESULT_DATA"] base64_result_log_zip = resp_data["resultdata"]["CONTENTS"][ "DOWNLOAD_FILE"][body_cnt][download_result_key] # globals.logger.debug(f"base64_result_log_zip:{base64_result_log_zip}") binary_result_log_zip = base64.b64decode( base64_result_log_zip.encode()) with tempfile.TemporaryDirectory() as tempdir: # zipファイル生成 Zip file generation path_zip_file = '{}/{}'.format(tempdir, download_result_key) # globals.logger.debug(f"path_zip_file:{path_zip_file}") with open(path_zip_file, mode='bw') as fp: fp.write(binary_result_log_zip) # zipファイルに含まれているファイル名の取得 # Get the file name contained in the zip file with zipfile.ZipFile(path_zip_file) as log_zip: # zipファイルに含まれているファイルのリストを返す # Returns a list of files contained in the zip file for f in log_zip.namelist(): # ファイル名の末尾が"/"じゃない内容を解凍 # Unzip the contents that do not end with "/" in the file name if f[-1:] != "/": # globals.logger.debug(f"f:{f}") # zipファイルに含まれているファイルを取り出す # Extract the files contained in the zip file log_zip.extract(f, tempdir) # 解凍した各フォルダの内容を再度解凍 # Unzip the contents of each unzipped folder again files = glob.glob(tempdir + "/**/*.zip") for file in files: # globals.logger.debug(f"file:{file}") with zipfile.ZipFile(file) as log_zip: for f in log_zip.namelist(): if f == "exec.log": # 実行ログ Execution log # globals.logger.debug(f"f:{f}") with log_zip.open(f) as f_log: exec_logs = f_log.read() # globals.logger.debug(f"logs:{exec_logs}") elif f == "error.log": # エラーログ error log # globals.logger.debug(f"f:{f}") with log_zip.open(f) as f_log: error_logs = f_log.read() # globals.logger.debug(f"logs:{error_logs}") sub_dir_name = os.path.basename(os.path.dirname(file)) # globals.logger.debug(f"sub_dir_name:{sub_dir_name}") if sub_dir_name == "0000000001": # フォルダの1番目は、Manifest埋め込みのログ # The first folder is the Manifest embedded log rows["manifest_embedding"] = { "execute_logs": exec_logs.decode('utf-8'), "error_logs": error_logs.decode('utf-8'), } elif sub_dir_name == "0000000002": # フォルダの2番目は、Manifest Commit&Pushのログ # The second folder is the Manifest Commit & Push log rows["manifest_commit_push"] = { "execute_logs": exec_logs.decode('utf-8'), "error_logs": error_logs.decode('utf-8'), } body_cnt += 1 # globals.logger.debug(f"rows:{rows}") # 正常終了 normal end ret_status = 200 # 戻り値をそのまま返却 return jsonify({"result": ret_status, "rows": rows}), ret_status except common.UserException as e: return common.server_error(e) except Exception as e: return common.server_error(e)
def get_git_commits(revision=None): """git commits 情報の取得 Get git commits information Args: revision (str): revision Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug('CALL {} revision[{}]'.format( inspect.currentframe().f_code.co_name, revision)) globals.logger.debug('#' * 50) # ヘッダ情報 header info. request_headers = { 'Authorization': 'token ' + request.headers["private-token"], 'Accept': 'application/vnd.github.v3+json', } # git_url (str): git url if request.args.get('git_url') is not None: git_url = urllib.parse.unquote(request.args.get('git_url')) else: raise Exception("gir_url parameter not found") # branch (str): branch if request.args.get('branch') is not None: branch = urllib.parse.unquote(request.args.get('branch')) else: branch = None git_repos = re.sub('\\.git$', '', re.sub('^https?://[^/][^/]*/', '', git_url)) # github repo commits get call api_url = "{}{}/commits".format(github_webhook_base_url, git_repos) # 個別指定がある場合のみ、条件を設定 # Set conditions only if there is an individual specification if revision is not None: api_url += "/{}".format(revision) if branch is not None: api_url += "?sha={}".format(urllib.parse.quote(branch)) globals.logger.debug("api_url:[{}]".format(api_url)) response = requests.get(api_url, headers=request_headers) ret_status = response.status_code if response.status_code == 200: rows = json.loads(response.text) # globals.logger.debug("rows:[{}]".format(rows)) else: rows = None globals.logger.debug("git commits get error:[{}] text:[{}]".format( response.status_code, response.text)) # 取得したGit commit情報を返却 Return the acquired Git commit information return jsonify({"result": ret_status, "rows": rows}), ret_status except common.UserException as e: return common.server_error(e) except Exception as e: return common.server_error(e)
def cd_result_get(workspace_id, conductor_id): """CD実行結果取得 cd result get Args: workspace_id (int): workspace id conductor_id (str): conductor id Returns: Response: HTTP Respose """ try: globals.logger.debug('#' * 50) globals.logger.debug( 'CALL {} workspace_id[{}] conductor_id[{}]'.format( inspect.currentframe().f_code.co_name, workspace_id, conductor_id)) globals.logger.debug('#' * 50) # ワークスペースアクセス情報取得 get workspace access info. access_info = api_access_info.get_access_info(workspace_id) # namespaceの取得 get namespace namespace = common.get_namespace_name(workspace_id) ita_restapi_endpoint = "http://{}.{}.svc:{}/default/menu/07_rest_api_ver1.php".format( EPOCH_ITA_HOST, namespace, EPOCH_ITA_PORT) ita_user = access_info['ITA_USER'] ita_pass = access_info['ITA_PASSWORD'] # POST送信する post sender # HTTPヘッダの生成 HTTP header generation filter_headers = { 'host': EPOCH_ITA_HOST + ':' + EPOCH_ITA_PORT, 'Content-Type': 'application/json', 'Authorization': base64.b64encode( (ita_user + ':' + ita_pass).encode()), 'X-Command': 'INFO', } # 実行パラメータ設定 parameter setting data = {"CONDUCTOR_INSTANCE_ID": conductor_id} # json文字列に変換 json convert json_data = json.dumps(data) # リクエスト送信 request post exec_response = requests.post(ita_restapi_endpoint + '?no=' + ite_menu_conductor_result, headers=filter_headers, data=json_data) if exec_response.status_code != 200: globals.logger.error(exec_response.text) error_detail = multi_lang.get_text( "EP034-0005", "実行結果取得の呼び出しに失敗しました status:{0}".format( exec_response.status_code), exec_response.status_code) raise common.UserException(error_detail) # globals.logger.debug("-------------------------") # globals.logger.debug("response:") # globals.logger.debug(exec_response.text) # globals.logger.debug("-------------------------") resp_data = json.loads(exec_response.text) if resp_data["status"] != "SUCCEED": globals.logger.error("no={} status:{}".format( ite_menu_conductor_exec, resp_data["status"])) error_detail = multi_lang.get_text( "EP034-0006", "実行結果取得の呼び出しに失敗しました ita-status:{0} resultdata:{1}".format( eresp_data["status"], eresp_data["resultdata"]), eresp_data["status"], eresp_data["resultdata"]) raise common.UserException(error_detail) rows = resp_data # 正常終了 normal end ret_status = 200 # 戻り値をそのまま返却 return to it-automation results return jsonify({"result": ret_status, "rows": rows}), ret_status except common.UserException as e: return common.server_error(e) except Exception as e: return common.server_error(e)