diff --git a/common_utils.py b/common_utils.py index d911d5a2b381728e00e4f7808603942002e0a477..b7524823adfcaa1ac034566fffec19e764143751 100644 --- a/common_utils.py +++ b/common_utils.py @@ -446,7 +446,7 @@ def get_resource_info_from_xml(cl, et): "provider": et.get("provider", "") } if cl == "clone": - #如果是组资源 + # 如果是组资源 if et.find("group"): return get_resource_info_from_xml("group", et.find("group")) else: @@ -476,25 +476,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..cc768d7945641ad478c9d16f16660477da9d5ebe 100644 --- a/config.py +++ b/config.py @@ -44,7 +44,7 @@ import re def get_node_list(): - #读取文件 + # 读取文件 filename = "/etc/corosync/corosync.conf" try: read = open(filename) @@ -53,19 +53,19 @@ def get_node_list(): 'action': False, 'error': "File " + filename + " doesn't exist!" } - node_list = [] #存储文件内数据 - line = read.readline() #按行读取文件内容 + 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 +109,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 +126,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 +149,7 @@ def get_hb_by_hosts(): def get_hb_conf(): - #判断集群是否存在 + # 判断集群是否存在 if is_cluster_exist(): return get_hb_dict() else: @@ -165,7 +165,7 @@ def get_hb_dict(): index = 0 while index < len(node_list): if node_list[index] == "node {": - #开始按照node {进行分割遍历每个node + # 开始按照node {进行分割遍历每个node index += 1 node_info = {} while index < len(node_list) and node_list[index] != "node {": @@ -184,7 +184,7 @@ def get_hb_dict(): ] """ res = {} - #形成指定格式 + # 形成指定格式 for i in nodes: """ {'ring0_addr': 'ha3', 'ring1_addr': 'ha4', 'name': 'ha3', 'nodeid': '1'} @@ -192,23 +192,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(): @@ -252,26 +252,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..f113aa7c4119a9c9da9164f090d6381e6daa9f2d 100644 Binary files a/ha-api.mo and b/ha-api.mo differ diff --git a/node.py b/node.py index fee3651be7b1279315c8bb11fc4c044e6ccbc17c..88c598d25c6dc76623a580c58c654d4dfe7a848c 100644 --- a/node.py +++ b/node.py @@ -84,7 +84,7 @@ def get_node_info(): if data != []: return {"action": True, "data": data} else: - return {"action": False, "data": "Get node failed!"} + return {"action": False, "data": _("Get node failed!")} def get_nodeid_info(nodeid): @@ -93,34 +93,34 @@ def get_nodeid_info(nodeid): "|awk -F ' ' '{print $1}'") nodeip = str(output) if nameid == {}: - return {'action': False, "data": "Get nodeid failed!"} + return {'action': False, "data": _("Get nodeid failed!")} else: return {'action': True, 'data': {'ips': nodeip}} 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"} + 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..667dbe8f60a6822ee8a2a39079cb41e1ca00cf83 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 = [] @@ -1944,10 +1939,5 @@ 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/scripts.py b/scripts.py index b21a836f47af53baa9ee14ba49856af81094cfd4..5aa5672c730e4fdccc002349a678e499e844e168 100644 --- a/scripts.py +++ b/scripts.py @@ -21,14 +21,14 @@ 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'] hbaddrs = [] for hb in hbs: if 'hbaddrs' in hb: - hbaddrs = hb['hbaddrs'] + hbaddrs = hb['hbaddrs'] for node in hbaddrs: nodeid = node['nodeid'] diff --git a/zh_CN.po b/zh_CN.po index 586d9726634d6466814f695559d52783995734af..8ec6762084932491539833e26b890fbe7d5fa595 100644 --- a/zh_CN.po +++ b/zh_CN.po @@ -22,6 +22,9 @@ msgstr "即使" msgid "\tThis will prevent" msgstr "这将阻止" +msgid "Update cluster properties Success" +msgstr "更新集群属性成功" + #: pacemaker-mgmt.new/mgmt/client/haclient.py.in:3180 #: pacemaker-mgmt.new/mgmt/client/haclient.py.in:3369 #: pacemaker-mgmt.new/mgmt/client/haclient.py.in:19263 @@ -3168,6 +3171,21 @@ msgstr "然后" msgid "Then Action" msgstr "然后操作" +msgid "There" +msgstr "集群中有运行的资源,请先关闭" + +msgid "Change cluster success" +msgstr "改变集群成功" + +msgid "Change node status success" +msgstr "更改节点状态成功" + +msgid "error info" +msgstr "更改节点信息错误" + +msgid "Get nodeid failed!" +msgstr "得到nodeid失败!" + #: pacemaker-mgmt.new/mgmt/client/haclient.py.in:2859 #: pacemaker-mgmt.new/mgmt/client/haclient.py.in:3099 #: pacemaker-mgmt.new/mgmt/client/haclient.py.in:8357