# neutron_lib.utils.helpers module

neutron_lib.utils.helpers.camelize(s)

  Camelize a str that uses _ as a camelize token.

  Parameters:

    s – The str to camelize that contains a _ at each index where a new camelized word starts.

  Returns:

    The camelized str.

neutron_lib.utils.helpers.compare_elements(a, b)

  Compare elements if a and b have same elements.

  This method doesn’t consider ordering.

  Parameters:

    - a – The first item to compare.

    - b – The second item to compare.

  Returns:

    True if a and b have the same elements, False otherwise.

neutron_lib.utils.helpers.dict2str(dic)

  Build a str representation of a dict.

  Parameters:

    dic – The dict to build a str representation for.

  Returns:

    The dict in str representation that is a k=v command list for each item in dic.

neutron_lib.utils.helpers.dict2tuple(d)

  Build a tuple from a dict.

  Parameters:

    d – The dict to coherence into a tuple.

  Returns:

    The dict d in tuple form.

neutron_lib.utils.helpers.diff_list_of_dict(old_list, new_list)

  Given 2 lists of dicts, return a tuple containing the diff.

  Parameters:

    - old_list – The old list of dicts to diff.

    - new_list – The new list of dicts to diff.

  Returns:

    A tuple where the first item is a list of the added dicts in the diff and the second item is the removed dicts.

neutron_lib.utils.helpers.get_random_string(length)

  Get a random hex string of the specified length.

  Parameters:

    length – The length for the hex string.

  Returns:

    A random hex string of the said length.

neutron_lib.utils.helpers.make_weak_ref(f)

  Make a weak reference to a function accounting for bound methods.

  Parameters:

    f – The callable to make a weak ref for.

  Returns:

    A weak ref to f.

neutron_lib.utils.helpers.parse_mappings(mapping_list, unique_values=True, unique_keys=True)

  Parse a list of mapping strings into a dictionary.

  Parameters:

    - mapping_list – A list of strings of the form ‘<key>:<value>’.

    - unique_values – Values must be unique if True.

    - unique_keys – Keys must be unique if True, else implies that keys and values are not unique.

  Returns:

    A dict mapping keys to values or to list of values.

  Raises:

    ValueError – Upon malformed data or duplicate keys.

neutron_lib.utils.helpers.resolve_ref(ref)

  Handles dereference of weakref.

  Parameters:

    ref – The weak ref to resolve.

  Returns:

    The resolved reference.

neutron_lib.utils.helpers.round_val(val)

  Round the value.

  Parameters:

    val – The value to round.

  Returns:

    The value rounded using the half round up scheme.

neutron_lib.utils.helpers.safe_decode_utf8(s)

  Safe decode a str from UTF.

  Parameters:

    s – The str to decode.

  Returns:

    The decoded str.

neutron_lib.utils.helpers.safe_sort_key(value)

  Return value hash or build one for dictionaries.

  Parameters:

    value – The value to build a hash for.

  Returns:

    The value sorted.

neutron_lib.utils.helpers.str2dict(string)

  Parse a str representation of a dict into its dict form.

  This is the inverse of dict2str()

  Parameters:

    string – The string to parse.

  Returns:

    A dict constructed from the str representation in string.

neutron_lib.utils.helpers.timecost(f)

this page last updated: 2026-08-15 12:38:23

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug