Beispiel #1
0
def node_maintenance(argv, on=True):
    action = ["-v", "on"] if on else ["-D"]

    cluster_nodes = utils.getNodesFromPacemaker()
    nodes = []
    failed_count = 0
    if "--all" in utils.pcs_options:
        nodes = cluster_nodes
    elif argv:
        for node in argv:
            if node not in cluster_nodes:
                utils.err(
                    "Node '{0}' does not appear to exist in "
                    "configuration".format(node),
                    False
                )
                failed_count += 1
            else:
                nodes.append(node)
    else:
        nodes.append("")

    if failed_count > 0:
        sys.exit(1)

    for node in nodes:
        node_attr = ["-N", node] if node else []
        output, retval = utils.run(
            ["crm_attribute", "-t", "nodes", "-n", "maintenance"] + action +
            node_attr
        )
        if retval != 0:
            node_name = ("node '{0}'".format(node)) if argv else "current node"
            failed_count += 1
            if on:
                utils.err(
                    "Unable to put {0} to maintenance mode: {1}".format(
                        node_name, output
                    ),
                    False
                )
            else:
                utils.err(
                    "Unable to remove {0} from maintenance mode: {1}".format(
                        node_name, output
                    ),
                    False
                )
    if failed_count > 0:
        sys.exit(1)
Beispiel #2
0
def stonith_level_verify():
    dom = utils.get_cib_dom()
    corosync_nodes = []
    if utils.hasCorosyncConf():
        corosync_nodes = utils.getNodesFromCorosyncConf()
    pacemaker_nodes = utils.getNodesFromPacemaker()

    fls = dom.getElementsByTagName("fencing-level")
    for fl in fls:
        node = fl.getAttribute("target")
        devices = fl.getAttribute("devices")
        for dev in devices.split(","):
            if not utils.is_stonith_resource(dev):
                utils.err("%s is not a stonith id" % dev)
        if node not in corosync_nodes and node not in pacemaker_nodes:
            utils.err("%s is not currently a node" % node)
Beispiel #3
0
def stonith_level_verify():
    dom = utils.get_cib_dom()
    corosync_nodes = []
    if utils.hasCorosyncConf():
        corosync_nodes = utils.getNodesFromCorosyncConf()
    pacemaker_nodes = utils.getNodesFromPacemaker()

    fls = dom.getElementsByTagName("fencing-level")
    for fl in fls:
        node = fl.getAttribute("target")
        devices = fl.getAttribute("devices")
        for dev in devices.split(","):
            if not utils.is_stonith_resource(dev):
                utils.err("%s is not a stonith id" % dev)
        if node not in corosync_nodes and node not in pacemaker_nodes:
            utils.err("%s is not currently a node" % node)
Beispiel #4
0
def stonith_level_add(level, node, devices):
    dom = utils.get_cib_dom()

    if not re.search(r'^\d+$', level) or re.search(r'^0+$', level):
        utils.err("invalid level '{0}', use a positive integer".format(level))
    level = level.lstrip('0')
    if "--force" not in utils.pcs_options:
        for dev in devices.split(","):
            if not utils.is_stonith_resource(dev):
                utils.err("%s is not a stonith id (use --force to override)" %
                          dev)
        corosync_nodes = []
        if utils.hasCorosyncConf():
            corosync_nodes = utils.getNodesFromCorosyncConf()
        pacemaker_nodes = utils.getNodesFromPacemaker()
        if node not in corosync_nodes and node not in pacemaker_nodes:
            utils.err("%s is not currently a node (use --force to override)" %
                      node)

    ft = dom.getElementsByTagName("fencing-topology")
    if len(ft) == 0:
        conf = dom.getElementsByTagName("configuration")[0]
        ft = dom.createElement("fencing-topology")
        conf.appendChild(ft)
    else:
        ft = ft[0]

    fls = ft.getElementsByTagName("fencing-level")
    for fl in fls:
        if fl.getAttribute("target") == node and fl.getAttribute(
                "index") == level and fl.getAttribute("devices") == devices:
            utils.err(
                "unable to add fencing level, fencing level for node: %s, at level: %s, with device: %s already exists"
                % (node, level, devices))

    new_fl = dom.createElement("fencing-level")
    ft.appendChild(new_fl)
    new_fl.setAttribute("target", node)
    new_fl.setAttribute("index", level)
    new_fl.setAttribute("devices", devices)
    new_fl.setAttribute("id",
                        utils.find_unique_id(dom, "fl-" + node + "-" + level))

    utils.replace_cib_configuration(dom)
Beispiel #5
0
def node_maintenance(argv, on=True):
    action = ["-v", "on"] if on else ["-D"]

    cluster_nodes = utils.getNodesFromPacemaker()
    nodes = []
    failed_count = 0
    if "--all" in utils.pcs_options:
        nodes = cluster_nodes
    elif argv:
        for node in argv:
            if node not in cluster_nodes:
                utils.err(
                    "Node '{0}' does not appear to exist in "
                    "configuration".format(node), False)
                failed_count += 1
            else:
                nodes.append(node)
    else:
        nodes.append("")

    if failed_count > 0:
        sys.exit(1)

    for node in nodes:
        node_attr = ["-N", node] if node else []
        output, retval = utils.run(
            ["crm_attribute", "-t", "nodes", "-n", "maintenance"] + action +
            node_attr)
        if retval != 0:
            node_name = ("node '{0}'".format(node)) if argv else "current node"
            failed_count += 1
            if on:
                utils.err(
                    "Unable to put {0} to maintenance mode: {1}".format(
                        node_name, output), False)
            else:
                utils.err(
                    "Unable to remove {0} from maintenance mode: {1}".format(
                        node_name, output), False)
    if failed_count > 0:
        sys.exit(1)
Beispiel #6
0
def stonith_level_add(level, node, devices):
    dom = utils.get_cib_dom()

    if not re.search(r'^\d+$', level) or re.search(r'^0+$', level):
        utils.err("invalid level '{0}', use a positive integer".format(level))
    level = level.lstrip('0')
    if "--force" not in utils.pcs_options:
        for dev in devices.split(","):
            if not utils.is_stonith_resource(dev):
                utils.err("%s is not a stonith id (use --force to override)" % dev)
        corosync_nodes = []
        if utils.hasCorosyncConf():
            corosync_nodes = utils.getNodesFromCorosyncConf()
        pacemaker_nodes = utils.getNodesFromPacemaker()
        if node not in corosync_nodes and node not in pacemaker_nodes:
            utils.err("%s is not currently a node (use --force to override)" % node)

    ft = dom.getElementsByTagName("fencing-topology")
    if len(ft) == 0:
        conf = dom.getElementsByTagName("configuration")[0]
        ft = dom.createElement("fencing-topology")
        conf.appendChild(ft)
    else:
        ft = ft[0]

    fls = ft.getElementsByTagName("fencing-level")
    for fl in fls:
        if fl.getAttribute("target") == node and fl.getAttribute("index") == level and fl.getAttribute("devices") == devices:
            utils.err("unable to add fencing level, fencing level for node: %s, at level: %s, with device: %s already exists" % (node,level,devices))

    new_fl = dom.createElement("fencing-level")
    ft.appendChild(new_fl)
    new_fl.setAttribute("target", node)
    new_fl.setAttribute("index", level)
    new_fl.setAttribute("devices", devices)
    new_fl.setAttribute("id", utils.find_unique_id(dom, "fl-" + node +"-" + level))

    utils.replace_cib_configuration(dom)