Package enomalism2 :: Module utilities
[hide private]

Module utilities

Contains helper functionality for Enomalism.


Requires: enomalism2.configuration.Variable

Status: Stable

Functions [hide private]
Boolean
is_list(obj)
Return true if the specified object is a list.
Boolean
is_dict(obj)
Return true if the specified object is a dictionary.
Boolean
is_str(obj)
Return true if the specified object is a string.
Boolean
is_int(obj)
Return true if the specified object is an integer.
Boolean
is_long(obj)
Return true if the specified object is a long integer.
Boolean
is_float(obj)
Return true if the specified object is a float.
Boolean
is_bool(obj)
Return true if the specified object is a boolean.
Boolean
is_unicode(obj)
Return true if the specified object is a unicode.
Boolean
is_none(obj)
Return true if the specified object is a None.
String
gen_timestamp(format='%Y-%m-%d %H:%M:%S')
Return a timestamp based on the specified format.
String
gen_uuid(value=None)
Generate a unique id.
String
get_ip_address(ifname='virbr0')
Return the ip address of the specified interface name.
List
find_libvirt_services()
Return a list of the supported libvert services on this machine.
UUID
to_uuid(id)
Convert the provided EC2 id to a UUID instance.
String
from_uuid(id)
Convert the provided UUID to its EC2 counterpart.
Boolean
valid_uuid(id)
Return true if the specified id is a valid uuid.
String
resolve_dns(name)
Return the ip address of the specified host name.
Bool
isA(type, obj, checked=[])
Return true if the specified object is of the specified type.
String
get_locale()
Return the current locale.
None
set_locale(locale=None)
Set the current locale.
None
e2_log(msg, level=logging.INFO, location='cherrypy')
Log a message.
Object
get_element(xml, element)
Return the XML element tree object built from the specified XML.
String
get_element_text(xml, element)
Return the text of the specfied element within the specified XML document.
Function Details [hide private]

is_list(obj)

 

Return true if the specified object is a list.

Example usage:

>>> from enomalism2.utilities import is_list
>>> is_list([])
Parameters:
  • obj (Object) - Any potential list object.
Returns: Boolean
True if obj is a list.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

is_dict(obj)

 

Return true if the specified object is a dictionary.

Example usage:

>>> from enomalism2.utilities import is_dict
>>> is_dict({})
Parameters:
  • obj (Object) - Any potential dict object.
Returns: Boolean
True if obj is a dict.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

is_str(obj)

 

Return true if the specified object is a string.

Example usage:

>>> from enomalism2.utilities import is_str
>>> is_str("")
Parameters:
  • obj (Object) - Any potential str object.
Returns: Boolean
True if obj is a str.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

is_int(obj)

 

Return true if the specified object is an integer.

Example usage:

>>> from enomalism2.utilities import is_int
>>> is_int(1)
Parameters:
  • obj (Object) - Any potential int object.
Returns: Boolean
True if obj is an int.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

is_long(obj)

 

Return true if the specified object is a long integer.

Example usage:

>>> from enomalism2.utilities import is_long
>>> is_long(5555555555555555)
Parameters:
  • obj (Object) - Any potential long object.
Returns: Boolean
True if obj is a long.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

is_float(obj)

 

Return true if the specified object is a float.

Example usage:

>>> from enomalism2.utilities import is_float
>>> is_float(1.111111)
Parameters:
  • obj (Object) - Any potential float object.
Returns: Boolean
True if obj is a float.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

is_bool(obj)

 

Return true if the specified object is a boolean.

Example usage:

>>> from enomalism2.utilities import is_bool
>>> is_bool(True)
Parameters:
  • obj (Object) - Any potential bool object.
Returns: Boolean
True if obj is a bool.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

is_unicode(obj)

 

Return true if the specified object is a unicode.

Example usage:

>>> from enomalism2.utilities import is_unicode
>>> is_unicode(u"")
Parameters:
  • obj (Object) - Any potential unicode object.
Returns: Boolean
True if obj is a unicode.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

is_none(obj)

 

Return true if the specified object is a None.

Example usage:

>>> from enomalism2.utilities import is_none
>>> is_none(None)
Parameters:
  • obj (Object) - Any potential none object.
Returns: Boolean
True if obj is a None.
Raises:
  • None - No exceptions are raised by this method.

Status: Stable

gen_timestamp(format='%Y-%m-%d %H:%M:%S')

 

Return a timestamp based on the specified format.

Example usage:

>>> from enomalism2.utilities import gen_timestamp
>>> gen_timestamp()
Parameters:
  • format (String) - The format used for the current time.
Returns: String
The current time.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

gen_uuid(value=None)

 

Generate a unique id. If a value is specified, a UUID conformant string is returned.

Example usage:

>>> from enomalism2.utilities import gen_uuid
>>> gen_uuid()
Parameters:
  • value (Int/Long/String) - An integer or a string representing a UUID.
Returns: String
A UUID string.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

get_ip_address(ifname='virbr0')

 

Return the ip address of the specified interface name.

Example usage:

>>> from enomalism2.utilities import get_ip_address
>>> get_ip_address()
Parameters:
  • ifname (String) - The name of the network interface.
Returns: String
The ip address.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

find_libvirt_services()

 

Return a list of the supported libvert services on this machine.

Example usage:

>>> from enomalism2.utilities import find_libvirt_services
>>> find_libvirt_services()
Returns: List
A list of libvert services.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

to_uuid(id)

 

Convert the provided EC2 id to a UUID instance. The first integer of the resulting UUID represents the type of EC2 object we are dealing with based on the prefix map. The provided EC2 id is split into to parts; the prefix and the hex. We then fill in the empty space and return a UUID.

Parameters:
  • id (String) - An EC2 instance or image id.
Returns: UUID
A newly created UUID instance representing the EC2 id.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

from_uuid(id)

 

Convert the provided UUID to its EC2 counterpart. We get the prefix of the EC2 id based on the prefix_map and the first character of the provided UUID. We then concatenate the prefix with the last 8 characters of the UUID.

Parameters:
  • id (UUID) - The UUID of an EC2 object.
Returns: String
The EC2 id.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

valid_uuid(id)

 

Return true if the specified id is a valid uuid.

Example usage:

>>> from enomalism2.utilities import valid_uuid
>>> valid_uuid('123')
Parameters:
  • id (String) - The id we are testing.
Returns: Boolean
True if id is a valid uuid.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

resolve_dns(name)

 

Return the ip address of the specified host name.

Example usage:

>>> from enomalism2.utilities import resolve_dns
>>> resolve_dns('google.com')
Parameters:
  • name (String) - The host name to resolve.
Returns: String
The ip address.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

isA(type, obj, checked=[])

 

Return true if the specified object is of the specified type. This method will also return true if the specified object is a sub-class of the specified type.

Example usage:

>>> from enomalism2.utilities import isA
>>> isA('string',"")
Parameters:
  • type (String) - The type to check against.
  • obj (Object) - The object to check.
  • checked (List) - The objects that have been checked.
Returns: Bool
True if the object matches the specified type.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

get_locale()

 

Return the current locale. First, we try to fetch the language preference from the current user. If this is not possible, we attempt to fetch the locale from the Enomalism configuration, defaulting to the TurboGears default if this cannot be found.

Example usage:

>>> from enomalism2.utilities import get_locale
>>> get_locale()
Returns: String
The current locale.
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

set_locale(locale=None)

 

Set the current locale.

Example usage:

>>> from enomalism2.utilities import set_locale
>>> set_locale()
Parameters:
  • locale (String) - The locale to set.
Returns: None
None
Raises:
  • None - No exceptions are raised by this function.

Status: Stable

e2_log(msg, level=logging.INFO, location='cherrypy')

 

Log a message.

Parameters:
  • msg (String) - The message to log.
  • level (Integer) - The level of looging to take place.
  • location (String) - The location to log to.
Returns: None
None
Raises:
  • None - No exceptions are raised by this method.

Status: Stable

get_element(xml, element)

 

Return the XML element tree object built from the specified XML.

Parameters:
  • xml (String) - The XML document.
  • element (String) - The name of the element we are searching for.
Returns: Object
The element tree object.
Raises:
  • e2_malformed_xml - Raised if the XML cannot be parsed.

Status: Beta

get_element_text(xml, element)

 

Return the text of the specfied element within the specified XML document.

Parameters:
  • xml (String) - The XML document.
  • element (String) - The name of the element we are searching for.
Returns: String
The text of the specified attribute.
Raises:
  • e2_malformed_xml - Raised if the XML cannot be parsed.

Status: Beta