1 Star 0 Fork 2

凹凸曼打小怪兽/wenjian

forked from banzhuanxiaodoubi/wenjian 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
openeuler_at_operation.py 3.17 KB
一键复制 编辑 原始数据 按行查看 历史
banzhuanxiaodoubi 提交于 2022-12-02 11:20 . wenjian
#!/usr/bin/env python
# -*- encoding=utf-8 -*-
import sys
import urllib
import json
import logging
from datetime import datetime
test_url = "http://172.168.131.95:8090/api"
def set_logger():
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s : %(message)s')
logger = logging.getLogger("upload")
return logger
def start_job(iso_url):
logger = set_logger()
start_job_url = test_url + "/start/" + iso_url
logger.info("the start job url is %s" % start_job_url)
try:
res = urllib.urlopen(start_job_url)
res_json = json.loads(res.read())
if isinstance(res_json, dict):
status_code = int(res_json.get("status_code"))
if status_code != 200:
error_msg = "the status code %d is not 200" % status_code
logger.error(error_msg)
return False, error_msg
job_id = res_json.get("id")
if not job_id:
error_msg = "can not get job id from response"
logger.error(error_msg)
return False, error_msg
return True, job_id
else:
logger.error("start job failed, and the return {} is not correct and the type is {}".format(res_json,
type(res_json)))
return False, "error"
except Exception as e:
return False, e
def restart_job(job_id):
logger = set_logger()
restart_job_url = test_url + "/restart/" + job_id
logger.info("the restart job url is %s" % restart_job_url)
try:
res = urllib.urlopen(restart_job_url)
res_json = json.loads(res.read())
if isinstance(res_json, dict):
status_code = int(res_json.get("status_code"))
if status_code != 200:
error_msg = "the status code %d is not 200" % status_code
logger.error(error_msg)
return False, error_msg
restart_ids = res_json.get("restart_ids")
if not restart_ids:
error_msg = "can not get restart_ids from response"
logger.error(error_msg)
return False, error_msg
return True, restart_ids
else:
logger.error("restart job failed, and the return {} is not correct and the type is {}".format(res_json,
type(
res_json)))
return False, "error"
except Exception as e:
return False, e
def stop_job(ids):
pass
operation = sys.argv[1]
if operation == "start":
if len(sys.argv) == 3:
iso_url = sys.argv[2]
else:
iso_url = None
ret, ids = start_job(iso_url)
if not ret:
print("error")
else:
print(ids)
if operation == "restart":
job_id = sys.argv[2]
ret, restart_ids = restart_job(job_id)
if not ret:
print("error")
else:
print(restart_ids)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/concave-convex-manda/wenjian.git
git@gitee.com:concave-convex-manda/wenjian.git
concave-convex-manda
wenjian
wenjian
master

搜索帮助