示例#1
0
    def _get_parameter(
        self, parameter_element: _Element
    ) -> Optional[AgentParameterDto]:
        if parameter_element.get("name", None) is None:
            return None

        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 AgentParameterDto(
            str(parameter_element.attrib["name"]),
            self._get_text_from_dom_element(
                parameter_element.find("shortdesc")
            ),
            self._get_text_from_dom_element(parameter_element.find("longdesc")),
            value_type,
            default_value,
            required=is_true(parameter_element.get("required", "0")),
            advanced=False,
            deprecated=is_true(parameter_element.get("deprecated", "0")),
            deprecated_by=[],
            obsoletes=parameter_element.get("obsoletes", None),
            unique=is_true(parameter_element.get("unique", "0")),
            pcs_deprecated_warning=None,
        )
示例#2
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 self._create_parameter({
            "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,
            "deprecated":
            is_true(parameter_element.get("deprecated", "0")),
            "obsoletes":
            parameter_element.get("obsoletes", None),
        })
示例#3
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"))
示例#4
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"))
示例#5
0
def show_acl_config(lib, argv, modifiers):
    """
    Options:
      * -f - CIB file
    """
    # TODO move to lib once lib supports cluster properties
    # enabled/disabled should be part of the structure returned
    # by lib.acl.get_config
    modifiers.ensure_only_supported("-f")
    if argv:
        raise CmdLineInputError()
    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)
示例#6
0
def _get_primitives_for_state_check(
    cluster_state, resource_id, expected_running
):
    primitives = cluster_state.xpath(
        """
        .//resource[{predicate_id}]
        |
        .//group[{predicate_id}]/resource[{predicate_position}]
        |
        .//clone[@id="{id}"]/resource
        |
        .//clone[@id="{id}"]/group/resource[{predicate_position}]
        |
        .//bundle[@id="{id}"]/replica/resource
    """.format(
            id=resource_id,
            predicate_id=_id_xpath_predicate(resource_id),
            predicate_position=("last()" if expected_running else "1"),
        )
    )
    return [
        element
        for element in primitives
        if not is_true(element.attrib.get("failed", ""))
    ]
示例#7
0
文件: acl.py 项目: ClusterLabs/pcs
def show_acl_config(lib, argv, modifiers):
    """
    Options:
      * -f - CIB file
    """
    # TODO move to lib once lib supports cluster properties
    # enabled/disabled should be part of the structure returned
    # by lib.acl.get_config
    modifiers.ensure_only_supported("-f")
    if argv:
        raise CmdLineInputError()
    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)
示例#8
0
文件: clone.py 项目: kmalyjur/pcs
def is_promotable_clone(resource_el):
    """
    Return True if resource_el is a promotable clone, False on clone and master
    """
    return is_clone(resource_el) and is_true(
        nvpair.get_value(
            nvpair.META_ATTRIBUTES_TAG,
            resource_el,
            "promotable",
            default="false",
        ))
示例#9
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"))
示例#10
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"))
示例#11
0
文件: clone.py 项目: tomjelinek/pcs
def is_promotable_clone(resource_el):
    """
    Return True if resource_el is a promotable clone, False on clone and master
    """
    return (
        is_clone(resource_el)
        and
        is_true(nvpair.get_value(
            nvpair.META_ATTRIBUTES_TAG,
            resource_el,
            "promotable",
            default="false",
        ))
    )
示例#12
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 self._create_parameter({
            "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")),
            "deprecated": is_true(parameter_element.get("deprecated", "0")),
            "obsoletes": parameter_element.get("obsoletes", None),
            "unique": is_true(parameter_element.get("unique", "0")),
        })
示例#13
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,
        }
示例#14
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])
示例#15
0
文件: state.py 项目: tomjelinek/pcs
def _get_primitives_for_state_check(
    cluster_state, resource_id, expected_running
):
    primitives = cluster_state.xpath("""
        .//resource[{predicate_id}]
        |
        .//group[{predicate_id}]/resource[{predicate_position}]
        |
        .//clone[@id="{id}"]/resource
        |
        .//clone[@id="{id}"]/group/resource[{predicate_position}]
        |
        .//bundle[@id="{id}"]/replica/resource
    """.format(
        id=resource_id,
        predicate_id=_id_xpath_predicate(resource_id),
        predicate_position=("last()" if expected_running else "1")
    ))
    return [
        element for element in primitives
            if not is_true(element.attrib.get("failed", ""))
    ]
示例#16
0
def is_enabled(operation_element):
    """
    Check if the specified operation is enabled
    etree operation_element -- the operation
    """
    return is_true(operation_element.attrib.get("enabled", "true"))