Exemplo n.º 1
0
def stonith_cmd(argv):
    if len(argv) < 1:
        sub_cmd, argv_next = "show", []
    else:
        sub_cmd, argv_next = argv[0], argv[1:]

    lib = utils.get_library_wrapper()
    modifiers = utils.get_modifiers()

    try:
        if sub_cmd == "help":
            usage.stonith([" ".join(argv_next)] if argv_next else [])
        elif sub_cmd == "list":
            stonith_list_available(lib, argv_next, modifiers)
        elif sub_cmd == "describe":
            stonith_list_options(lib, argv_next, modifiers)
        elif sub_cmd == "create":
            stonith_create(lib, argv_next, modifiers)
        elif sub_cmd == "update":
            if len(argv_next) > 1:
                stn_id = argv_next.pop(0)
                resource.resource_update(stn_id, argv_next)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "delete":
            if len(argv_next) == 1:
                stn_id = argv_next.pop(0)
                resource.resource_remove(stn_id)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "show":
            resource.resource_show(argv_next, True)
            levels = stonith_level_config_to_str(
                lib.fencing_topology.get_config())
            if levels:
                print("\n".join(indent(levels, 1)))
        elif sub_cmd == "level":
            stonith_level_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "fence":
            stonith_fence(argv_next)
        elif sub_cmd == "cleanup":
            resource.resource_cleanup(argv_next)
        elif sub_cmd == "refresh":
            resource.resource_refresh(argv_next)
        elif sub_cmd == "confirm":
            stonith_confirm(argv_next)
        elif sub_cmd == "get_fence_agent_info":
            get_fence_agent_info(argv_next)
        elif sub_cmd == "sbd":
            sbd_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "enable":
            resource.resource_enable_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "disable":
            resource.resource_disable_cmd(lib, argv_next, modifiers)
        else:
            raise CmdLineInputError()
    except LibraryError as e:
        utils.process_library_reports(e.args)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "stonith", sub_cmd)
Exemplo n.º 2
0
def stonith_cmd(argv):
    if len(argv) < 1:
        sub_cmd, argv_next = "show", []
    else:
        sub_cmd, argv_next = argv[0], argv[1:]

    lib = utils.get_library_wrapper()
    modifiers = utils.get_modificators()

    try:
        if sub_cmd == "help":
            usage.stonith(argv)
        elif sub_cmd == "list":
            stonith_list_available(lib, argv_next, modifiers)
        elif sub_cmd == "describe":
            stonith_list_options(lib, argv_next, modifiers)
        elif sub_cmd == "create":
            stonith_create(lib, argv_next, modifiers)
        elif sub_cmd == "update":
            if len(argv_next) > 1:
                stn_id = argv_next.pop(0)
                resource.resource_update(stn_id, argv_next)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "delete":
            if len(argv_next) == 1:
                stn_id = argv_next.pop(0)
                resource.resource_remove(stn_id)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "show":
            resource.resource_show(argv_next, True)
            levels = stonith_level_config_to_str(
                lib.fencing_topology.get_config()
            )
            if levels:
                print("\n".join(indent(levels, 1)))
        elif sub_cmd == "level":
            stonith_level_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "fence":
            stonith_fence(argv_next)
        elif sub_cmd == "cleanup":
            resource.resource_cleanup(argv_next)
        elif sub_cmd == "confirm":
            stonith_confirm(argv_next)
        elif sub_cmd == "get_fence_agent_info":
            get_fence_agent_info(argv_next)
        elif sub_cmd == "sbd":
            sbd_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "enable":
            resource.resource_enable(argv_next)
        elif sub_cmd == "disable":
            resource.resource_disable(argv_next)
        else:
            raise CmdLineInputError()
    except LibraryError as e:
        utils.process_library_reports(e.args)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "stonith", sub_cmd)
Exemplo n.º 3
0
def stonith_cmd(lib, argv, modifiers):
    if argv:
        sub_cmd, argv_next = argv[0], argv[1:]
    else:
        sub_cmd, argv_next = "status", []

    try:
        if sub_cmd == "help":
            usage.stonith([" ".join(argv_next)] if argv_next else [])
        elif sub_cmd == "list":
            stonith_list_available(lib, argv_next, modifiers)
        elif sub_cmd == "describe":
            stonith_list_options(lib, argv_next, modifiers)
        elif sub_cmd == "create":
            stonith_create(lib, argv_next, modifiers)
        elif sub_cmd == "update":
            resource.resource_update(lib, argv_next, modifiers)
        elif sub_cmd in {"delete", "remove"}:
            resource.resource_remove_cmd(lib, argv_next, modifiers)
        # TODO remove, deprecated command
        # replaced with 'stonith status' and 'stonith config'
        elif sub_cmd == "show":
            resource.resource_show(lib, argv_next, modifiers, stonith=True)
            print_stonith_levels(lib)
        elif sub_cmd == "status":
            resource.resource_status(lib, argv_next, modifiers, stonith=True)
            print_stonith_levels(lib)
        elif sub_cmd == "config":
            resource.resource_config(lib, argv_next, modifiers, stonith=True)
            print_stonith_levels(lib)
        elif sub_cmd == "level":
            stonith_level_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "fence":
            stonith_fence(lib, argv_next, modifiers)
        elif sub_cmd == "cleanup":
            resource.resource_cleanup(lib, argv_next, modifiers)
        elif sub_cmd == "refresh":
            resource.resource_refresh(lib, argv_next, modifiers)
        elif sub_cmd == "confirm":
            stonith_confirm(lib, argv_next, modifiers)
        elif sub_cmd == "get_fence_agent_info":
            get_fence_agent_info(lib, argv_next, modifiers)
        elif sub_cmd == "sbd":
            sbd_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "enable":
            resource.resource_enable_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "disable":
            resource.resource_disable_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "history":
            stonith_history_cmd(lib, argv_next, modifiers)
        else:
            raise CmdLineInputError()
    except LibraryError as e:
        utils.process_library_reports(e.args)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "stonith", sub_cmd)
Exemplo n.º 4
0
def stonith_create(lib, argv, modifiers):
    if modifiers["before"] and modifiers["after"]:
        raise error("you cannot specify both --before and --after{0}".format(
            "" if modifiers["group"] else " and you have to specify --group"
        ))

    if not modifiers["group"]:
        if modifiers["before"]:
            raise error("you cannot use --before without --group")
        elif modifiers["after"]:
            raise error("you cannot use --after without --group")

    if len(argv) < 2:
        usage.stonith(["create"])
        sys.exit(1)

    stonith_id = argv[0]
    stonith_type = argv[1]

    parts = parse_create_args(argv[2:])

    settings = dict(
        allow_absent_agent=modifiers["force"],
        allow_invalid_operation=modifiers["force"],
        allow_invalid_instance_attributes=modifiers["force"],
        ensure_disabled=modifiers["disabled"],
        use_default_operations=not modifiers["no-default-ops"],
        wait=modifiers["wait"],
    )

    if not modifiers["group"]:
        lib.stonith.create(
            stonith_id, stonith_type, parts["op"],
            parts["meta"],
            parts["options"],
            **settings
        )
    else:
        adjacent_resource_id = None
        put_after_adjacent = False
        if modifiers["after"]:
            adjacent_resource_id = modifiers["after"]
            put_after_adjacent = True
        if modifiers["before"]:
            adjacent_resource_id = modifiers["before"]
            put_after_adjacent = False

        lib.stonith.create_in_group(
            stonith_id, stonith_type, modifiers["group"], parts["op"],
            parts["meta"],
            parts["options"],
            adjacent_resource_id=adjacent_resource_id,
            put_after_adjacent=put_after_adjacent,
            **settings
        )
Exemplo n.º 5
0
def stonith_create(lib, argv, modifiers):
    if modifiers["before"] and modifiers["after"]:
        raise error("you cannot specify both --before and --after{0}".format(
            "" if modifiers["group"] else " and you have to specify --group"
        ))

    if not modifiers["group"]:
        if modifiers["before"]:
            raise error("you cannot use --before without --group")
        elif modifiers["after"]:
            raise error("you cannot use --after without --group")

    if len(argv) < 2:
        usage.stonith(["create"])
        sys.exit(1)

    stonith_id = argv[0]
    stonith_type = argv[1]

    parts = parse_create_args(argv[2:])

    settings = dict(
        allow_absent_agent=modifiers["force"],
        allow_invalid_operation=modifiers["force"],
        allow_invalid_instance_attributes=modifiers["force"],
        ensure_disabled=modifiers["disabled"],
        use_default_operations=not modifiers["no-default-ops"],
        wait=modifiers["wait"],
    )

    if not modifiers["group"]:
        lib.stonith.create(
            stonith_id, stonith_type, parts["op"],
            parts["meta"],
            parts["options"],
            **settings
        )
    else:
        adjacent_resource_id = None
        put_after_adjacent = False
        if modifiers["after"]:
            adjacent_resource_id = modifiers["after"]
            put_after_adjacent = True
        if modifiers["before"]:
            adjacent_resource_id = modifiers["before"]
            put_after_adjacent = False

        lib.stonith.create_in_group(
            stonith_id, stonith_type, modifiers["group"], parts["op"],
            parts["meta"],
            parts["options"],
            adjacent_resource_id=adjacent_resource_id,
            put_after_adjacent=put_after_adjacent,
            **settings
        )
Exemplo n.º 6
0
def stonith_cmd(argv):
    lib = utils.get_library_wrapper()
    modifiers = utils.get_modificators()
    if len(argv) == 0:
        argv = ["show"]

    sub_cmd = argv.pop(0)
    try:
        if (sub_cmd == "help"):
            usage.stonith(argv)
        elif (sub_cmd == "list"):
            stonith_list_available(argv)
        elif (sub_cmd == "describe"):
            if len(argv) == 1:
                stonith_list_options(argv[0])
            else:
                raise CmdLineInputError()
        elif (sub_cmd == "create"):
            stonith_create(argv)
        elif (sub_cmd == "update"):
            if len(argv) > 1:
                stn_id = argv.pop(0)
                resource.resource_update(stn_id,argv)
            else:
                raise CmdLineInputError()
        elif (sub_cmd == "delete"):
            if len(argv) == 1:
                stn_id = argv.pop(0)
                resource.resource_remove(stn_id)
            else:
                raise CmdLineInputError()
        elif (sub_cmd == "show"):
            resource.resource_show(argv, True)
            stonith_level([])
        elif (sub_cmd == "level"):
            stonith_level(argv)
        elif (sub_cmd == "fence"):
            stonith_fence(argv)
        elif (sub_cmd == "cleanup"):
            resource.resource_cleanup(argv)
        elif (sub_cmd == "confirm"):
            stonith_confirm(argv)
        elif (sub_cmd == "get_fence_agent_info"):
            get_fence_agent_info(argv)
        elif (sub_cmd == "sbd"):
            sbd_cmd(lib, argv, modifiers)
        else:
            raise CmdLineInputError()
    except LibraryError as e:
        utils.process_library_reports(e.args)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "stonith", sub_cmd)
Exemplo n.º 7
0
def stonith_cmd(argv):
    if len(argv) == 0:
        argv = ["show"]

    sub_cmd = argv.pop(0)
    if (sub_cmd == "help"):
        usage.stonith(argv)
    elif (sub_cmd == "list"):
        stonith_list_available(argv)
    elif (sub_cmd == "describe"):
        if len(argv) == 1:
            stonith_list_options(argv[0])
        else:
            usage.stonith()
            sys.exit(1)
    elif (sub_cmd == "create"):
        stonith_create(argv)
    elif (sub_cmd == "update"):
        if len(argv) > 1:
            stn_id = argv.pop(0)
            resource.resource_update(stn_id,argv)
        else:
            usage.stonith(["update"])
            sys.exit(1)
    elif (sub_cmd == "delete"):
        if len(argv) == 1:
            stn_id = argv.pop(0)
            resource.resource_remove(stn_id)
        else:
            usage.stonith(["delete"])
            sys.exit(1)
    elif (sub_cmd == "show"):
        resource.resource_show(argv, True)
        stonith_level([])
    elif (sub_cmd == "level"):
        stonith_level(argv)
    elif (sub_cmd == "fence"):
        stonith_fence(argv)
    elif (sub_cmd == "cleanup"):
        try:
            resource.resource_cleanup(argv)
        except utils.CmdLineInputError as e:
            exit_on_cmdline_input_errror('cleanup')
        except LibraryError as e:
            utils.process_library_reports(e.args)
    elif (sub_cmd == "confirm"):
        stonith_confirm(argv)
    elif (sub_cmd == "get_fence_agent_info"):
        get_fence_agent_info(argv)
    else:
        usage.stonith()
        sys.exit(1)
Exemplo n.º 8
0
def stonith_cmd(argv):
    if len(argv) < 1:
        sub_cmd, argv_next = "show", []
    else:
        sub_cmd, argv_next = argv[0], argv[1:]

    lib = utils.get_library_wrapper()
    modifiers = utils.get_modificators()

    try:
        if sub_cmd == "help":
            usage.stonith(argv)
        elif sub_cmd == "list":
            stonith_list_available(lib, argv_next, modifiers)
        elif sub_cmd == "describe":
            stonith_list_options(lib, argv_next, modifiers)
        elif sub_cmd == "create":
            stonith_create(argv_next)
        elif sub_cmd == "update":
            if len(argv_next) > 1:
                stn_id = argv_next.pop(0)
                resource.resource_update(stn_id, argv_next)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "delete":
            if len(argv_next) == 1:
                stn_id = argv_next.pop(0)
                resource.resource_remove(stn_id)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "show":
            resource.resource_show(argv_next, True)
            stonith_level([])
        elif sub_cmd == "level":
            stonith_level(argv_next)
        elif sub_cmd == "fence":
            stonith_fence(argv_next)
        elif sub_cmd == "cleanup":
            resource.resource_cleanup(argv_next)
        elif sub_cmd == "confirm":
            stonith_confirm(argv_next)
        elif sub_cmd == "get_fence_agent_info":
            get_fence_agent_info(argv_next)
        elif sub_cmd == "sbd":
            sbd_cmd(lib, argv_next, modifiers)
        else:
            raise CmdLineInputError()
    except LibraryError as e:
        utils.process_library_reports(e.args)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "stonith", sub_cmd)
Exemplo n.º 9
0
def stonith_create(argv):
    if len(argv) < 2:
        usage.stonith(["create"])
        sys.exit(1)

    stonith_id = argv.pop(0)
    stonith_type = argv.pop(0)
    st_values, op_values, meta_values = resource.parse_resource_options(
        argv, with_clone=False
    )
    metadata = utils.get_stonith_metadata("/usr/sbin/" + stonith_type)
    if metadata:
        if stonith_does_agent_provide_unfencing(metadata):
            meta_values = [
                meta for meta in meta_values if not meta.startswith("provides=")
            ]
            meta_values.append("provides=unfencing")
    resource.resource_create(
        stonith_id, "stonith:" + stonith_type, st_values, op_values, meta_values
    )
Exemplo n.º 10
0
def stonith_create(argv):
    if len(argv) < 2:
        usage.stonith(["create"])
        sys.exit(1)

    stonith_id = argv.pop(0)
    stonith_type = argv.pop(0)
    st_values, op_values, meta_values = resource.parse_resource_options(
        argv, with_clone=False
    )

    try:
        metadata = lib_ra.StonithAgent(
            utils.cmd_runner(),
            stonith_type
        )
        if metadata.get_provides_unfencing():
            meta_values = [
                meta for meta in meta_values if not meta.startswith("provides=")
            ]
            meta_values.append("provides=unfencing")
    except lib_ra.ResourceAgentError as e:
        forced = utils.get_modificators().get("force", False)
        if forced:
            severity = ReportItemSeverity.WARNING
        else:
            severity = ReportItemSeverity.ERROR
        utils.process_library_reports([
            lib_ra.resource_agent_error_to_report_item(
                e, severity, not forced
            )
        ])
    except LibraryError as e:
        utils.process_library_reports(e.args)

    resource.resource_create(
        stonith_id, "stonith:" + stonith_type, st_values, op_values, meta_values,
        group=utils.pcs_options.get("--group", None)
    )
Exemplo n.º 11
0
def stonith_level(argv):
    if len(argv) == 0:
        stonith_level_show()
        return

    subcmd = argv.pop(0)

    if subcmd == "add":
        if len(argv) < 3:
            usage.stonith(["level add"])
            sys.exit(1)
        stonith_level_add(argv[0], argv[1], ",".join(argv[2:]))
    elif subcmd in ["remove","delete"]:
        if len(argv) < 1:
            usage.stonith(["level remove"])
            sys.exit(1)

        node = ""
        devices = ""
        if len(argv) == 2:
            node = argv[1]
        elif len(argv) > 2:
            node = argv[1]
            devices = ",".join(argv[2:])

        stonith_level_rm(argv[0], node, devices)
    elif subcmd == "clear":
        if len(argv) == 0:
            stonith_level_clear()
        else:
            stonith_level_clear(argv[0])
    elif subcmd == "verify":
        stonith_level_verify()
    else:
        print("pcs stonith level: invalid option -- '%s'" % subcmd)
        usage.stonith(["level"])
        sys.exit(1)
Exemplo n.º 12
0
def stonith_level(argv):
    if len(argv) == 0:
        stonith_level_show()
        return

    subcmd = argv.pop(0)

    if subcmd == "add":
        if len(argv) < 3:
            usage.stonith(["level add"])
            sys.exit(1)
        stonith_level_add(argv[0], argv[1], ",".join(argv[2:]))
    elif subcmd in ["remove", "delete"]:
        if len(argv) < 1:
            usage.stonith(["level remove"])
            sys.exit(1)

        node = ""
        devices = ""
        if len(argv) == 2:
            node = argv[1]
        elif len(argv) > 2:
            node = argv[1]
            devices = ",".join(argv[2:])

        stonith_level_rm(argv[0], node, devices)
    elif subcmd == "clear":
        if len(argv) == 0:
            stonith_level_clear()
        else:
            stonith_level_clear(argv[0])
    elif subcmd == "verify":
        stonith_level_verify()
    else:
        print("pcs stonith level: invalid option -- '%s'" % subcmd)
        usage.stonith(["level"])
        sys.exit(1)
Exemplo n.º 13
0
from pcs import (
    resource,
    stonith,
    usage,
)
from pcs.cli.common.routing import create_router

from .resource_stonith_common import (
    resource_defaults_cmd,
    resource_op_defaults_cmd,
)

stonith_cmd = create_router(
    {
        "help":
        lambda lib, argv, modifiers: print(usage.stonith(argv)),
        "list":
        stonith.stonith_list_available,
        "describe":
        stonith.stonith_list_options,
        "config":
        stonith.config_cmd,
        "create":
        stonith.stonith_create,
        "update":
        stonith.update_cmd,
        "update-scsi-devices":
        stonith.stonith_update_scsi_devices,
        "delete":
        stonith.delete_cmd,
        "remove":
Exemplo n.º 14
0
from pcs import (
    resource,
    stonith,
    usage,
)
from pcs.cli.common.routing import create_router


stonith_cmd = create_router(
    {
        "help": lambda lib, argv, modifiers: usage.stonith(argv),
        "list": stonith.stonith_list_available,
        "describe": stonith.stonith_list_options,
        "create": stonith.stonith_create,
        "update": resource.resource_update,
        "update-scsi-devices": stonith.stonith_update_scsi_devices,
        "delete": resource.resource_remove_cmd,
        "remove": resource.resource_remove_cmd,
        # TODO remove, deprecated command
        # replaced with 'stonith status' and 'stonith config'
        "show": stonith.stonith_show_cmd,
        "status": stonith.stonith_status_cmd,
        "config": stonith.stonith_config_cmd,
        "level": create_router(
            {
                "add": stonith.stonith_level_add_cmd,
                "clear": stonith.stonith_level_clear_cmd,
                "config": stonith.stonith_level_config_cmd,
                "remove": stonith.stonith_level_remove_cmd,
                "delete": stonith.stonith_level_remove_cmd,
                "verify": stonith.stonith_level_verify_cmd,
Exemplo n.º 15
0
from pcs import (
    resource,
    stonith,
    usage,
)
from pcs.cli.common.routing import create_router


stonith_cmd = create_router(
    {
        "help": lambda lib, argv, modifiers: usage.stonith(argv),
        "list": stonith.stonith_list_available,
        "describe": stonith.stonith_list_options,
        "create": stonith.stonith_create,
        "update": resource.resource_update,
        "delete": resource.resource_remove_cmd,
        "remove": resource.resource_remove_cmd,
        # TODO remove, deprecated command
        # replaced with 'stonith status' and 'stonith config'
        "show": stonith.stonith_show_cmd,
        "status": stonith.stonith_status_cmd,
        "config": stonith.stonith_config_cmd,
        "level": create_router(
            {
                "add": stonith.stonith_level_add_cmd,
                "clear": stonith.stonith_level_clear_cmd,
                "config": stonith.stonith_level_config_cmd,
                "remove": stonith.stonith_level_remove_cmd,
                "delete": stonith.stonith_level_remove_cmd,
                "verify": stonith.stonith_level_verify_cmd,
            },
Exemplo n.º 16
0
def exit_on_cmdline_input_errror(usage_name):
    usage.stonith([usage_name])
    sys.exit(1)