def resource_clone_create(argv, update = False): name = argv.pop(0) element = None dom = utils.get_cib_dom() re = dom.documentElement.getElementsByTagName("resources")[0] for res in re.getElementsByTagName("primitive") + re.getElementsByTagName("group"): if res.getAttribute("id") == name: element = res break if element == None: print "Error: unable to find group or resource: %s" % name sys.exit(1) if update == True: if element.parentNode.tagName != "clone": print "Error: %s is not currently a clone" % name sys.exit(1) clone = element.parentNode for ma in clone.getElementsByTagName("meta_attributes"): clone.removeChild(ma) else: for c in re.getElementsByTagName("clone"): if c.getAttribute("id") == name + "-clone": print "Error: clone already exists for: %s" % name sys.exit(1) clone = dom.createElement("clone") clone.setAttribute("id",name + "-clone") clone.appendChild(element) re.appendChild(clone) meta = dom.createElement("meta_attributes") meta.setAttribute("id",name + "-clone-meta") args = convert_args_to_tuples(argv) for arg in args: nvpair = dom.createElement("nvpair") nvpair.setAttribute("id", name+"-"+arg[0]) nvpair.setAttribute("name", arg[0]) nvpair.setAttribute("value", arg[1]) meta.appendChild(nvpair) clone.appendChild(meta) xml_resource_string = re.toxml() args = ["cibadmin", "-o", "resources", "-R", "-X", xml_resource_string] output, retval = utils.run(args) if retval != 0: print output sys.exit(1)
def make_xmlresponse(result): """ construct a response from a dict of uri:error_code elements """ doc = minidom.getDOMImplementation().createDocument(None, "multistatus", None) doc.documentElement.setAttribute("xmlns:D","DAV:") doc.documentElement.tagName = "D:multistatus" for el,ec in result.items(): re=doc.createElementNS("DAV:","response") hr=doc.createElementNS("DAV:","href") st=doc.createElementNS("DAV:","status") huri=doc.createTextNode(quote_uri(el)) t=doc.createTextNode(gen_estring(ec)) st.appendChild(t) hr.appendChild(huri) re.appendChild(hr) re.appendChild(st) doc.documentElement.appendChild(re) return doc.toxml(encoding="utf-8")