Example #1
0
def recipient_add(lib, argv, modifiers):
    """
    Options:
      * -f - CIB file (in lib wrapper)
      * --force - allows not unique recipient values
    """
    modifiers.ensure_only_supported("-f", "--force")
    if len(argv) < 2:
        raise CmdLineInputError()

    alert_id = argv[0]

    sections = parse_cmd_sections(argv[1:], set(["options", "meta"]))
    main_args = prepare_options(sections["main"])
    ensure_only_allowed_options(main_args, ["description", "id", "value"])

    lib.alert.add_recipient(
        alert_id,
        main_args.get("value", None),
        prepare_options(sections["options"]),
        prepare_options(sections["meta"]),
        recipient_id=main_args.get("id", None),
        description=main_args.get("description", None),
        allow_same_value=modifiers.get("--force")
    )
Example #2
0
def quorum_device_update_cmd(lib, argv, modifiers):
    """
    Options:
      * --force - allow unknown options
      * --skip-offline - skip offline nodes
      * --corosync_conf - mocked corosync configuration file
      * --request-timeout - HTTP timeout, has effect only if --corosync_conf is
        not specified
    """
    modifiers.ensure_only_supported(
        "--force", "--skip-offline", "--request-timeout", "--corosync_conf"
    )
    groups = _parse_quorum_device_groups(argv)
    if not groups:
        raise CmdLineInputError()
    generic_options = parse_args.prepare_options(groups.get("generic", []))
    model_options = parse_args.prepare_options(groups.get("model", []))
    heuristics_options = parse_args.prepare_options(
        groups.get("heuristics", [])
    )

    if "model" in generic_options:
        raise CmdLineInputError("Model cannot be specified in generic options")

    lib.quorum.update_device(
        model_options,
        generic_options,
        heuristics_options,
        force_options=modifiers.get("--force"),
        skip_offline_nodes=modifiers.get("--skip-offline"),
    )
Example #3
0
File: quorum.py Project: idevat/pcs
def quorum_device_add_cmd(lib, argv, modificators):
    # we expect "model" keyword once, followed by the actual model value
    options_lists = parse_args.split_list(argv, "model")
    if len(options_lists) != 2:
        raise CmdLineInputError()
    # check if model value was specified
    if not options_lists[1] or "=" in options_lists[1][0]:
        raise CmdLineInputError()
    generic_options = parse_args.prepare_options(options_lists[0])
    model = options_lists[1][0]
    model_options = parse_args.prepare_options(options_lists[1][1:])

    if "model" in generic_options:
        raise CmdLineInputError(
            "Model cannot be specified in generic options"
        )

    lib.quorum.add_device(
        model,
        model_options,
        generic_options,
        force_model=modificators["force"],
        force_options=modificators["force"],
        skip_offline_nodes=modificators["skip_offline_nodes"]
    )
Example #4
0
def parse_bundle_update_options(arg_list):
    """
    Commandline options: no options
    """
    groups = _parse_bundle_groups(arg_list)
    port_map = {"add": [], "remove": []}
    for map_group in groups.get("port-map", []):
        _split_bundle_map_update_op_and_options(
            map_group, port_map, "port-map"
        )
    storage_map = {"add": [], "remove": []}
    for map_group in groups.get("storage-map", []):
        _split_bundle_map_update_op_and_options(
            map_group, storage_map, "storage-map"
        )
    parts = {
        "container": prepare_options(groups.get("container", [])),
        "network": prepare_options(groups.get("network", [])),
        "port_map_add": port_map["add"],
        "port_map_remove": port_map["remove"],
        "storage_map_add": storage_map["add"],
        "storage_map_remove": storage_map["remove"],
        "meta": prepare_options(groups.get("meta", []))
    }
    return parts
Example #5
0
def parse_create(arg_list):
    groups = group_by_keywords(
        arg_list,
        set(["op", "meta", "clone", "promotable", "bundle"]),
        implicit_first_group_key="options",
        group_repeated_keywords=["op"],
        only_found_keywords=True,
    )

    parts = {
        "meta":  prepare_options(groups.get("meta", [])),
        "options":  prepare_options(groups.get("options", [])),
        "op": [
            prepare_options(op)
            for op in build_operations(groups.get("op", []))
        ],
    }

    if "clone" in groups:
        parts["clone"] = prepare_options(groups["clone"])
    if "promotable" in groups:
        parts["promotable"] = prepare_options(groups["promotable"])
    if "bundle" in groups:
        parts["bundle"] = groups["bundle"]

    return parts
Example #6
0
def alert_add(lib, argv, modifiers):
    if not argv:
        raise CmdLineInputError()

    sections = parse_cmd_sections(argv, set(["options", "meta"]))
    main_args = prepare_options(sections["main"])
    ensure_only_allowed_options(main_args, ["id", "description", "path"])

    lib.alert.create_alert(
        main_args.get("id", None),
        main_args.get("path", None),
        prepare_options(sections["options"]),
        prepare_options(sections["meta"]),
        main_args.get("description", None)
    )
Example #7
0
def node_add_guest(lib, arg_list, modifiers):
    """
    Options:
      * --wait
      * --force - allow incomplete distribution of files, allow pcmk remote
        service to fail
      * --skip-offline - skip offline nodes
      * --request-timeout - HTTP request timeout
      For tests:
      * --corosync_conf
      * -f
    """
    modifiers.ensure_only_supported(
        "--wait", "--force", "--skip-offline", "--request-timeout",
        "--corosync_conf", "-f",
    )
    if len(arg_list) < 2:
        raise CmdLineInputError()


    node_name = arg_list[0]
    resource_id = arg_list[1]
    meta_options = prepare_options(arg_list[2:])

    lib.remote_node.node_add_guest(
        node_name,
        resource_id,
        meta_options,
        skip_offline_nodes=modifiers.get("--skip-offline"),
        allow_incomplete_distribution=modifiers.get("--force"),
        allow_pacemaker_remote_service_fail=modifiers.get("--force"),
        wait=modifiers.get("--wait"),
    )
Example #8
0
def prepare_set_args(argv):
    if argv.count("setoptions") > 1:
        raise CmdLineInputError(
            "Keyword 'setoptions' may be mentioned at most once"
        )

    resource_set_args, constraint_options_args = (
        parse_args.split_list(argv, "setoptions")
        if "setoptions" in argv else (argv, [])
    )

    if not resource_set_args:
        raise CmdLineInputError()

    resource_set_list = prepare_resource_sets(resource_set_args)
    if(
        not resource_set_list
        or
        not all(resource_set["ids"] for resource_set in resource_set_list)
    ):
        raise CmdLineInputError()

    constraint_options = {}
    if constraint_options_args:
        constraint_options = parse_args.prepare_options(constraint_options_args)

    return (resource_set_list, constraint_options)
Example #9
0
def parse_add(arg_list):
    info, option_candidates = separate_tail_option_candidates(arg_list)

    if not info:
        raise CmdLineInputError("Ticket not specified")

    ticket, resource_specification = info[0], info[1:]

    if len(resource_specification) not in (1, 2):
        raise CmdLineInputError(
            "invalid resource specification: '{0}'"
            .format(" ".join(resource_specification))
        )

    if len(resource_specification) == 2:
        resource_role, resource_id = resource_specification
    else:
        resource_role = ""
        resource_id = resource_specification[0]

    return (
        ticket,
        resource_id,
        resource_role,
        parse_args.prepare_options(option_candidates)
    )
Example #10
0
File: node.py Project: idevat/pcs
def attribute_set_cmd(node, argv):
    try:
        attrs = prepare_options(argv)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "node", "attribute")
    for name, value in attrs.items():
        utils.set_node_attribute(name, value, node)
Example #11
0
def sbd_setup_block_device(lib, argv, modifiers):
    """
    Options:
      * --force - do not show warning about wiping the devices
    """
    modifiers.ensure_only_supported("--force")
    options = parse_args.prepare_options(
        argv,
        allowed_repeatable_options=("device",)
    )
    device_list = options.get("device", [])
    if not device_list:
        raise CmdLineInputError("No device defined")

    if not modifiers.get("--force"):
        answer = utils.get_terminal_input(
            (
                "WARNING: All current content on device(s) '{device}' will be"
                + " overwritten. Are you sure you want to continue? [y/N] "
            ).format(device="', '".join(device_list))
        )
        if answer.lower() not in ["y", "yes"]:
            print("Canceled")
            return

    lib.sbd.initialize_block_devices(
        device_list,
        {
            name: value for name, value in options.items()
            if name != "device"
        }
    )
Example #12
0
def set_node_utilization(node, argv):
    cib = utils.get_cib_dom()
    node_el = utils.dom_get_node(cib, node)
    if node_el is None:
        if utils.usefile:
            utils.err("Unable to find a node: {0}".format(node))

        for attrs in utils.getNodeAttributesFromPacemaker():
            if attrs.name == node and attrs.type == "remote":
                node_attrs = attrs
                break
        else:
            utils.err("Unable to find a node: {0}".format(node))

        nodes_section_list = cib.getElementsByTagName("nodes")
        if len(nodes_section_list) == 0:
            utils.err("Unable to get nodes section of cib")

        dom = nodes_section_list[0].ownerDocument
        node_el = dom.createElement("node")
        node_el.setAttribute("id", node_attrs.id)
        node_el.setAttribute("type", node_attrs.type)
        node_el.setAttribute("uname", node_attrs.name)
        nodes_section_list[0].appendChild(node_el)

    utils.dom_update_utilization(node_el, prepare_options(argv), "nodes-")
    utils.replace_cib_configuration(cib)
Example #13
0
 def test_allow_repeatable_multiple(self):
     self.assertEqual(
         {'a': ['1', '3', '2', '4']},
         prepare_options(
             ["a=1", "a=3", "a=2", "a=4"], allowed_repeatable_options=("a")
         )
     )
Example #14
0
def alert_update(lib, argv, modifiers):
    if not argv:
        raise CmdLineInputError()

    alert_id = argv[0]

    sections = parse_cmd_sections(argv[1:], set(["options", "meta"]))
    main_args = prepare_options(sections["main"])
    ensure_only_allowed_options(main_args, ["description", "path"])

    lib.alert.update_alert(
        alert_id,
        main_args.get("path", None),
        prepare_options(sections["options"]),
        prepare_options(sections["meta"]),
        main_args.get("description", None)
    )
Example #15
0
def attribute_set_cmd(node, argv):
    """
    Commandline options:
      * -f - CIB file
      * --force - no error if attribute to delete doesn't exist
    """
    for name, value in prepare_options(argv).items():
        utils.set_node_attribute(name, value, node)
Example #16
0
def recipient_update(lib, argv, modifiers):
    if len(argv) < 1:
        raise CmdLineInputError()

    recipient_id = argv[0]

    sections = parse_cmd_sections(argv[1:], set(["options", "meta"]))
    main_args = prepare_options(sections["main"])
    ensure_only_allowed_options(main_args, ["description", "value"])

    lib.alert.update_recipient(
        recipient_id,
        prepare_options(sections["options"]),
        prepare_options(sections["meta"]),
        recipient_value=main_args.get("value", None),
        description=main_args.get("description", None),
        allow_same_value=modifiers["force"]
    )
Example #17
0
def quorum_update_cmd(lib, argv, modificators):
    options = parse_args.prepare_options(argv)
    if not options:
        raise CmdLineInputError()

    lib.quorum.set_options(
        options,
        skip_offline_nodes=modificators["skip_offline_nodes"]
    )
Example #18
0
def prepare_resource_sets(cmdline_args):
    return [
        {
            "ids": [id for id in args if "=" not in id],
            "options": parse_args.prepare_options(
                [opt for opt in args if "=" in opt]
            ),
        } for args in parse_args.split_list(cmdline_args, "set")
    ]
Example #19
0
def parse_create_simple(arg_list):
    groups = group_by_keywords(
        arg_list,
        set(["op", "meta"]),
        implicit_first_group_key="options",
        group_repeated_keywords=["op"],
    )

    parts = {
        "meta":  prepare_options(groups.get("meta", [])),
        "options":  prepare_options(groups.get("options", [])),
        "op": [
            prepare_options(op)
            for op in build_operations(groups.get("op", []))
        ],
    }

    return parts
Example #20
0
def alert_add(lib, argv, modifiers):
    """
    Options:
      * -f - CIB file (in lib wrapper)
    """
    modifiers.ensure_only_supported("-f")
    if not argv:
        raise CmdLineInputError()

    sections = parse_cmd_sections(argv, set(["options", "meta"]))
    main_args = prepare_options(sections["main"])
    ensure_only_allowed_options(main_args, ["id", "description", "path"])

    lib.alert.create_alert(
        main_args.get("id", None),
        main_args.get("path", None),
        prepare_options(sections["options"]),
        prepare_options(sections["meta"]),
        main_args.get("description", None)
    )
Example #21
0
def config_ticket_add(lib, arg_list, modifiers):
    """
    add ticket to current configuration
    """
    if not arg_list:
        raise CmdLineInputError
    lib.booth.config_ticket_add(
        arg_list[0],
        prepare_options(arg_list[1:]),
        allow_unknown_options=modifiers["force"]
    )
Example #22
0
def sbd_enable(lib, argv, modifiers):
    sbd_cfg = parse_args.prepare_options(argv)
    default_watchdog, watchdog_dict = _sbd_parse_watchdogs(
        modifiers["watchdog"]
    )
    lib.sbd.enable_sbd(
        default_watchdog,
        watchdog_dict,
        sbd_cfg,
        allow_unknown_opts=modifiers["force"],
        ignore_offline_nodes=modifiers["skip_offline_nodes"]
    )
Example #23
0
def _parse_host_options(host, options):
    # pylint: disable=invalid-name
    ADDR_OPT_KEYWORD = "addr"
    supported_options = set([ADDR_OPT_KEYWORD])
    parsed_options = parse_args.prepare_options(options)
    unknown_options = set(parsed_options.keys()) - supported_options
    if unknown_options:
        raise CmdLineInputError(
            "Unknown options {} for host '{}'".format(
                ", ".join(unknown_options), host
            )
        )
    addr, port = _parse_addr(parsed_options.get(ADDR_OPT_KEYWORD, host))
    return {"dest_list": [dict(addr=addr, port=port)]}
Example #24
0
File: quorum.py Project: idevat/pcs
def quorum_device_update_cmd(lib, argv, modificators):
    # we expect "model" keyword once
    options_lists = parse_args.split_list(argv, "model")
    if len(options_lists) == 1:
        generic_options = parse_args.prepare_options(options_lists[0])
        model_options = dict()
    elif len(options_lists) == 2:
        generic_options = parse_args.prepare_options(options_lists[0])
        model_options = parse_args.prepare_options(options_lists[1])
    else:
        raise CmdLineInputError()

    if "model" in generic_options:
        raise CmdLineInputError(
            "Model cannot be specified in generic options"
        )

    lib.quorum.update_device(
        model_options,
        generic_options,
        force_options=modificators["force"],
        skip_offline_nodes=modificators["skip_offline_nodes"]
    )
Example #25
0
def quorum_device_add_cmd(lib, argv, modifiers):
    """
    Options:
      * --force - allow unknown model or options
      * --skip-offline - skip offline nodes
      * --request-timeout - HTTP timeout, has effect only if --corosync_conf is
        not specified
      * --corosync_conf - mocked corosync configuration file
    """
    modifiers.ensure_only_supported(
        "--force", "--skip-offline", "--request-timeout", "--corosync_conf"
    )
    groups = _parse_quorum_device_groups(argv)
    model_and_model_options = groups.get("model", [])
    # we expect "model" keyword once, followed by the actual model value
    if not model_and_model_options or "=" in model_and_model_options[0]:
        raise CmdLineInputError()

    generic_options = parse_args.prepare_options(groups.get("generic", []))
    model = model_and_model_options[0]
    model_options = parse_args.prepare_options(model_and_model_options[1:])
    heuristics_options = parse_args.prepare_options(
        groups.get("heuristics", [])
    )

    if "model" in generic_options:
        raise CmdLineInputError("Model cannot be specified in generic options")

    lib.quorum.add_device(
        model,
        model_options,
        generic_options,
        heuristics_options,
        force_model=modifiers.get("--force"),
        force_options=modifiers.get("--force"),
        skip_offline_nodes=modifiers.get("--skip-offline"),
    )
Example #26
0
def _split_bundle_map_update_op_and_options(
    map_arg_list, result_parts, map_name
):
    """
    Commandline options: no options
    """
    if len(map_arg_list) < 2:
        raise _bundle_map_update_not_valid(map_name)
    op, options = map_arg_list[0], map_arg_list[1:]
    if op == "add":
        result_parts["add"].append(prepare_options(options))
    elif op in {"delete", "remove"}:
        result_parts["remove"].extend(options)
    else:
        raise _bundle_map_update_not_valid(map_name)
Example #27
0
def parse_bundle_create_options(arg_list):
    """
    Commandline options: no options
    """
    groups = _parse_bundle_groups(arg_list)
    container_options = groups.get("container", [])
    container_type = ""
    if container_options and "=" not in container_options[0]:
        container_type = container_options.pop(0)
    parts = {
        "container_type": container_type,
        "container": prepare_options(container_options),
        "network": prepare_options(groups.get("network", [])),
        "port_map": [
            prepare_options(port_map)
            for port_map in groups.get("port-map", [])
        ],
        "storage_map": [
            prepare_options(storage_map)
            for storage_map in groups.get("storage-map", [])
        ],
        "meta": prepare_options(groups.get("meta", []))
    }
    return parts
Example #28
0
def set_node_utilization(node, argv):
    """
    Commandline options:
      * -f - CIB file
    """
    nvpair_dict = prepare_options(argv)
    if not nvpair_dict:
        return
    only_removing = True
    for value in nvpair_dict.values():
        if value != "":
            only_removing = False
            break

    cib = utils.get_cib_dom()
    node_el = utils.dom_get_node(cib, node)
    if node_el is None:
        if utils.usefile:
            utils.err("Unable to find a node: {0}".format(node))

        for attrs in utils.getNodeAttributesFromPacemaker():
            if attrs.name == node and attrs.type == "remote":
                node_attrs = attrs
                break
        else:
            utils.err("Unable to find a node: {0}".format(node))

        nodes_section_list = cib.getElementsByTagName("nodes")
        if not nodes_section_list:
            utils.err("Unable to get nodes section of cib")

        if only_removing:
            # Do not create new node if we are only removing values from it.
            return

        dom = nodes_section_list[0].ownerDocument
        node_el = dom.createElement("node")
        node_el.setAttribute("id", node_attrs.id)
        node_el.setAttribute("type", node_attrs.type)
        node_el.setAttribute("uname", node_attrs.name)
        nodes_section_list[0].appendChild(node_el)

    utils.dom_update_utilization(node_el, nvpair_dict, "nodes-")
    utils.replace_cib_configuration(cib)
Example #29
0
def quorum_update_cmd(lib, argv, modifiers):
    """
    Options:
      * --skip-offline - skip offline nodes
      * --force - force changes
      * --corosync_conf - mocked corosync configuration file
      * --request-timeout - HTTP timeout, has effect only if --corosync_conf is
        not specified
    """
    modifiers.ensure_only_supported(
        "--skip-offline", "--force", "--corosync_conf", "--request-timeout"
    )
    options = parse_args.prepare_options(argv)
    if not options:
        raise CmdLineInputError()

    lib.quorum.set_options(
        options,
        skip_offline_nodes=modifiers.get("--skip-offline"),
        force=modifiers.get("--force"),
    )
Example #30
0
def sbd_enable(lib, argv, modifiers):
    """
    Options:
      * --request-timeout - HTTP request timeout
      * --force - allow unknown SBD options
      * --skip-offline - skip offline cluster nodes
      * --no-watchdog-validation - do not validate watchdog
    """
    modifiers.ensure_only_supported(
        "--request-timeout", "--force", "--skip-offline",
        "--no-watchdog-validation",
    )
    options = parse_args.prepare_options(
        argv,
        allowed_repeatable_options=("device", "watchdog")
    )
    default_watchdog, watchdog_dict = _sbd_parse_watchdogs(
        options.get("watchdog", [])
    )
    default_device_list, node_device_dict = _sbd_parse_node_specific_options(
        options.get("device", [])
    )

    lib.sbd.enable_sbd(
        default_watchdog,
        watchdog_dict,
        {
            name: value for name, value in options.items()
            if name not in ("device", "watchdog")
        },
        default_device_list=(
            default_device_list if default_device_list else None
        ),
        node_device_dict=node_device_dict if node_device_dict else None,
        allow_unknown_opts=modifiers.get("--force"),
        ignore_offline_nodes=modifiers.get("--skip-offline"),
        no_watchdog_validation=modifiers.get("--no-watchdog-validation"),
    )