Example #1
0
def stonith_level_parse_node(arg):
    target_type_candidate, target_value_candidate = parse_args.parse_typed_arg(
        arg, target_type_map_cli_to_lib.keys(), "node")
    target_type = target_type_map_cli_to_lib[target_type_candidate]
    if target_type == TARGET_TYPE_ATTRIBUTE:
        target_value = parse_args.split_option(target_value_candidate)
    else:
        target_value = target_value_candidate
    return target_type, target_value
Example #2
0
def stonith_level_parse_node(arg):
    target_type_candidate, target_value_candidate = parse_args.parse_typed_arg(
        arg,
        target_type_map_cli_to_lib.keys(),
        "node"
    )
    target_type = target_type_map_cli_to_lib[target_type_candidate]
    if target_type == TARGET_TYPE_ATTRIBUTE:
        target_value = parse_args.split_option(target_value_candidate)
    else:
        target_value = target_value_candidate
    return target_type, target_value
Example #3
0
 def _parse_score_options(argv):
     # When passed an array of arguments if the first argument doesn't have
     # an '=' then it's the score, otherwise they're all arguments. Return a
     # tuple with the score and array of name,value pairs
     """
     Commandline options: no options
     """
     if not argv:
         return SCORE_INFINITY, []
     score = SCORE_INFINITY if "=" in argv[0] else argv.pop(0)
     # create a list of 2-tuples (name, value)
     arg_array = [parse_args.split_option(arg) for arg in argv]
     return score, arg_array
Example #4
0
 def test_ok(self):
     self.assertEqual(("option1", "value2"), split_option("option1=value2"))
Example #5
0
 def test_multiple_eq_char(self):
     self.assertEqual(("option1", "value2=value1"),
                      split_option("option1=value2=value1"))
Example #6
0
 def test_no_option_value_allowed(self):
     self.assertEqual(("option1", ""), split_option("option1="))
Example #7
0
 def test_no_option_value_not_allowed(self):
     arg = "option1"
     with self.assertRaisesRegex(CmdLineInputError,
                                 f"value of '{arg}' option is empty"):
         split_option(f"{arg}=", allow_empty_value=False)
Example #8
0
 def test_no_option_name(self):
     arg = "=value1"
     with self.assertRaisesRegex(CmdLineInputError,
                                 f"missing key in '{arg}' option"):
         split_option(arg)
Example #9
0
 def test_no_eq_char(self):
     arg = "option1"
     with self.assertRaisesRegex(CmdLineInputError,
                                 f"missing value of '{arg}' option"):
         split_option(arg)
Example #10
0
def _order_add(resource1, resource2, options_list, modifiers):
    """
    Commandline options:
      * -f - CIB file
      * --force - allow constraint for any resource, allow duplicate constraints
    """
    cib_dom = utils.get_cib_dom()
    _validate_constraint_resource(cib_dom, resource1)
    _validate_constraint_resource(cib_dom, resource2)

    order_options = []
    id_specified = False
    sym = None
    for arg in options_list:
        if arg == "symmetrical":
            sym = "true"
        elif arg == "nonsymmetrical":
            sym = "false"
        else:
            name, value = parse_args.split_option(arg, allow_empty_value=False)
            if name == "id":
                id_valid, id_error = utils.validate_xml_id(
                    value, 'constraint id')
                if not id_valid:
                    utils.err(id_error)
                if utils.does_id_exist(cib_dom, value):
                    utils.err(
                        "id '%s' is already in use, please specify another one"
                        % value)
                id_specified = True
                order_options.append((name, value))
            elif name == "symmetrical":
                if value.lower() in OPTIONS_SYMMETRICAL:
                    sym = value.lower()
                else:
                    utils.err(
                        "invalid symmetrical value '%s', allowed values are: %s"
                        % (value, ", ".join(OPTIONS_SYMMETRICAL)))
            else:
                order_options.append((name, value))
    if sym:
        order_options.append(("symmetrical", sym))

    options = ""
    if order_options:
        options = " (Options: %s)" % " ".join([
            "%s=%s" % (name, value)
            for name, value in order_options if name not in ("kind", "score")
        ])

    scorekind = "kind: Mandatory"
    id_suffix = "mandatory"
    for opt in order_options:
        if opt[0] == "score":
            scorekind = "score: " + opt[1]
            id_suffix = opt[1]
            break
        if opt[0] == "kind":
            scorekind = "kind: " + opt[1]
            id_suffix = opt[1]
            break

    if not id_specified:
        order_id = "order-" + resource1 + "-" + resource2 + "-" + id_suffix
        order_id = utils.find_unique_id(cib_dom, order_id)
        order_options.append(("id", order_id))

    (dom, constraintsElement) = getCurrentConstraints()
    element = dom.createElement("rsc_order")
    element.setAttribute("first", resource1)
    element.setAttribute("then", resource2)
    for order_opt in order_options:
        element.setAttribute(order_opt[0], order_opt[1])
    constraintsElement.appendChild(element)
    if not modifiers.get("--force"):
        duplicates = order_find_duplicates(constraintsElement, element)
        if duplicates:
            utils.err(
                "duplicate constraint already exists, use --force to override\n"
                + "\n".join([
                    "  " + constraint_order.console_report.constraint_plain(
                        {"options": dict(dup.attributes.items())}, True)
                    for dup in duplicates
                ]))
    print("Adding " + resource1 + " " + resource2 + " (" + scorekind + ")" +
          options)

    utils.replace_cib_configuration(dom)