Align timestamp of metric for statistics
>>> align_metrictime(35.0, 60.0)
60.0
>>> align_metrictime(60.0, 60.0)
120.0
>>> align_metrictime(150.0, 60.0)
180.0
>>> align_metrictime(150.1, 60.0)
180.0
clean up stale locks left behind by process failures
The lockfile module, used by @synchronized, can leave stale lockfiles behind after process failure. These locks can cause process hangs at startup, when a process deadlocks on a lock which will never be unlocked.
Intended to be called at service startup.
delete a file, but ignore file not found error
Helper method to execute command with optional retry.
:cmd Passed to subprocess.Popen. :process_input Send to opened process. :check_exit_code Defaults to 0. Raise exception.ProcessExecutionError
unless program exits with this code.
:attempts How many times to retry cmd. :run_as_root True | False. Defaults to False. If set to True,
the command is prefixed by the command specified in the root_helper FLAG.
:raises exception.Error on receiving unknown arguments :raises exception.ProcessExecutionError
it will convert from
to
{u’member1’: u’value1’, u’member2’: u’value2’}
this is useful for processing dimension.
ex) if key is ‘member’, it will convert from
to
[‘something1’, ‘something2’, ‘something3’]
Find a configuration file using the given hint.
Parameters: | config_path – Full or relative path to the config. |
---|---|
Returns: | Full path of the config, if it exists. |
Raises : | synaps.exception.ConfigNotFound |
Returns a class from a string including module and class.
Returns an object including a module or module and class.
Returns iso formatted utcnow.
If the Flags.monkey_patch set as True, this function patches a decorator for all functions in specified modules. You can set decorators for each modules using FLAGS.monkey_patch_modules. The format is “Module path:Decorator function”. Example: ‘nova.api.ec2.cloud:nova.notifier.api.notify_decorator’
Parameters of the decorator is as follows. (See nova.notifier.api.notify_decorator)
name - name of the function function - object of the function
Parses the given server_string and returns a list of host and port. If it’s not a combination of host part and port, the port element is a null string. If the input is invalid expression, return a null list.
Turn a formatted time back into a datetime.
Constant-time string comparison.
Params s1: | the first string |
---|---|
Params s2: | the second string |
Returns: | True if the strings are equal. |
This function takes two strings and compares them. It is intended to be used when doing a comparison for authentication purposes to help guard against timing attacks.
Returns formatted utcnow.
Returns formatted utcnow.
Convert a complex object into primitives.
Handy for JSON serialization. We can optionally handle instances, but since this is a recursive function, we could have cyclical data structures.
To handle cyclical data structures we could track the actual objects visited in a set, but not all objects are hashable. Instead we just track the depth of the object inspections and don’t go too deep.
Therefore, convert_instances=True is lossy ... be aware.
Overridable version of utils.utcnow.
Timestamp version of our utcnow function.
Try to turn a string into utf-8 if possible.
Code is directly from the utf8 function in http://github.com/facebook/tornado/blob/master/tornado/escape.py
International Telecommunication Union ITU-T Rec. E.123 (02/2001)
Notation for national and international telephone numbers, e-mail addresses and web addresses
Escapes a string so it is valid within XML or XHTML.