示例#1
0
文件: resource.py 项目: jnpkrn/pcs
def resource_clone_remove(argv):
    if len(argv) != 1:
        usage.resource()
        sys.exit(1)

    name = argv.pop()
    dom = utils.get_cib_dom()
    re = dom.documentElement.getElementsByTagName("resources")[0]

    found = False
    for res in re.getElementsByTagName("primitive") + re.getElementsByTagName("group"):
        if res.getAttribute("id") == name:
            clone = res.parentNode
            if clone.tagName != "clone":
                print "Error: %s is not in a clone" % name
                sys.exit(1)
            clone.parentNode.appendChild(res)
            clone.parentNode.removeChild(clone)
            found = True
            break

    if found == False:
        print "Error: could not find resource or group: %s" % name
        sys.exit(1)

    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)
示例#2
0
文件: resource.py 项目: jnpkrn/pcs
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)