diff --git a/resource.py b/resource.py index 46b5d390af6111bb8497ff698df513e2b7a1a200..ec711c3b60493e08a721f3c4fa7c43e30b35a325 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)