예제 #1
0
 def is_logd(self):
     return string_to_bool(
         os.getenv(
             constants.OCF_VAR_LOGD,
             False,
         ),
         False,
     )
예제 #2
0
 def is_debug(self):
     return string_to_bool(
         os.getenv(
             constants.OCF_VAR_DEBUG,
             False,
         ),
         False,
     )
예제 #3
0
    def modify_value(self, value):
        """
        Boolean property converts its value to boolean or to None
        if the value cannot be converted.

        :param value: input value
        :type value: str
        :return: boolean value
        :rtype: bool
        """
        return string_to_bool(value)
예제 #4
0
    def required(self):
        """
        Indicates that this value is required to use this resource and
        a user should provide an explicit value for this parameter.
        Default value will nod be used.
        Can ne set by the *{0}* constant in the parameter definition
        and can be either true or False. Defaults to **False**.

        :rtype: bool
        :return: true or false
        """
        return string_to_bool(
            getattr(self, constants.CONST_REQUIRED, False)
        )
예제 #5
0
 def test_string_to_bool(self):
     true_values = [True, "YES", "on", "Y", 1, "1"]
     false_values = [False, "NO", "off", "N", 0, "0"]
     none_values = [None, "none", 10, "bad value", "", 1.1, [1], {"a": 1}]
     for value in true_values:
         self.assertEquals(helpers.string_to_bool(value), True)
     for value in false_values:
         self.assertEquals(helpers.string_to_bool(value), False)
     for value in none_values:
         self.assertIsNone(helpers.string_to_bool(value))
     self.assertEquals(helpers.string_to_bool("bad value", True), True)
     self.assertEquals(helpers.string_to_bool("bad value", False), False)
     self.assertEquals(helpers.string_to_bool("bad value", "default"), "default")
     self.assertEquals(helpers.string_to_bool("YES", "default"), True)
예제 #6
0
    def unique(self):
        """
        Indicates that this value is unique across the cluster.
        If there are several resources of this type, a single value
        can be assigned only to a single instance and other instances
        should have different values.
        If disabled, many similar resources may have the same value of
        this parameter.
        Can be set by the *{0}* constant in the parameter definition
        and can be either True or False. Defaults to **False**.

        :rtype: bool
        :return: true or false
        """
        return string_to_bool(
            getattr(self, constants.CONST_UNIQUE, False)
        )