networkapi.infrastructure package

Submodules

networkapi.infrastructure.datatable module

networkapi.infrastructure.datatable.build_query_to_datatable(query_set, asorting_cols, custom_search, searchable_columns, start_record, end_record)[source]

Build query using params received

networkapi.infrastructure.datatable.build_query_to_datatable_v3(query_set, search={})[source]

Build query using params received and return with dict

Parameters:
  • query_set – Object “query” with data
  • search.extends_search – Permmit to filter objects by relationship or
  • search.asorting_cols – List of fields to use in “order_by”
  • search.custom_search – Value generic to search in some fields
  • search.searchable_columns – List of fields used in “generic search”
  • search.start_record – Value used in initial “limit”
  • search.end_record – Value used in final “limit
Return obj_map.total:
 

Total objects returned

Return obj_map.next_search:
 

Copy of search

Return obj_map.next_search.start_record:
 

Value to use in initial “limit” in next search(add 25)

Return obj_map.next_search.end_record:
 

Value to use in final “limit” in next search(add 25)

Return obj_map.prev_search.start_record:
 

Value to use in initial “limit” in prev search(remove 25 of value received)

Return obj_map.prev_search.end_record:
 

Value to use in final “limit” in prev search(remove 25 of value received)

networkapi.infrastructure.ip_subnet_utils module

networkapi.infrastructure.ip_subnet_utils.get_prefix_IPV4(num_hosts)[source]
networkapi.infrastructure.ip_subnet_utils.get_prefix_IPV6(num_hosts)[source]
networkapi.infrastructure.ip_subnet_utils.is_subnetwork(network_address_01, network_address_02)[source]

Verifica se o endereço network_address_01 é sub-rede do endereço network_address_02.

@param network_address_01: Uma tuple com os octetos do endereço, formato: (oct1, oct2, oct3, oct5) @param network_address_02: Uma tuple com os octetos do endereço e o bloco, formato: (oct1, oct2, oct3, oct5, bloco)

@return: True se network_address_01 é sub-rede de network_address_02. False caso contrário.

networkapi.infrastructure.ip_subnet_utils.is_valid_ip(address)[source]

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

networkapi.infrastructure.ip_subnet_utils.network_mask_from_cidr_mask(cidr_mask)[source]

Calcula a máscara de uma rede a partir do número do bloco do endereço.

@param cidr_mask: Valor do bloco do endereço.

@return: Tuple com o octeto 1, 2, 3, 4 da máscara: (oct1,oct2,oct3,oct4).

networkapi.infrastructure.ipaddr module

A fast, lightweight IPv4/IPv6 manipulation library in Python.

This library is used to create/poke/manipulate IPv4 and IPv6 addresses and networks.

exception networkapi.infrastructure.ipaddr.AddressValueError[source]

Bases: exceptions.ValueError

A Value Error related to the address.

networkapi.infrastructure.ipaddr.CollapseAddrList(addresses)

Collapse a list of IP objects.

Example:
collapse_address_list([IPv4(‘1.1.0.0/24’), IPv4(‘1.1.1.0/24’)]) ->
[IPv4(‘1.1.0.0/23’)]
Args:
addresses: A list of IPv4Network or IPv6Network objects.
Returns:
A list of IPv4Network or IPv6Network objects depending on what we were passed.
Raises:
TypeError: If passed a list of mixed version objects.
networkapi.infrastructure.ipaddr.IPAddress(address, version=None)[source]

Take an IP string/int and return an object of the correct type.

Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default.
version: An Integer, 4 or 6. If set, don’t try to automatically
determine what the IP address type is. important for things like IPAddress(1), which could be IPv4, ‘0.0.0.1’, or IPv6, ‘::1’.
Returns:
An IPv4Address or IPv6Address object.
Raises:
ValueError: if the string passed isn’t either a v4 or a v6
address.
networkapi.infrastructure.ipaddr.IPNetwork(address, version=None, strict=False)[source]

Take an IP string/int and return an object of the correct type.

Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default.
version: An Integer, if set, don’t try to automatically
determine what the IP address type is. important for things like IPNetwork(1), which could be IPv4, ‘0.0.0.1/32’, or IPv6, ‘::1/128’.
Returns:
An IPv4Network or IPv6Network object.
Raises:
ValueError: if the string passed isn’t either a v4 or a v6
address. Or if a strict network was requested and a strict network wasn’t given.
class networkapi.infrastructure.ipaddr.IPv4Address(address)[source]

Bases: networkapi.infrastructure.ipaddr._BaseV4, networkapi.infrastructure.ipaddr._BaseIP

Represent and manipulate single IPv4 Addresses.

class networkapi.infrastructure.ipaddr.IPv4Network(address, strict=False)[source]

Bases: networkapi.infrastructure.ipaddr._BaseV4, networkapi.infrastructure.ipaddr._BaseNet

This class represents and manipulates 32-bit IPv4 networks.

Attributes: [examples for IPv4Network(‘1.2.3.4/27’)]
._ip: 16909060 .ip: IPv4Address(‘1.2.3.4’) .network: IPv4Address(‘1.2.3.0’) .hostmask: IPv4Address(‘0.0.0.31’) .broadcast: IPv4Address(‘1.2.3.31’) .netmask: IPv4Address(‘255.255.255.224’) .prefixlen: 27
IsLinkLocal()
IsLoopback()
IsMulticast()
IsRFC1918()
class networkapi.infrastructure.ipaddr.IPv6Address(address)[source]

Bases: networkapi.infrastructure.ipaddr._BaseV6, networkapi.infrastructure.ipaddr._BaseIP

Represent and manipulate single IPv6 Addresses.

class networkapi.infrastructure.ipaddr.IPv6Network(address, strict=False)[source]

Bases: networkapi.infrastructure.ipaddr._BaseV6, networkapi.infrastructure.ipaddr._BaseNet

This class represents and manipulates 128-bit IPv6 networks.

Attributes: [examples for IPv6(‘2001:658:22A:CAFE:200::1/64’)]
.ip: IPv6Address(‘2001:658:22a:cafe:200::1’) .network: IPv6Address(‘2001:658:22a:cafe::’) .hostmask: IPv6Address(‘::ffff:ffff:ffff:ffff’) .broadcast: IPv6Address(‘2001:658:22a:cafe:ffff:ffff:ffff:ffff’) .netmask: IPv6Address(‘ffff:ffff:ffff:ffff::’) .prefixlen: 64
with_netmask
exception networkapi.infrastructure.ipaddr.NetmaskValueError[source]

Bases: exceptions.ValueError

A Value Error related to the netmask.

networkapi.infrastructure.ipaddr.collapse_address_list(addresses)[source]

Collapse a list of IP objects.

Example:
collapse_address_list([IPv4(‘1.1.0.0/24’), IPv4(‘1.1.1.0/24’)]) ->
[IPv4(‘1.1.0.0/23’)]
Args:
addresses: A list of IPv4Network or IPv6Network objects.
Returns:
A list of IPv4Network or IPv6Network objects depending on what we were passed.
Raises:
TypeError: If passed a list of mixed version objects.
networkapi.infrastructure.ipaddr.get_mixed_type_key(obj)[source]

Return a key suitable for sorting between networks and addresses.

Address and Network objects are not sortable by default; they’re fundamentally different so the expression

IPv4Address(‘1.1.1.1’) <= IPv4Network(‘1.1.1.1/24’)

doesn’t make any sense. There are some times however, where you may wish to have ipaddr sort these for you anyway. If you need to do this, you can use this function as the key= argument to sorted().

Args:
obj: either a Network or Address object.
Returns:
appropriate key.
networkapi.infrastructure.ipaddr.summarize_address_range(first, last)[source]

Summarize a network range given the first and last IP addresses.

Example:
>>> summarize_address_range(IPv4Address('1.1.1.0'),
    IPv4Address('1.1.1.130'))
[IPv4Network('1.1.1.0/25'), IPv4Network('1.1.1.128/31'),
IPv4Network('1.1.1.130/32')]
Args:
first: the first IPv4Address or IPv6Address in the range. last: the last IPv4Address or IPv6Address in the range.
Returns:
The address range collapsed to a list of IPv4Network’s or IPv6Network’s.
Raise:
TypeError:
If the first and last objects are not IP addresses. If the first and last objects are not the same version.
ValueError:
If the last object is not greater than the first. If the version is not 4 or 6.
networkapi.infrastructure.ipaddr.v4_int_to_packed(address)[source]

The binary representation of this address.

Args:
address: An integer representation of an IPv4 IP address.
Returns:
The binary representation of this address.
Raises:
ValueError: If the integer is too large to be an IPv4 IP
address.
networkapi.infrastructure.ipaddr.v6_int_to_packed(address)[source]

The binary representation of this address.

Args:
address: An integer representation of an IPv4 IP address.
Returns:
The binary representation of this address.

networkapi.infrastructure.script_utils module

exception networkapi.infrastructure.script_utils.ScriptError(cause, message)[source]

Bases: exceptions.Exception

Representa um erro ocorrido durante a chamada do script.

networkapi.infrastructure.script_utils.exec_script(command)[source]

networkapi.infrastructure.xml_utils module

exception networkapi.infrastructure.xml_utils.InvalidNodeNameXMLError(cause, message)[source]

Bases: networkapi.infrastructure.xml_utils.XMLError

Nome inválido para representá-lo como uma TAG de XML.

exception networkapi.infrastructure.xml_utils.InvalidNodeTypeXMLError(cause, message)[source]

Bases: networkapi.infrastructure.xml_utils.XMLError

Tipo inválido para o conteúdo de uma TAG de XML.

exception networkapi.infrastructure.xml_utils.XMLError(cause, message)[source]

Bases: exceptions.Exception

Representa um erro ocorrido durante o marshall ou unmarshall do XML.

networkapi.infrastructure.xml_utils.dumps(map, root_name, root_attributes=None)[source]

Cria um string no formato XML a partir dos elementos do map.

Os elementos do mapa serão nós filhos do root_name.

Cada chave do map será um Nó no XML. E o valor da chave será o conteúdo do Nó.

Throws: XMLError, InvalidNodeNameXMLError, InvalidNodeTypeXMLError

networkapi.infrastructure.xml_utils.dumps_networkapi(map, version='1.0')[source]
networkapi.infrastructure.xml_utils.loads(xml, force_list=None)[source]

Cria um dict com os dados do element root.

O dict terá como chave o nome do element root e como valor o conteúdo do element root. Quando o conteúdo de um element é uma lista de Nós então o valor do element será um dict com uma chave para cada nó. Entretanto, se existir nós, de um mesmo pai, com o mesmo nome, então eles serão armazenados uma mesma chave do dict que terá como valor uma lista.

Se o element root tem atributo, então também retorna um dict com os atributos.

Throws: XMLError

Module contents