diff --git a/a.sh b/aa.sh similarity index 100% rename from a.sh rename to aa.sh diff --git a/cluster.py b/cluster.py index ed3338b5445247d8377faa027f5e07e79999c519..83b06217abf73ccb6144a9f57dc02990c0d58260 100644 --- a/cluster.py +++ b/cluster.py @@ -42,7 +42,7 @@ def update_cluster_properties(data): status, output = common_utils.run_cmd(cmd_str) if status != 0: return {'action': False, 'error': _(output)} - return {'action': True, 'info': _('Update cluster properties Success')} + return {'action': True, 'info': _("Update cluster properties Success")} def operation_cluster_action(action): @@ -61,4 +61,3 @@ def operation_cluster_action(action): if __name__ == "__main__": print(common_utils.run_cmd("pcs status")) - #print(get_cluster_properties_info()) diff --git a/common_utils.py b/common_utils.py index d911d5a2b381728e00e4f7808603942002e0a477..b9817492625e7f858c2611011a7d80e7b35114e6 100644 --- a/common_utils.py +++ b/common_utils.py @@ -1,24 +1,12 @@ import os -import sys import subprocess -import xml.dom.minidom -from xml.dom.minidom import parseString import xml.etree.ElementTree as ET import re import json -import tempfile import signal -import time -from io import BytesIO -import tarfile -import getpass -import base64 -import threading import logging from functools import lru_cache -from urllib.parse import urlencode import settings -import xml.parsers as parsers import xmltodict import abc import reports @@ -476,25 +464,25 @@ def get_resource_info(ct, xml_data): etree = ET.fromstring(xml_data) try: data = {} - #根据分类 + # 根据分类 if ct == "primitive": data = get_resource_info_from_xml("primitive", etree) if ct == "group": data["rscs"] = get_resource_info_from_xml("group", etree) if ct == "clone": data["rsc_id"] = get_resource_info_from_xml("clone", etree) - #获取meta_attributes + # 获取meta_attributes e = etree.find("meta_attributes") if e: prop = get_resource_info_from_xml("meta", e) data["meta_attributes"] = prop - #获取instance_attributes + # 获取instance_attributes e = etree.find("instance_attributes") if e: prop = get_resource_info_from_xml("inst", e) data["instance_attributes"] = prop - #获取actions + # 获取actions e = etree.find("operations") if e: prop = get_resource_info_from_xml("operations", e) diff --git a/config.py b/config.py index ee2336cee98e6cd56f13e7bc1e37029be335b786..62988f6750249d44bda1394252259bd739c47df5 100644 --- a/config.py +++ b/config.py @@ -1,12 +1,7 @@ import common_utils import json import xmltodict -from xml.dom.minidom import parseString -from xml.dom.minidom import getDOMImplementation -import xml.etree.ElementTree as ET -from collections import OrderedDict import os -import re ''' {                     "hbaddrs1":[ @@ -44,7 +39,7 @@ import re def get_node_list(): - #读取文件 + # 读取文件 filename = "/etc/corosync/corosync.conf" try: read = open(filename) @@ -53,19 +48,19 @@ def get_node_list(): 'action': False, 'error': "File " + filename + " doesn't exist!" } - node_list = [] #存储文件内数据 - line = read.readline() #按行读取文件内容 - while line and not "nodelist {" in line: + node_list = [] # 存储文件内数据 + line = read.readline() # 按行读取文件内容 + while line and not "nodelist {" in line: line = read.readline() - #读到nodelist - #node_list.append(line) + # 读到nodelist + # node_list.append(line) while line: if "quorum {" in line: break node_list.append(line.strip()) line = read.readline() read.close - #修改格式 + # 修改格式 while "nodelist {" in node_list: node_list.remove("nodelist {") while "" in node_list: @@ -109,12 +104,12 @@ def get_node_list(): # return {'action': True, "data": data} -#判断集群是否存在 +# 判断集群是否存在 def is_cluster_exist(): return os.path.exists("/etc/corosync/corosync.conf") -#通过/var/lib/pcsd/known-hosts获取hb信息 +# 通过/var/lib/pcsd/known-hosts获取hb信息 def get_hb_by_hosts(): cmd_str = "cat /var/lib/pcsd/known-hosts" status, output = common_utils.run_cmd(cmd_str) @@ -126,7 +121,7 @@ def get_hb_by_hosts(): _("No node in the Cluster, please run \'pcs host auth $nodename\' to add node" ) } - #解析json为字典 + # 解析json为字典 info = json.loads(str(output)) ret = {} if "known_hosts" in info.keys(): @@ -149,7 +144,7 @@ def get_hb_by_hosts(): def get_hb_conf(): - #判断集群是否存在 + # 判断集群是否存在 if is_cluster_exist(): return get_hb_dict() else: @@ -161,7 +156,7 @@ def get_hb_dict(): """ ['node {', 'ring0_addr: ha3', 'name: ha3', 'nodeid: 1', 'node {', 'ring0_addr: ha4', 'name: ha4', 'nodeid: 2'] """ - nodes = [] #按照node存储为键值对 + nodes = [] # 按照node存储为键值对 index = 0 while index < len(node_list): if node_list[index] == "node {": @@ -184,7 +179,7 @@ def get_hb_dict(): ] """ res = {} - #形成指定格式 + # 形成指定格式 for i in nodes: """ {'ring0_addr': 'ha3', 'ring1_addr': 'ha4', 'name': 'ha3', 'nodeid': '1'} @@ -192,23 +187,23 @@ def get_hb_dict(): name = i.get("name", "") for k, v in i.items(): if k != "name" and k != "nodeid": - #只选取ip + # 只选取ip """ {'ring0_addr': 'ha3'} """ info = {} info["nodeid"] = name info["ip"] = v - #判断属于哪个心跳 + # 判断属于哪个心跳 hb = str(k) if hb in res.keys(): - #如果存在,向其中添加 + # 如果存在,向其中添加 res[hb].append(info) else: - #如果不存在,新建 + # 如果不存在,新建 res[hb] = [] res[hb].append(info) - #将res里的所有ringx_addr重命名为hbaddrsx + # 将res里的所有ringx_addr重命名为hbaddrsx ret = {} count = 0 for key, value in res.items(): @@ -237,7 +232,6 @@ def edit_hb_info(data): hb_info[nodeid].append(nodeip) if 'hbaddrs2' in data: hbaddrs2 = data['hbaddrs2'] - hb = "" for nodeinfo in hbaddrs2: nodeid = str(nodeinfo['nodeid']) nodeip = str(nodeinfo['ip']) @@ -252,26 +246,26 @@ def edit_hb_info(data): for v in value: addr = "addr=" + str(v) cmd = cmd + " " + addr - cmd = cmd + cmd2 #pcs cluster setup hacluster ha1 addr=10.1.167.86 ha2 addr=10.1.167.81 + cmd = cmd + cmd2 + # pcs cluster setup hacluster ha1 addr=10.1.167.86 ha2 addr=10.1.167.81 cmd_resource = "crm_mon -1 --as-xml" status, output = common_utils.run_cmd(cmd_resource) if status == 0: - xml_nodes = parseString(output).documentElement json_str = json.dumps(xmltodict.parse(output)) json_dict = json.loads(json_str) run_resources = json_dict['crm_mon']['resources'] else: run_resources = None - if run_resources == None: + if run_resources is None: status, output = common_utils.run_cmd("pcs cluster cib ra-cfg") status, output = common_utils.run_cmd("pcs resource cleanup") status, output = common_utils.run_cmd("pcs cluster stop --all") status, output = common_utils.run_cmd("pcs cluster destroy --all") status, output = common_utils.run_cmd(cmd) status, output = common_utils.run_cmd("pcs cluster cib-push ra-cfg") - return {"action": True, "info": "Change cluster success"} + return {"action": True, "info": _("Change cluster success")} else: - return {"action": False, "error": "集群中有运行的资源,请先关闭"} + return {"action": False, "error": _("There")} if __name__ == '__main__': diff --git a/ha-api.mo b/ha-api.mo index ed5750255b93f1d9e12e4f8d2b6b665d807d515e..b4fd5022863b5a41b0c278adf72056daa94f4077 100644 Binary files a/ha-api.mo and b/ha-api.mo differ diff --git a/node.py b/node.py index fee3651be7b1279315c8bb11fc4c044e6ccbc17c..d6db8480cc5170c5009b90c4590aa13342b0bf6a 100644 --- a/node.py +++ b/node.py @@ -1,11 +1,7 @@ import common_utils -import json -import xml.etree.ElementTree as ET from xml.dom.minidom import parseString -from flask import session import config -import run -#from Manager import Manager +# from Manager import Manager """ { "action":true, @@ -48,7 +44,6 @@ def get_node_info(): for nodes in new_nodes.getElementsByTagName('nodes'): for node in nodes.getElementsByTagName('node'): name = node.getAttribute('name') - id = node.getAttribute('id') online = node.getAttribute('online') standby = node.getAttribute('standby') is_dc = node.getAttribute('is_dc') @@ -77,7 +72,7 @@ def get_node_info(): status = "Not Running" status_json = {} - status_json['id'] = name + status_json['nid'] = name status_json['status'] = status status_json['is_dc'] = is_dc data.append(status_json) @@ -100,27 +95,27 @@ def get_nodeid_info(nodeid): def get_nodes_action(node_id, action): nodeid = str(node_id) - #节点未开启 + # 节点未开启 if nodeid == {} or nodeid is None: return {'action': False, 'error': _("Cannot find the")} - #备用 + # 备用 if action == 'standby': status, output = common_utils.run_cmd("pcs node standby " + nodeid) - #不备用 + # 不备用 if action == 'unstandby': status, output = common_utils.run_cmd("pcs node unstandby " + nodeid) - #启动 + # 启动 if action == 'start': status, output = common_utils.run_cmd("pcs cluster start " + nodeid + " &sleep 5") - #停止 + # 停止 if action == 'stop': status, output = common_utils.run_cmd("pcs cluster stop " + nodeid) - #重启 + # 重启 if action == 'restart': status, output = common_utils.run_cmd("pcs cluster restart " + nodeid) if action == {} or action is None: return {"action": False, "error": "error info"} else: - return {"action": True, "info": "Change node status success"} + return {"action": True, "info": _("Change node status success")} diff --git a/resource.py b/resource.py index 823f3296fd82c44478ac5da627e861d35cb65f39..e3115eaa543bd85ad434bf731892a3845c4b501b 100644 --- a/resource.py +++ b/resource.py @@ -562,7 +562,6 @@ def get_all_rsc_status(): 4:_('Stop Failed'), 5:_('running (Master)'), 6:_('running (Slave)')} - rsc_info = { "hj1": {"status": 0 , "status_message": "test", running_node: []} "hj2": {"status": 0 , "status_message": "test", running_node: []} @@ -1305,12 +1304,12 @@ def update_resource_attributes(rsc_id, data): return {'action': True, 'info': _("Update resource attributes Success")} -#获取rsc已有的op列表(仅属性名,如start) +# 获取rsc已有的op列表(仅属性名,如start) def get_all_ops(rsc_id): op_list = [] cmd_str = "crm_resource --resource " + str(rsc_id) + " --query-xml" - status, output = common_utils.run_cmd(cmd_str) #输出为xml格式 - #format + status, output = common_utils.run_cmd(cmd_str) # 输出为xml格式 + # format xml_data = output.split(":\n") xml = xml_data[1] etree = ET.fromstring(xml) @@ -1322,13 +1321,13 @@ def get_all_ops(rsc_id): return op_list -#获取组资源的rscs列表 +# 获取组资源的rscs列表 def get_group_rscs(group_id): cmd_str = "crm_resource --resource " + str(group_id) + " --query-xml" - status, output = common_utils.run_cmd(cmd_str) #输出为xml格式 + status, output = common_utils.run_cmd(cmd_str) # 输出为xml格式 if status != 0: return {'action': False, 'error': _(output)} - #format + # format xml_data = output.split(":\n") xml = xml_data[1] etree = ET.fromstring(xml) @@ -1339,13 +1338,13 @@ def get_group_rscs(group_id): return rscs -#获取资源category(primitive, group, clone) +# 获取资源category(primitive, group, clone) def get_rsc_category(rsc_id): cmd_str = "crm_resource --resource " + str(rsc_id) + " --query-xml" - status, output = common_utils.run_cmd(cmd_str) #输出为xml格式 + status, output = common_utils.run_cmd(cmd_str) # 输出为xml格式 if status != 0: return {'action': False, 'error': _(output)} - #format + # format xml_data = output.split(":\n") xml = xml_data[1] etree = ET.fromstring(xml) @@ -1354,7 +1353,7 @@ def get_rsc_category(rsc_id): def del_pri_attrib(rsc_id): - #删除之前所有的属性 + # 删除之前所有的属性 attrib = [] attrib = get_meta_and_inst(rsc_id) if "meta_attributes" in attrib: @@ -1532,10 +1531,6 @@ def create_resource(data): def unmigrate_rsc(is_all_rscs, rsc_id): # 保留标签 is_all_rscs = False - - # if rsc_id not in get_all_rsc(): - # return {'action': False, 'error': _("Cannot find the %s: %s") % (_("resource"), str(rsc_id))} - rsc_locations = {} for rsc_location in get_all_migrate_rscs(): id = str(rsc_location.getAttribute("id")) @@ -1573,7 +1568,7 @@ def unmigrate_rsc(is_all_rscs, rsc_id): def get_all_rsc_metas(): - #获取支持的资源代理标准 + # 获取支持的资源代理标准 standards = [] status, output = common_utils.run_cmd("crm_resource --list-standards") if status != 0: @@ -1583,14 +1578,14 @@ def get_all_rsc_metas(): res = {} for st in standards: if st == "ocf": - #获取providers列表 + # 获取providers列表 status, output = common_utils.run_cmd( "crm_resource --list-ocf-providers") if status != 0: return {'action': False, 'error': _(output)} pvds = [] pvds = str(output).split("\n") - #根据providers列出所有资源 + # 根据providers列出所有资源 for p in pvds: status, output = common_utils.run_cmd( "crm_resource --list-agents ocf:" + str(p)) @@ -1603,7 +1598,7 @@ def get_all_rsc_metas(): res[str(p)] = ag # 去除重复项 data["ocf"] = res - #lsb目前没有 + # lsb目前没有 elif st == "lsb": continue else: @@ -1619,7 +1614,7 @@ def get_all_rsc_metas(): return {'action': True, 'data': data} -#获取资源元属性 +# 获取资源元属性 def get_rsc_meta_attributes(category): ''' { @@ -1746,15 +1741,15 @@ def get_rsc_meta_attributes(category): def get_resource_info_by_rsc_id(rsc_id): cmd_str = "crm_resource --resource " + str(rsc_id) + " --query-xml" - status, output = common_utils.run_cmd(cmd_str) #输出为xml格式 + status, output = common_utils.run_cmd(cmd_str) # 输出为xml格式 if status != 0: return {'action': False, 'error': _(output)} - #format + # format xml_data = output.split(":\n") xml = xml_data[1] etree = ET.fromstring(xml) ct = etree.tag - data = common_utils.get_resource_info(ct, xml) #获取资源信息并按格式输出 + data = common_utils.get_resource_info(ct, xml) # 获取资源信息并按格式输出 data["id"] = str(rsc_id) data["category"] = str(ct) ret = {} @@ -1775,25 +1770,25 @@ def get_resource_info_by_rsc_id(rsc_id): return ret -#获取资源已有元属性和实例属性 +# 获取资源已有元属性和实例属性 def get_meta_and_inst(rsc_id): cmd_str = "crm_resource --resource " + str(rsc_id) + " --query-xml" - status, output = common_utils.run_cmd(cmd_str) #输出为xml格式 + status, output = common_utils.run_cmd(cmd_str) # 输出为xml格式 if status != 0: return {'action': False, 'error': _(output)} - #format + # format xml_data = output.split(":\n") xml = xml_data[1] etree = ET.fromstring(xml) data = {} - #获取meta_attributes + # 获取meta_attributes e = etree.find("meta_attributes") if e: prop = [] for item in e.findall("./nvpair"): prop.append(item.get("name")) data["meta_attributes"] = prop - #获取instance_attributes + # 获取instance_attributes e = etree.find("instance_attributes") if e: prop = [] @@ -1942,12 +1937,6 @@ def del_colocation_by_id_action(source_id, target_id): if __name__ == '__main__': - print(get_all_rsc_status()) - # print(get_resource_info_by_rsc_id("q11")) - # print(get_resource_info()) print(get_sub_rscs("dummyx-clone")) print(get_sub_rscs("dummy1-clone")) - - # get_rsc_category("q11") - # print(get_resource_svc("q3")) diff --git a/run.py b/run.py index 16d39eb47ef264cfc0e22772d9a25f8ebc95f8e4..2766b4dc187a175d8e9fac0a44d4bf560dcf05d2 100644 --- a/run.py +++ b/run.py @@ -38,13 +38,12 @@ def create_app(test_config=None): # Set the secret key to some random bytes. Keep this really secret. app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' app.config['SECRET_KEY'] = os.urandom(24) + app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(minutes=5) # Debug INFO app.debug = True @app.before_request def login_check(): - session.permanent = True - app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(minutes=5) user_name = session.get('user_name') if user_name is None: if not request.path.startswith('/api/v1/login'): @@ -89,7 +88,6 @@ def create_app(test_config=None): methods=['GET', 'POST', 'PUT']) def cluster_ops(): if request.method == 'GET': - #return Response(json.dumps(cluster.get_cluster_properties_info()), mimetype='application/json') return json.dumps(cluster.get_cluster_properties_info()) if request.method == 'PUT': data = request.json @@ -98,7 +96,7 @@ def create_app(test_config=None): else: return - #local HA operation + # local HA operation @app.route('/api/' + API_VERSION + '/haclusters/1/localnodes/', methods=['GET', 'POST', 'PUT']) def loocalnodes_ops(action): @@ -112,14 +110,14 @@ def create_app(test_config=None): if request.method == 'GET': return json.dumps(resource.get_resource_info()) if request.method == 'POST': - #添加资源 primitive group clone + # 添加资源 primitive group clone data = request.json ret = json.dumps(resource.create_resource(data)) return ret else: return - #获取所有资源类型 + # 获取所有资源类型 @app.route('/api/' + API_VERSION + '/haclusters/1/metas', methods=['GET', 'POST', 'PUT']) def resource_meta_ops(): @@ -128,7 +126,7 @@ def create_app(test_config=None): else: return - #获取资源元属性 + # 获取资源元属性 @app.route('/api/' + API_VERSION + '/haclusters/1/resources/meta_attributes/', methods=['GET', 'POST', 'PUT']) @@ -138,7 +136,7 @@ def create_app(test_config=None): else: return - #修改资源 + # 修改资源 @app.route('/api/' + API_VERSION + '/haclusters/1/resources/', methods=['GET', 'POST', 'PUT']) def resource_ops_by_id(rsc_id): @@ -277,21 +275,21 @@ def create_app(test_config=None): """ return render_template('index.html') - #获取node + # 获取node @app.route('/api/' + API_VERSION + '/haclusters/1/nodes/', methods=['GET', 'POST', 'PUT']) def get_nodes(): if request.method == 'GET': return json.dumps(node.get_node_info()) - #根据id取单个node + # 根据id取单个node @app.route('/api/' + API_VERSION + '/haclusters/1/nodes/', methods=['GET', 'POST', 'PUT']) def get_nodeid(nodeid): if request.method == 'GET': return json.dumps(node.get_nodeid_info(nodeid)) - #node状态修改 + # node状态修改 @app.route('/api/' + API_VERSION + '/haclusters/1/nodes//', methods=['GET', 'POST', 'PUT']) @@ -299,7 +297,7 @@ def create_app(test_config=None): if request.method == 'PUT': return json.dumps(node.get_nodes_action(node_id, action)) - #获取资源创建 + # 获取资源创建 @app.route('/api/' + API_VERSION + '/haclusters/1/metas//', methods=['GET', 'POST', 'PUT']) diff --git a/scripts.py b/scripts.py index b21a836f47af53baa9ee14ba49856af81094cfd4..b58e6d49f758cbfaf84f4a2a96c559cda3001bc7 100644 --- a/scripts.py +++ b/scripts.py @@ -2,9 +2,8 @@ # !/usr/bin/python # coding: iso-8859-15 -import json + import os -import re import common_utils import stat @@ -21,7 +20,7 @@ def generate_scripts(data): if status != 0: return {'action': False, 'error': output} localnodeid = str(output).strip() - #configdata = get_hb_config_org(True) + # configdata = get_hb_config_org(True) configdata = None hbs = configdata['data'] diff --git a/zh_CN.po b/zh_CN.po index 586d9726634d6466814f695559d52783995734af..36e564e6dbe5e713d280c9cbb50cd82ac40b5ba3 100644 --- a/zh_CN.po +++ b/zh_CN.po @@ -16,6 +16,15 @@ msgstr "" msgid "\tThis message can be disabled with -Q\n" msgstr "" +msgid "Update cluster properties Success" +msgstr "更新集群属性成功" + +msgid "There" +msgstr "集群中有运行的资源,请先关闭" + +msgid "Change cluster success" +msgstr "改变集群成功" + msgid "\tThis will be the case even if" msgstr "即使" @@ -4962,6 +4971,12 @@ msgstr "磁盘心跳使用的“%s”名称变更为“%s”,导致现存配置 msgid "Please ensure that the HA service has already been started!" msgstr "请检查HA集群是否处于启动状态!" +msgid "Action on node success" +msgstr "节点上的操作成功" + +msgid "No input data" +msgstr "没有输入数据" + msgid "resources is running,please stop it first" msgstr "GFS资源处于运行状态,请先停止相关资源。" @@ -5121,6 +5136,10 @@ msgstr "安装license成功" msgid "Action on resource success" msgstr "资源操作成功" +msgid "Change node status success" +msgstr "更改节点状态成功" + + msgid "Check locate disk label success" msgstr "检测本地磁盘成功" @@ -5148,11 +5167,4 @@ msgstr "获取心跳信息失败" msgid "Init disk hb success" msgstr "初始化磁盘心跳成功" -msgid "Action on node success" -msgstr "节点上的操作成功" -msgid "Update cluster properties Success" -msgstr "更新集群属性成功" - -msgid "No input data" -msgstr "没有输入数据"