def meta_clone(self): return string_to_integer( os.getenv( constants.OCF_VAR_META_CLONE, None ) )
def ra_version_minor(self): return string_to_integer( os.getenv( constants.OCF_VAR_RA_VERSION_MINOR, 0, ) )
def meta_master(self): return string_to_integer( os.getenv( constants.OCF_VAR_META_MASTER, None ) )
def ra_version_major(self): return string_to_integer( os.getenv( constants.OCF_VAR_RA_VERSION_MAJOR, 1, ) )
def check_level(self): return string_to_integer( os.getenv( constants.OCF_VAR_CHECK_LEVEL, constants.DEFAULT_DEPTH, ) )
def modify_value(self, value): """ Integer property converts ins value to an integer or to None if input value cannot be converted. :param value: input value :type value: str :return: integer value """ return string_to_integer(value)
def test_string_to_integer(self): values = { 1: 1, 0: 0, 10: 10, -1: 1, 1.2: 1, "1": 1, "0": 0, "10": 10, "-10": 10, "2a": 2, "a2": 2, "a2a": 2, None: None, "": None, "test": None, } for value_in, value_out in values.items(): self.assertEquals(helpers.string_to_integer(value_in), value_out) self.assertEquals(helpers.string_to_integer("bad_value", 10), 10) self.assertEquals(helpers.string_to_integer("bad_value", "default"), "default") self.assertEquals(helpers.string_to_integer(1, "default"), 1)
def read_file(self, key=None): """ Read the pid file and return the recorded number or None if the file cannot be read. :param key: Custom pid file suffix :type key: str or None :return: The pid number :rtype: int or None """ if not self.file_is_present(key): return None with open(self.file_path(key), 'r') as pid_file: number = pid_file.read() return string_to_integer(number)
def timeout(self): """ Returns the handler's timeout value. It will be used in the meta-data XML to advise the user what is the minimal number of seconds required to execute this agent's action. The value can be set by the *{0}* constant and will default to the default value **{1}** if not set. :return: The timeout value in seconds :rtype: int """ return string_to_integer( getattr( self, constants.CONST_TIMEOUT, constants.DEFAULT_TIMEOUT ) )
def interval(self): """ Interval is the number of seconds between the monitor actions calls. This value is used in the meta-data XML to advise the user what is the minimum interval for this monitor? or for this monitor type if there are several monitor actions defined. Interval can be set by the *{0}* constant and will default to **{1}** if unset. :return: The interval value in seconds :rtype: int """ return string_to_integer( getattr( self, constants.CONST_INTERVAL, constants.DEFAULT_INTERVAL, ) )
def depth(self): """ Depth, or the check_level, is used to define several monitor actions. For example, the short monitor action with a small depth number and the long and expensive one with a large depth. Small monitor can have a small interval value and be called very often and the large monitor can perform many additional checks, have a large monitor value and be called infrequently. The depth value will be used to distinguish these actions. Depth can be set by the *{0}* constant and will default to **{1}** if unset. :return: The depth value :rtype: int """ return string_to_integer( getattr( self, constants.CONST_DEPTH, constants.DEFAULT_DEPTH, ) )
def get(pid): pid = string_to_integer(pid) try: return psutil.Process(pid) except (TypeError, psutil.NoSuchProcess): return None
def is_running(pid): pid = string_to_integer(pid) return psutil.pid_exists(pid)