networkapi.util package

Submodules

networkapi.util.decorators module

class networkapi.util.decorators.cached_property(func)[source]

Bases: object

Decorator that converts a method with a single self argument into a property cached on the instance. # https://github.com/django/django/blob/2456ffa42c33d63b54579eae0f5b9cf2a8cd3714/django/utils/functional.py#L38-50

networkapi.util.decorators.deprecated(new_uri=None)[source]

This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.

networkapi.util.decorators.logs_method_apiview(func)[source]
networkapi.util.decorators.mock_return(mock_value=None)[source]
networkapi.util.decorators.permission_classes_apiview(permission_classes)[source]
networkapi.util.decorators.permission_obj_apiview(functions)[source]
networkapi.util.decorators.raise_exception_treat(func)[source]

networkapi.util.json_validate module

networkapi.util.json_validate.json_validate(json_file)[source]
networkapi.util.json_validate.raise_json_validate(info=None)[source]
networkapi.util.json_validate.verify_ports(pools)[source]
networkapi.util.json_validate.verify_ports_vip(vips)[source]

networkapi.util.signals_helper module

networkapi.util.signals_helper.ValuesQuerySetToDict(vqs)[source]

converts a ValuesQuerySet to Dict

networkapi.util.signals_helper.get_m2m_fields_for(instance=None)[source]

gets m2mfields for instance

networkapi.util.signals_helper.get_m2m_values_for(instance=None)[source]
networkapi.util.signals_helper.m2m_clean_unchanged_fields(dict_diff)[source]

returns a list of dicts with only the changes

networkapi.util.signals_helper.m2m_dict_diff(old, new)[source]
networkapi.util.signals_helper.m2m_proccess_diff_states(old, new)[source]

old and new are dictionaries in the following format

old: {u’toppings.1’: {u’id’: [1, None], ‘name’: [u’ceboloa’, None]},

u’toppings.11’: {u’id’: [11, None], ‘name’: [u’abacate’, None]}, u’toppings.5’: {u’id’: [5, None], ‘name’: [u’cogumelo’, None]}, u’toppings.6’: {u’id’: [6, None], ‘name’: [u’abobrinha’, None]}, u’toppings.8’: {u’id’: [8, None], ‘name’: [u’codorna’, None]}, u’toppings.9’: {u’id’: [9, None], ‘name’: [u’banana’, None]}}

new: {u’toppings.1’: {u’id’: [None, 1], ‘name’: [None, u’ceboloa’]},

u’toppings.10’: {u’id’: [None, 10], ‘name’: [None, u’abacaxi’]}, u’toppings.5’: {u’id’: [None, 5], ‘name’: [None, u’cogumelo’]}, u’toppings.6’: {u’id’: [None, 6], ‘name’: [None, u’abobrinha’]}, u’toppings.8’: {u’id’: [None, 8], ‘name’: [None, u’codorna’]}, u’toppings.9’: {u’id’: [None, 9], ‘name’: [None, u’banana’]}}
networkapi.util.signals_helper.normalize_dict(d)[source]

removes datetime objects and passwords

networkapi.util.signals_helper.persist_m2m_audit()[source]

Module contents

class networkapi.util.IP_VERSION[source]
IPv4 = (u'v4', u'IPv4')
IPv6 = (u'v6', u'IPv6')
List = ((u'v4', u'IPv4'), (u'v6', u'IPv6'))
networkapi.util.cache_function(length, equipment=False)[source]

Cache the result of function

@param length: time in seconds to stay in cache

networkapi.util.clear_newline_chr(string)[source]
networkapi.util.clone(obj)[source]

Clone the object

@param obj: object to be cloned

@return object cloned.

networkapi.util.convert_boolean_to_int(param)[source]

Convert the parameter of boolean to int.

@param param: parameter to be converted.

@return Parameter converted.

networkapi.util.convert_string_or_int_to_boolean(param, force=None)[source]

Convert the parameter of string or int to boolean. @param param: parameter to be converted. @return Parameter converted.

networkapi.util.destroy_cache_function(key_list, equipment=False)[source]
networkapi.util.get_environment_map(environment)[source]
networkapi.util.get_vlan_map(vlan, network_ipv4, network_ipv6)[source]
networkapi.util.is_healthcheck_valid(healthcheck)[source]
networkapi.util.is_valid_boolean_param(param, required=True)[source]

Checks if the parameter is a valid boolean.

@param param: Value to be validated.

@return True if the parameter has a valid boolean value, or False otherwise.

networkapi.util.is_valid_email(param)[source]

Checks if the parameter is a valid e-mail.

@param param: Value to be validated.

@return True if the parameter has a valid e-mail value, or False otherwise.

networkapi.util.is_valid_healthcheck_destination(param)[source]

Checks if the parameter is a valid healthcheck_destination.

@param param: Value to be validated.

@return True if the parameter has a valid healthcheck_destination value, or False otherwise.

networkapi.util.is_valid_int_greater_equal_zero_param(param)[source]

Checks if the parameter is a valid integer value and greater and equal than zero.

@param param: Value to be validated.

@return True if the parameter has a valid integer value, or False otherwise.

networkapi.util.is_valid_int_greater_zero_param(param, required=True)[source]

Checks if the parameter is a valid integer value and greater than zero.

@param param: Value to be validated.

@return True if the parameter has a valid integer value, or False otherwise.

networkapi.util.is_valid_int_param(param, required=True)[source]

Checks if the parameter is a valid integer value.

@param param: Value to be validated.

@return True if the parameter has a valid integer value, or False otherwise.

networkapi.util.is_valid_ip(address)[source]

Verifica se address é um endereço ip válido.

networkapi.util.is_valid_ip_ipaddr(param)[source]

Checks if the parameter is a valid ip is ipv4 or ipv6.

@param param: Value to be validated.

@return True if the parameter has a valid ipv6 or ipv4 value, or False otherwise.

networkapi.util.is_valid_ipv4(param)[source]

Checks if the parameter is a valid ipv4.

@param param: Value to be validated.

@return True if the parameter has a valid ipv4 value, or False otherwise.

networkapi.util.is_valid_ipv6(param)[source]

Checks if the parameter is a valid ipv6.

@param param: Value to be validated.

@return True if the parameter has a valid ipv6 value, or False otherwise.

networkapi.util.is_valid_list_int_greater_zero_param(list_param, required=True)[source]

Checks if the parameter list is a valid integer value and greater than zero.

@param param: Value to be validated.

@raise ValidationError: If there is validation error in the field

networkapi.util.is_valid_option(param)[source]

Checks if the parameter is a valid field text and 0-9 and should follow the format of [A-Za-z] and special characters hyphen, underline and point.

@param param: Value to be validated.

@return True if the parameter has a valid text value, or False otherwise.

networkapi.util.is_valid_pool_identifier_text(param, required=True)[source]

Checks if the parameter is a valid field text and should follow the format of [A-Za-z] and special characters hyphen and underline.

@param param: Value to be validated. @param required: Check if the value can be None

@return True if the parameter has a valid text value, or False otherwise.

networkapi.util.is_valid_regex(string, regex)[source]

Checks if the parameter is a valid value by regex.

Parameters:param – Value to be validated.
Returns:True if the parameter has a valid vakue, or False otherwise.
networkapi.util.is_valid_string_maxsize(param, maxsize=None, required=True)[source]

Checks if the parameter is a valid string and his size is less than maxsize. If the parameter maxsize is None than the size is ignored If the parameter required is True than the string can not be None

@param param: Value to be validated. @param maxsize: Max size of the value to be validated. @param required: Check if the value can be None

@return True if the parameter is valid or False otherwise.

networkapi.util.is_valid_string_minsize(param, minsize=None, required=True)[source]

Checks if the parameter is a valid string and his size is more than minsize. If the parameter minsize is None than the size is ignored If the parameter required is True than the string can not be None

@param param: Value to be validated. @param minsize: Min size of the value to be validated. @param required: Check if the value can be None

@return True if the parameter is valid or False otherwise.

networkapi.util.is_valid_text(param, required=True)[source]

Checks if the parameter is a valid field text and should follow the format of [A-Za-z] and special characters hyphen and underline.

@param param: Value to be validated. @param required: Check if the value can be None

@return True if the parameter has a valid text value, or False otherwise.

networkapi.util.is_valid_uri(param)[source]

Checks if the parameter is a valid uri.

@param param: Value to be validated.

@return True if the parameter has a valid uri value, or False otherwise.

networkapi.util.is_valid_version_ip(param, IP_VERSION)[source]

Checks if the parameter is a valid ip version value.

@param param: Value to be validated.

@return True if the parameter has a valid ip version value, or False otherwise.

networkapi.util.is_valid_yes_no_choice(param)[source]

Checks if the parameter is valid ‘S’ or ‘N’ char.

@param param: valid to be validated.

@return True if the parameter is a valid choice, or False otherwise.

networkapi.util.is_valid_zero_one_param(param, required=True)[source]

Checks if the parameter is a valid zero or one string.

@param param: Value to be validated.

@return True if the parameter has a valid zero or one value, or False otherwise.

networkapi.util.mount_ipv4_string(ip)[source]
networkapi.util.mount_ipv6_string(ip)[source]
networkapi.util.search_hide_password(msg)[source]

Search and hide password

networkapi.util.to_ip(address)[source]

Resolve o endereço IP caso address seja um hostname.

Parameters:address – Hostname ou endereço IP.
Returns:Endereço IP correspondente ao endereço informado.
networkapi.util.valid_expression(operator, value1, value2)[source]
networkapi.util.valid_regex(string, regex)[source]