예제 #1
0
파일: cluster.py 프로젝트: lyon667/pcs
def get_cib(argv):
    if len(argv) == 0:
        print utils.get_cib(),
    else:
        filename = argv[0]
        f = open(filename, 'w')
        output = utils.get_cib()
        if output != "":
            f.write(utils.get_cib())
        else:
            print "Error: No data in the CIB"
            sys.exit(1)
예제 #2
0
def get_cib(argv):
    if len(argv) == 0:
        print utils.get_cib(),
    else:
        filename = argv[0]
        f = open(filename, 'w')
        output = utils.get_cib()
        if output != "":
            f.write(utils.get_cib())
        else:
            print "Error: No data in the CIB"
            sys.exit(1)
예제 #3
0
파일: cluster.py 프로젝트: deriamis/pcs
def get_cib(argv):
    if len(argv) == 0:
        print utils.get_cib(),
    else:
        filename = argv[0]
        try:
            f = open(filename, 'w')
            output = utils.get_cib()
            if output != "":
                    f.write(utils.get_cib())
            else:
                utils.err("No data in the CIB")
        except IOError as e:
            utils.err("Unable to write to file '%s', %s" % (filename, e.strerror))
예제 #4
0
파일: resource.py 프로젝트: bwheatley/pcs
def resource_clone_remove(argv):
    if len(argv) != 1:
        usage.resource()
        sys.exit(1)

    name = argv.pop()
    dom = xml.dom.minidom.parseString(utils.get_cib())
    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)
예제 #5
0
파일: resource.py 프로젝트: bwheatley/pcs
def resource_clone_create(argv, update = False):
    name = argv.pop(0)
    element = None
    dom = xml.dom.minidom.parseString(utils.get_cib())
    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)
예제 #6
0
파일: cluster.py 프로젝트: deriamis/pcs
def cluster_edit(argv):
    if 'EDITOR' in os.environ:
        editor = os.environ['EDITOR']
        tempcib = tempfile.NamedTemporaryFile('w+b',-1,".pcs")
        cib = utils.get_cib()
        tempcib.write(cib)
        tempcib.flush()
        try:
            subprocess.call([editor, tempcib.name])
        except OSError:
            utils.err("unable to open file with $EDITOR: " + editor)

        tempcib.seek(0)
        newcib = "".join(tempcib.readlines())
        if newcib == cib:
            print "CIB not updated, no changes detected"
        else:
            cluster_push([tempcib.name])

    else:
        utils.err("$EDITOR environment variable is not set")
예제 #7
0
파일: config.py 프로젝트: akanouras/pcs
def config_export_pcs_commands(argv, verbose=False):
    if no_clufter:
        utils.err(
            "Unable to perform export due to missing python-clufter package"
        )

    # parse options
    debug = "--debug" in utils.pcs_options
    force = "--force" in utils.pcs_options
    interactive = "--interactive" in utils.pcs_options
    invalid_args = False
    output_file = None
    for arg in argv:
        if "=" in arg:
            name, value = arg.split("=", 1)
            if name == "output":
                output_file = value
            else:
                invalid_args = True
        else:
            invalid_args = True
    if invalid_args or not output_file:
        usage.config(["export", "pcs-commands"])
        sys.exit(1)

    # prepare convertor options
    clufter_args = {
        "nocheck": force,
        "batch": True,
        "sys": "linux",
        # Make it work on RHEL6 as well for sure
        "color": "always" if sys.stdout.isatty() else "never",
        "coro": settings.corosync_conf_file,
        "ccs": settings.cluster_conf_file,
        "output": {"passin": "bytestring"},
        "start_wait": "60",
        "tmp_cib": "tmp-cib.xml",
        "force": force,
        "text_width": "80",
        "silent": True,
        "noguidance": True,
    }
    if interactive:
        if "EDITOR" not in os.environ:
            utils.err("$EDITOR environment variable is not set")
        clufter_args["batch"] = False
        clufter_args["editor"] = os.environ["EDITOR"]
    if debug:
        logging.getLogger("clufter").setLevel(logging.DEBUG)
    if utils.usefile:
        clufter_args["cib"] = os.path.abspath(utils.filename)
    else:
        clufter_args["cib"] = ("bytestring", utils.get_cib())
    if verbose:
        clufter_args["text_width"] = "-1"
        clufter_args["silent"] = False
        clufter_args["noguidance"] = False
    clufter_args_obj = type(str("ClufterOptions"), (object, ), clufter_args)
    cmd_name = "pcs2pcscmd-flatiron" if utils.is_rhel6() else "pcs2pcscmd-needle"

    # run convertor
    run_clufter(
        cmd_name, clufter_args_obj, debug, force,
        "Error: unable to export cluster configuration"
    )

    # save commands
    ok, message = utils.write_file(
        output_file,
        clufter_args_obj.output["passout"]
    )
    if not ok:
        utils.err(message)
예제 #8
0
파일: cluster.py 프로젝트: bwheatley/pcs
def get_cib():
    print utils.get_cib(),
예제 #9
0
파일: resource.py 프로젝트: bwheatley/pcs
def resource_group_add(group_name, resource_ids):
    out = utils.get_cib()
    dom = xml.dom.minidom.parseString(out)
    top_element = dom.documentElement
    resources_element = top_element.getElementsByTagName("resources")[0]
    group_found = False

    for resource in top_element.getElementsByTagName("primitive"):
        if resource.getAttribute("id") == group_name:
            print "Error: %s is already a resource" % group_name
            sys.exit(1)

    for group in top_element.getElementsByTagName("group"):
        if group.getAttribute("id") == group_name:
            group_found = True
            mygroup = group

    if group_found == False:
        mygroup = dom.createElement("group")
        mygroup.setAttribute("id", group_name)
        resources_element.appendChild(mygroup)


    resources_to_move = []
    for resource_id in resource_ids:
        already_exists = False
        for resource in mygroup.getElementsByTagName("primitive"):
            # If resource already exists in group then we skip
            if resource.getAttribute("id") == resource_id:
                print resource_id + " already exists in " + group_name + "\n"
                already_exists = True
                break
        if already_exists == True:
            continue

        resource_found = False
        for resource in resources_element.getElementsByTagName("primitive"):
            if resource.nodeType == xml.dom.minidom.Node.TEXT_NODE:
                continue
            if resource.getAttribute("id") == resource_id:
                resources_to_move.append(resource)
                resource_found = True
                break

        if resource_found == False:
            print "Unable to find resource: " + resource_id
            continue

    if resources_to_move:
        for resource in resources_to_move:
            oldParent = resource.parentNode
            mygroup.appendChild(resource)
            if oldParent.tagName == "group" and len(oldParent.getElementsByTagName("primitive")) == 0:
                oldParent.parentNode.removeChild(oldParent)
        
        xml_resource_string = resources_element.toxml()
        args = ["cibadmin", "-o", "resources", "-R", "-X", xml_resource_string]
        output,retval = utils.run(args)
        if retval != 0:
            print output,
    else:
        print "Error: No resources to add."
        sys.exit(1)