|
|
bf4277 |
--- pcs-0.9.115/pcs/resource.py.cloneonestepfix 2015-01-20 14:02:56.312974531 -0600
|
|
|
bf4277 |
+++ pcs-0.9.115/pcs/resource.py 2015-01-20 15:45:56.066239316 -0600
|
|
|
bf4277 |
@@ -379,26 +379,34 @@ def resource_create(ra_id, ra_type, ra_v
|
|
|
bf4277 |
% (", ".join(bad_opts), get_full_ra_type(ra_type, True)))
|
|
|
bf4277 |
if len(missing_req_opts) != 0:
|
|
|
bf4277 |
print "Warning: missing required option(s): '%s' for resource type: %s" % (", ".join(missing_req_opts),get_full_ra_type(ra_type,True))
|
|
|
bf4277 |
- xml_resource_string = create_xml_string("primitive", primitive_values, instance_attributes + op_attributes + meta_attributes)
|
|
|
bf4277 |
- args = ["cibadmin"]
|
|
|
bf4277 |
- args = args + ["-o", "resources", "-C", "-X", xml_resource_string]
|
|
|
bf4277 |
- output,retval = utils.run(args)
|
|
|
bf4277 |
- if retval != 0:
|
|
|
bf4277 |
- utils.err ("Unable to create resource/fence device\n" + output)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ resource_elem = create_xml_element("primitive", primitive_values, instance_attributes + op_attributes + meta_attributes)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ dom = utils.get_cib_dom()
|
|
|
bf4277 |
+ dom.getElementsByTagName("resources")[0].appendChild(resource_elem)
|
|
|
bf4277 |
|
|
|
bf4277 |
if "--clone" in utils.pcs_options or len(clone_opts) > 0:
|
|
|
bf4277 |
- resource_clone_create([ra_id] + clone_opts)
|
|
|
bf4277 |
+ dom = resource_clone_create_dom(dom, [ra_id] + clone_opts)
|
|
|
bf4277 |
if "--group" in utils.pcs_options:
|
|
|
bf4277 |
print "Warning: --group ignored when creating a clone"
|
|
|
bf4277 |
if "--master" in utils.pcs_options:
|
|
|
bf4277 |
print "Warning: --master ignored when creating a clone"
|
|
|
bf4277 |
elif "--master" in utils.pcs_options:
|
|
|
bf4277 |
- resource_master_create([ra_id+"-master",ra_id]+ master_meta_values)
|
|
|
bf4277 |
+ dom = resource_master_create_dom(dom, [ra_id+"-master",ra_id]+ master_meta_values)
|
|
|
bf4277 |
if "--group" in utils.pcs_options:
|
|
|
bf4277 |
print "Warning: --group ignored when creating a master"
|
|
|
bf4277 |
elif "--group" in utils.pcs_options:
|
|
|
bf4277 |
groupname = utils.pcs_options["--group"]
|
|
|
bf4277 |
- resource_group_add(groupname,[ra_id])
|
|
|
bf4277 |
+ dom = resource_group_add_dom(dom, groupname,[ra_id])
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ xml_resource_string = dom.documentElement.getElementsByTagName("resources")[0].toprettyxml()
|
|
|
bf4277 |
+ args = ["cibadmin"]
|
|
|
bf4277 |
+ args = args + ["-o", "resources", "-M", "-X", xml_resource_string]
|
|
|
bf4277 |
+ output,retval = utils.run(args)
|
|
|
bf4277 |
+ if retval != 0:
|
|
|
bf4277 |
+ utils.err ("Unable to create resource/fence device\n" + output)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+# utils.replace_cib_configuration(dom)
|
|
|
bf4277 |
|
|
|
bf4277 |
def resource_move(argv,clear=False,ban=False):
|
|
|
bf4277 |
other_options = []
|
|
|
bf4277 |
@@ -1087,6 +1095,57 @@ def resource_clone_create(argv, update =
|
|
|
bf4277 |
if retval != 0:
|
|
|
bf4277 |
utils.err("unable to create clone\n" + output)
|
|
|
bf4277 |
|
|
|
bf4277 |
+def resource_clone_create_dom(cib_dom, argv, update = False):
|
|
|
bf4277 |
+ name = argv.pop(0)
|
|
|
bf4277 |
+ element = None
|
|
|
bf4277 |
+ dom = cib_dom
|
|
|
bf4277 |
+ re = dom.documentElement.getElementsByTagName("resources")[0]
|
|
|
bf4277 |
+ for res in re.getElementsByTagName("primitive") + re.getElementsByTagName("group"):
|
|
|
bf4277 |
+ if res.getAttribute("id") == name:
|
|
|
bf4277 |
+ element = res
|
|
|
bf4277 |
+ break
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if element == None:
|
|
|
bf4277 |
+ utils.err("unable to find group or resource: %s" % name)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if utils.is_resource_clone(name):
|
|
|
bf4277 |
+ utils.err("%s is already a clone resource" % name)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if utils.is_group_clone(name):
|
|
|
bf4277 |
+ utils.err("cannot clone a group that has already been cloned")
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if utils.is_resource_masterslave(name):
|
|
|
bf4277 |
+ utils.err("%s is already a master/slave resource" % name)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ # If element is currently in a group and it's the last member, we get rid of the group
|
|
|
bf4277 |
+ if element.parentNode.tagName == "group" and element.parentNode.getElementsByTagName("primitive").length <= 1:
|
|
|
bf4277 |
+ element.parentNode.parentNode.removeChild(element.parentNode)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if update == True:
|
|
|
bf4277 |
+ if element.parentNode.tagName != "clone":
|
|
|
bf4277 |
+ utils.err("%s is not currently a clone" % name)
|
|
|
bf4277 |
+ clone = element.parentNode
|
|
|
bf4277 |
+ for ma in clone.getElementsByTagName("meta_attributes"):
|
|
|
bf4277 |
+ clone.removeChild(ma)
|
|
|
bf4277 |
+ else:
|
|
|
bf4277 |
+ clone = dom.createElement("clone")
|
|
|
bf4277 |
+ clone.setAttribute("id",name + "-clone")
|
|
|
bf4277 |
+ clone.appendChild(element)
|
|
|
bf4277 |
+ re.appendChild(clone)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ meta = dom.createElement("meta_attributes")
|
|
|
bf4277 |
+ meta.setAttribute("id",name + "-clone-meta")
|
|
|
bf4277 |
+ args = convert_args_to_tuples(argv)
|
|
|
bf4277 |
+ for arg in args:
|
|
|
bf4277 |
+ nvpair = dom.createElement("nvpair")
|
|
|
bf4277 |
+ nvpair.setAttribute("id", name+"-"+arg[0])
|
|
|
bf4277 |
+ nvpair.setAttribute("name", arg[0])
|
|
|
bf4277 |
+ nvpair.setAttribute("value", arg[1])
|
|
|
bf4277 |
+ meta.appendChild(nvpair)
|
|
|
bf4277 |
+ clone.appendChild(meta)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ return dom
|
|
|
bf4277 |
+
|
|
|
bf4277 |
def resource_clone_master_remove(argv):
|
|
|
bf4277 |
if len(argv) != 1:
|
|
|
bf4277 |
usage.resource()
|
|
|
bf4277 |
@@ -1218,6 +1277,90 @@ def resource_master_create(argv, update=
|
|
|
bf4277 |
if not update:
|
|
|
bf4277 |
constraint.constraint_resource_update(rg_id)
|
|
|
bf4277 |
|
|
|
bf4277 |
+def resource_master_create_dom(dom, argv, update=False):
|
|
|
bf4277 |
+ non_option_args_count = 0
|
|
|
bf4277 |
+ for arg in argv:
|
|
|
bf4277 |
+ if arg.find("=") == -1:
|
|
|
bf4277 |
+ non_option_args_count += 1
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if (non_option_args_count < 1):
|
|
|
bf4277 |
+ usage.resource()
|
|
|
bf4277 |
+ sys.exit(1)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if non_option_args_count == 1 and not update:
|
|
|
bf4277 |
+ argv.insert(0,argv[0]+"-master")
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ master_id = argv.pop(0)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if (update):
|
|
|
bf4277 |
+ master_found = False
|
|
|
bf4277 |
+ for master in dom.getElementsByTagName("master"):
|
|
|
bf4277 |
+ if master.getAttribute("id") == master_id:
|
|
|
bf4277 |
+ master_element = master
|
|
|
bf4277 |
+ master_found = True
|
|
|
bf4277 |
+ break
|
|
|
bf4277 |
+ if not master_found:
|
|
|
bf4277 |
+ utils.err("Unable to find multi-state resource with id %s" % master_id)
|
|
|
bf4277 |
+ else:
|
|
|
bf4277 |
+ rg_id = argv.pop(0)
|
|
|
bf4277 |
+ if utils.does_id_exist(dom, master_id):
|
|
|
bf4277 |
+ utils.err("%s already exists in the cib" % master_id)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if utils.is_resource_clone(rg_id):
|
|
|
bf4277 |
+ utils.err("%s is already a clone resource" % rg_id)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if utils.is_resource_masterslave(rg_id):
|
|
|
bf4277 |
+ utils.err("%s is already a master/slave resource" % rg_id)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ resources = dom.getElementsByTagName("resources")[0]
|
|
|
bf4277 |
+ rg_found = False
|
|
|
bf4277 |
+ for resource in (resources.getElementsByTagName("primitive") +
|
|
|
bf4277 |
+ resources.getElementsByTagName("group")):
|
|
|
bf4277 |
+ if resource.getAttribute("id") == rg_id:
|
|
|
bf4277 |
+ rg_found = True
|
|
|
bf4277 |
+ break
|
|
|
bf4277 |
+ if not rg_found:
|
|
|
bf4277 |
+ utils.err("Unable to find resource or group with id %s" % rg_id)
|
|
|
bf4277 |
+ # If the resource elements parent is a group, and it's the last
|
|
|
bf4277 |
+ # element in the group, we remove the group
|
|
|
bf4277 |
+ if resource.parentNode.tagName == "group" and resource.parentNode.getElementsByTagName("primitive").length <= 1:
|
|
|
bf4277 |
+ resource.parentNode.parentNode.removeChild(resource.parentNode)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ master_element = dom.createElement("master")
|
|
|
bf4277 |
+ master_element.setAttribute("id", master_id)
|
|
|
bf4277 |
+ resource.parentNode.removeChild(resource)
|
|
|
bf4277 |
+ master_element.appendChild(resource)
|
|
|
bf4277 |
+ resources.appendChild(master_element)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if len(argv) > 0:
|
|
|
bf4277 |
+ meta = None
|
|
|
bf4277 |
+ for child in master_element.childNodes:
|
|
|
bf4277 |
+ if child.nodeType != xml.dom.Node.ELEMENT_NODE:
|
|
|
bf4277 |
+ continue
|
|
|
bf4277 |
+ if child.tagName == "meta_attributes":
|
|
|
bf4277 |
+ meta = child
|
|
|
bf4277 |
+ if meta == None:
|
|
|
bf4277 |
+ meta = dom.createElement("meta_attributes")
|
|
|
bf4277 |
+ meta.setAttribute("id", master_id + "-meta_attributes")
|
|
|
bf4277 |
+ master_element.appendChild(meta)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ for arg in convert_args_to_tuples(argv):
|
|
|
bf4277 |
+ for nvpair in meta.getElementsByTagName("nvpair"):
|
|
|
bf4277 |
+ if nvpair.getAttribute("name") == arg[0]:
|
|
|
bf4277 |
+ meta.removeChild(nvpair)
|
|
|
bf4277 |
+ break
|
|
|
bf4277 |
+ if arg[1] == "":
|
|
|
bf4277 |
+ continue
|
|
|
bf4277 |
+ nvpair = dom.createElement("nvpair")
|
|
|
bf4277 |
+ nvpair.setAttribute("id", meta.getAttribute("id") + "-" + arg[0])
|
|
|
bf4277 |
+ nvpair.setAttribute("name", arg[0])
|
|
|
bf4277 |
+ nvpair.setAttribute("value", arg[1])
|
|
|
bf4277 |
+ meta.appendChild(nvpair)
|
|
|
bf4277 |
+ if len(meta.getElementsByTagName("nvpair")) == 0:
|
|
|
bf4277 |
+ master_element.removeChild(meta)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ return dom
|
|
|
bf4277 |
+
|
|
|
bf4277 |
def resource_master_remove(argv):
|
|
|
bf4277 |
if len(argv) < 1:
|
|
|
bf4277 |
usage.resource()
|
|
|
bf4277 |
@@ -1465,6 +1608,65 @@ def resource_group_add(group_name, resou
|
|
|
bf4277 |
else:
|
|
|
bf4277 |
utils.err("No resources to add.")
|
|
|
bf4277 |
|
|
|
bf4277 |
+def resource_group_add_dom(dom, group_name, resource_ids):
|
|
|
bf4277 |
+ top_element = dom.documentElement
|
|
|
bf4277 |
+ resources_element = top_element.getElementsByTagName("resources")[0]
|
|
|
bf4277 |
+ group_found = False
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if group_name == "":
|
|
|
bf4277 |
+ utils.err("group name cannot be empty")
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ for resource in top_element.getElementsByTagName("primitive"):
|
|
|
bf4277 |
+ if resource.getAttribute("id") == group_name:
|
|
|
bf4277 |
+ utils.err("Error: %s is already a resource" % group_name)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ for group in top_element.getElementsByTagName("group"):
|
|
|
bf4277 |
+ if group.getAttribute("id") == group_name:
|
|
|
bf4277 |
+ group_found = True
|
|
|
bf4277 |
+ mygroup = group
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if group_found == False:
|
|
|
bf4277 |
+ mygroup = dom.createElement("group")
|
|
|
bf4277 |
+ mygroup.setAttribute("id", group_name)
|
|
|
bf4277 |
+ resources_element.appendChild(mygroup)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ resources_to_move = []
|
|
|
bf4277 |
+ for resource_id in resource_ids:
|
|
|
bf4277 |
+ already_exists = False
|
|
|
bf4277 |
+ for resource in mygroup.getElementsByTagName("primitive"):
|
|
|
bf4277 |
+ # If resource already exists in group then we skip
|
|
|
bf4277 |
+ if resource.getAttribute("id") == resource_id:
|
|
|
bf4277 |
+ utils.err(resource_id + " already exists in " + group_name)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ resource_found = False
|
|
|
bf4277 |
+ for resource in resources_element.getElementsByTagName("primitive"):
|
|
|
bf4277 |
+ if resource.nodeType == xml.dom.minidom.Node.TEXT_NODE:
|
|
|
bf4277 |
+ continue
|
|
|
bf4277 |
+ if resource.getAttribute("id") == resource_id:
|
|
|
bf4277 |
+ if resource.parentNode.tagName == "master":
|
|
|
bf4277 |
+ utils.err("cannot group master/slave resources")
|
|
|
bf4277 |
+ if resource.parentNode.tagName == "clone":
|
|
|
bf4277 |
+ utils.err("cannot group clone resources")
|
|
|
bf4277 |
+ resources_to_move.append(resource)
|
|
|
bf4277 |
+ resource_found = True
|
|
|
bf4277 |
+ break
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if resource_found == False:
|
|
|
bf4277 |
+ utils.err("Unable to find resource: " + resource_id)
|
|
|
bf4277 |
+ continue
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ if resources_to_move:
|
|
|
bf4277 |
+ for resource in resources_to_move:
|
|
|
bf4277 |
+ oldParent = resource.parentNode
|
|
|
bf4277 |
+ mygroup.appendChild(resource)
|
|
|
bf4277 |
+ if oldParent.tagName == "group" and len(oldParent.getElementsByTagName("primitive")) == 0:
|
|
|
bf4277 |
+ oldParent.parentNode.removeChild(oldParent)
|
|
|
bf4277 |
+
|
|
|
bf4277 |
+ return dom
|
|
|
bf4277 |
+ else:
|
|
|
bf4277 |
+ utils.err("No resources to add.")
|
|
|
bf4277 |
+
|
|
|
bf4277 |
def resource_group_list(argv):
|
|
|
bf4277 |
group_xpath = "//group"
|
|
|
bf4277 |
group_xml = utils.get_cib_xpath(group_xpath)
|