예제 #1
0
def delete_node(nodename):
    rc, stdout, stderr = AgentShell.run_old(["crm_node", "-l"])
    node_id = None
    for line in stdout.split("\n"):
        node_id, name, status = line.split(" ")
        if name == nodename:
            break
    AgentShell.try_run(["crm_node", "--force", "-R", node_id])
    cibxpath("delete", '//nodes/node[@uname="{}"]'.format(nodename))
    cibxpath("delete", '//status/node_state[@uname="{}"]'.format(nodename))
예제 #2
0
def unmount_target(uuid):
    # This is called by the Target RA from corosync

    # only unmount targets that are controlled by chroma:Target
    try:
        result = cibxpath("query", "//primitive")
    except OSError as err:
        if err.rc == errno.ENOENT:
            exit(-1)
        raise err

    dom = ET.fromstring(result.stdout)

    # Searches for <nvpair name="target" value=uuid> in
    # <primitive provider="chroma" type="Target"> in dom
    if (next(
        (ops for res in dom.findall(".//primitive")
         if res.get("provider") == "chroma" and res.get("type") == "Target"
         for ops in res.findall(".//nvpair")
         if ops.get("name") == "target" and ops.get("value") == uuid),
            None,
    ) is not None):
        return
    dom.unlink()

    info = _get_target_config(uuid)

    filesystem = FileSystem(info["backfstype"], info["bdev"])

    filesystem.umount()

    if agent_result_is_error(export_target(info["device_type"], info["bdev"])):
        exit(-1)
예제 #3
0
def _unconfigure_target_ha(ha_label, force=False):
    if force:
        extra = ["--force"]
    else:
        extra = []

    if _resource_exists(_group_name(ha_label)):
        path = '//group[@id="{}"]'.format(_group_name(ha_label))
    else:
        path = '//primitive[@id="{}"]'.format(ha_label)

    return cibxpath("delete", path, extra)
예제 #4
0
def _find_resource_constraint(ha_label, primary):
    result = cibxpath(
        "query",
        '//constraints/rsc_location[@id="{}"]'.format(_constraint(ha_label, primary)),
    )

    # Single line: <rsc_location id="HA_LABEL-PRIMARY" node="NODE" rsc="HA_LABEL" score="20"/>
    match = re.match(r".*node=.([^\"]+)", result.stdout)

    if match:
        return match.group(1)

    return None
예제 #5
0
def _unconfigure_target_priority(primary, ha_label):
    return cibxpath(
        "delete",
        '//rsc_location[@id="{}"]'.format(_constraint(ha_label, primary)))