Beispiel #1
0
 def test_true_is_true(self):
     self.assertTrue(lib.is_true("true"))
     self.assertTrue(lib.is_true("tRue"))
     self.assertTrue(lib.is_true("on"))
     self.assertTrue(lib.is_true("ON"))
     self.assertTrue(lib.is_true("yes"))
     self.assertTrue(lib.is_true("yeS"))
     self.assertTrue(lib.is_true("y"))
     self.assertTrue(lib.is_true("Y"))
     self.assertTrue(lib.is_true("1"))
 def test_true_is_true(self):
     self.assertTrue(lib.is_true("true"))
     self.assertTrue(lib.is_true("tRue"))
     self.assertTrue(lib.is_true("on"))
     self.assertTrue(lib.is_true("ON"))
     self.assertTrue(lib.is_true("yes"))
     self.assertTrue(lib.is_true("yeS"))
     self.assertTrue(lib.is_true("y"))
     self.assertTrue(lib.is_true("Y"))
     self.assertTrue(lib.is_true("1"))
Beispiel #3
0
    def _get_parameter(self, parameter_element):
        value_type = "string"
        default_value = None
        content_element = parameter_element.find("content")
        if content_element is not None:
            value_type = content_element.get("type", value_type)
            default_value = content_element.get("default", default_value)

        return {
            "name":
            parameter_element.get("name", ""),
            "longdesc":
            self._get_text_from_dom_element(
                parameter_element.find("longdesc")),
            "shortdesc":
            self._get_text_from_dom_element(
                parameter_element.find("shortdesc")),
            "type":
            value_type,
            "default":
            default_value,
            "required":
            is_true(parameter_element.get("required", "0")),
            "advanced":
            False,
        }
Beispiel #4
0
 def test_nontrue_is_not_true(self):
     self.assertFalse(lib.is_true(""))
     self.assertFalse(lib.is_true(" 1 "))
     self.assertFalse(lib.is_true("a"))
     self.assertFalse(lib.is_true("2"))
     self.assertFalse(lib.is_true("10"))
     self.assertFalse(lib.is_true("yes please"))
 def test_nontrue_is_not_true(self):
     self.assertFalse(lib.is_true(""))
     self.assertFalse(lib.is_true(" 1 "))
     self.assertFalse(lib.is_true("a"))
     self.assertFalse(lib.is_true("2"))
     self.assertFalse(lib.is_true("10"))
     self.assertFalse(lib.is_true("yes please"))
Beispiel #6
0
def acl_show(argv):
    dom = utils.get_cib_dom()

    properties = prop.get_set_properties(defaults=prop.get_default_properties())
    acl_enabled = properties.get("enable-acl", "").lower()
    if is_true(acl_enabled):
        print("ACLs are enabled")
    else:
        print("ACLs are disabled, run 'pcs acl enable' to enable")
    print()

    print_targets(dom)
    print_groups(dom)
    print_roles(dom)
Beispiel #7
0
def show_acl_config(lib, argv, modifiers):
    # TODO move to lib once lib supports cluster properties
    # enabled/disabled should be part of the structure returned
    # by lib.acl.get_config
    properties = utils.get_set_properties(defaults=prop.get_default_properties())
    acl_enabled = properties.get("enable-acl", "").lower()
    if is_true(acl_enabled):
        print("ACLs are enabled")
    else:
        print("ACLs are disabled, run 'pcs acl enable' to enable")
    print()

    data = lib.acl.get_config()
    _print_list_of_objects(data.get("target_list", []), target_to_str)
    _print_list_of_objects(data.get("group_list", []), group_to_str)
    _print_list_of_objects(data.get("role_list", []), role_to_str)
Beispiel #8
0
def constraint_plain(constraint_info, with_id=False):
    """
    dict constraint_info see constraint in pcs/lib/exchange_formats.md
    bool with_id have to show id with options_dict
    """
    options = constraint_info["options"]
    oc_resource1 = options.get("first", "")
    oc_resource2 = options.get("then", "")
    first_action = options.get("first-action", "")
    then_action = options.get("then-action", "")
    oc_id = options.get("id", "")
    oc_score = options.get("score", "")
    oc_kind = options.get("kind", "")
    oc_sym = ""
    oc_id_out = ""
    oc_options = ""
    if (
        "symmetrical" in options
        and
        not is_true(options.get("symmetrical", "false"))
    ):
        oc_sym = "(non-symmetrical)"
    if oc_kind != "":
        score_text = "(kind:" + oc_kind + ")"
    elif oc_kind == "" and oc_score == "":
        score_text = "(kind:Mandatory)"
    else:
        score_text = "(score:" + oc_score + ")"
    if with_id:
        oc_id_out = "(id:"+oc_id+")"
    already_processed_options = (
        "first", "then", "first-action", "then-action", "id", "score", "kind",
        "symmetrical"
    )
    oc_options = " ".join([
        "{0}={1}".format(name, value)
        for name, value in options.items()
        if name not in already_processed_options
    ])
    if oc_options:
        oc_options = "(Options: " + oc_options + ")"
    return " ".join([arg for arg in [
        first_action, oc_resource1, "then", then_action, oc_resource2,
        score_text, oc_sym, oc_options, oc_id_out
    ] if arg])
Beispiel #9
0
def constraint_plain(constraint_info, with_id=False):
    """
    dict constraint_info see constraint in pcs/lib/exchange_formats.md
    bool with_id have to show id with options_dict
    """
    options = constraint_info["options"]
    oc_resource1 = options.get("first", "")
    oc_resource2 = options.get("then", "")
    first_action = options.get("first-action", "")
    then_action = options.get("then-action", "")
    oc_id = options.get("id", "")
    oc_score = options.get("score", "")
    oc_kind = options.get("kind", "")
    oc_sym = ""
    oc_id_out = ""
    oc_options = ""
    if ("symmetrical" in options
            and not is_true(options.get("symmetrical", "false"))):
        oc_sym = "(non-symmetrical)"
    if oc_kind != "":
        score_text = "(kind:" + oc_kind + ")"
    elif oc_kind == "" and oc_score == "":
        score_text = "(kind:Mandatory)"
    else:
        score_text = "(score:" + oc_score + ")"
    if with_id:
        oc_id_out = "(id:" + oc_id + ")"
    already_processed_options = ("first", "then", "first-action",
                                 "then-action", "id", "score", "kind",
                                 "symmetrical")
    oc_options = " ".join([
        "{0}={1}".format(name, value) for name, value in options.items()
        if name not in already_processed_options
    ])
    if oc_options:
        oc_options = "(Options: " + oc_options + ")"
    return " ".join([
        arg for arg in [
            first_action, oc_resource1, "then", then_action, oc_resource2,
            score_text, oc_sym, oc_options, oc_id_out
        ] if arg
    ])
Beispiel #10
0
def order_el_to_string(ord_loc, showDetail=False):
    oc_resource1 = ord_loc.getAttribute("first")
    oc_resource2 = ord_loc.getAttribute("then")
    first_action = ord_loc.getAttribute("first-action")
    then_action = ord_loc.getAttribute("then-action")
    oc_id = ord_loc.getAttribute("id")
    oc_score = ord_loc.getAttribute("score")
    oc_kind = ord_loc.getAttribute("kind")
    oc_sym = ""
    oc_id_out = ""
    oc_options = ""
    if (
        ord_loc.getAttribute("symmetrical")
        and
        not is_true(ord_loc.getAttribute("symmetrical"))
    ):
        oc_sym = "(non-symmetrical)"
    if oc_kind != "":
        score_text = "(kind:" + oc_kind + ")"
    elif oc_kind == "" and oc_score == "":
        score_text = "(kind:Mandatory)"
    else:
        score_text = "(score:" + oc_score + ")"
    if showDetail:
        oc_id_out = "(id:"+oc_id+")"
    already_processed_attrs = (
        "first", "then", "first-action", "then-action", "id", "score", "kind",
        "symmetrical"
    )
    oc_options = " ".join([
        "{0}={1}".format(name, value)
        for name, value in ord_loc.attributes.items()
        if name not in already_processed_attrs
    ])
    if oc_options:
        oc_options = "(Options: " + oc_options + ")"
    return " ".join([arg for arg in [
        first_action, oc_resource1, "then", then_action, oc_resource2,
        score_text, oc_sym, oc_options, oc_id_out
    ] if arg])
Beispiel #11
0
def _get_parameter(parameter_dom):
    """
    Returns dictionary that describes parameter.
    dictionary format:
    {
        name: name of parameter
        longdesc: long description,
        shortdesc: short description,
        type: data type od parameter,
        default: default value,
        required: True if is required parameter, False otherwise
    }
    Raises InvalidMetadataFormat if parameter_dom is not in valid format

    parameter_dom -- parameter dom element
    """
    if parameter_dom.tag != "parameter" or parameter_dom.get("name") is None:
        raise InvalidMetadataFormat()

    longdesc = __get_text_from_dom_element(parameter_dom.find("longdesc"))
    shortdesc = __get_text_from_dom_element(parameter_dom.find("shortdesc"))

    content = parameter_dom.find("content")
    if content is None:
        val_type = "string"
    else:
        val_type = content.get("type", "string")

    return {
        "name": parameter_dom.get("name"),
        "longdesc": longdesc,
        "shortdesc": shortdesc,
        "type": val_type,
        "default": None if content is None else content.get("default"),
        "required": is_true(parameter_dom.get("required", "0"))
    }