From c8fb7c747537fcf45d9194415fdd03deb65a04ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=AD=90=E8=B4=A4?= <2367744612@qq.com> Date: Mon, 6 Jul 2020 16:40:13 +0800 Subject: [PATCH] create_resource_failed --- resource.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/resource.py b/resource.py index 46b5d39..ec711c3 100644 --- a/resource.py +++ b/resource.py @@ -992,6 +992,39 @@ def resource_action(rsc_id, action, data): rsc_id ) + " --set-parameter target-role --meta --parameter-value started" status, output = common_utils.run_cmd(cmd_str) + cmd_target_role = "crm_resource --resource " + str( + rsc_id) + " --query-xml" + status, output = common_utils.run_cmd(cmd_target_role) + xml_str = output.split("xml:")[1] + json_str = json.dumps(xmltodict.parse(xml_str)) + json_dict = json.loads(json_str) + print(json_dict) + clone_group = [] + action_id = '' + for i in json_dict: + action_id = i + if action_id == "primitive": + value = json_dict["primitive"]["meta_attributes"]["nvpair"][ + "@value"] + if action_id == "group": + value = json_dict["group"]["meta_attributes"]["nvpair"]["@value"] + if action_id == "clone": + for i in json_dict['clone']: + group_res = i + clone_group.append(group_res) + if clone_group[1] == "group": + print(1) + value = json_dict["clone"]["meta_attributes"]["nvpair"][ + "@value"] + else: + print(2) + value = json_dict["clone"]["primitive"]["meta_attributes"][ + "nvpair"]["@value"] + if value == "stopped": + return { + 'action': False, + 'error': _("The resource failed to start because of a problem") + } if status != 0: return {'action': False, 'error': _(output)} return {"action": True, "info": _("Action on resource success")} @@ -1427,7 +1460,8 @@ def create_resource(data): if rsc_id is resource_id['id'] or rsc_id == resource_id['id']: return { 'action': False, - 'error': " %s Resources already exist" % (str(rsc_id)) + 'error': "id: %s " + "组资源已经存在" % str(rsc_id) } if "provider" in data: provider = " provider=\"" + str(data["provider"]) + "\"" @@ -1489,7 +1523,8 @@ def create_resource(data): if rsc_id is resource_id['id'] or rsc_id == resource_id['id']: return { 'action': False, - 'error': " %s Resources already exist" % (str(rsc_id)) + 'error': "id: %s " + "组资源已经存在" % str(rsc_id) } for r in rscs: cmd_str = cmd_str + " " + str(r) -- Gitee