8.2. Common Functions for Jinja processing

nettoolkit.j2config.cmn.common_fn.addressing(net)[source]

get the ip of given subnet

Parameters:

net (str) – input ipv4 address

Returns:

ip address

Return type:

str

nettoolkit.j2config.cmn.common_fn.as_path_repeat(asn, times)[source]

as-path repeat function

Parameters:
  • asn (str) – as number

  • times (int) – number of time to be repeated.

Returns:

as path appended string

Return type:

str

nettoolkit.j2config.cmn.common_fn.comma_separated(items)[source]

joins provided items (iterables) by comma

Parameters:

items (list) – input items

Returns:

joins items by comma

Return type:

str

nettoolkit.j2config.cmn.common_fn.convert_to_int(lst)[source]

convert numeric string type elements to integer type in a list.

Parameters:

lst (list) – converts numeric eliments as integer

Returns:

updated list

Return type:

list

nettoolkit.j2config.cmn.common_fn.get_item(lst, n)[source]

get the nth item from list

Parameters:
  • lst (list) – list containing various items

  • n (int) – index of item to be retrived

Returns:

n-th item from list

Return type:

str

nettoolkit.j2config.cmn.common_fn.get_summaries(lst_of_pfxs)[source]

get the summaries for provided prefixes.

Parameters:

lst_of_pfxs (list) – list of prefixes to be summarized

Returns:

list of summarized prefixes

Return type:

list

nettoolkit.j2config.cmn.common_fn.groups_of_nine(lst)[source]

breaks down provided list in to multiple groups with max. nine elements in each group

Parameters:

lst (list) – input list

Returns:

updated list of (lists: containing 9 elements)

Return type:

list

nettoolkit.j2config.cmn.common_fn.int_to_str(data)[source]

get the actual physical interface value by removing training sub interfaces.

Parameters:

data (str) – input interface string

Returns:

trunkated interface (after removal of sub-interface value)

Return type:

str

nettoolkit.j2config.cmn.common_fn.invmask(net)[source]

get inverse mask for given network (eg: 0.0.0.255)

Parameters:

net (str) – input ipv4 address

Returns:

subnet mask

Return type:

str

nettoolkit.j2config.cmn.common_fn.iprint(x)[source]

i print function to be use withing jinja template for debug.

Parameters:

x (str) – value to be print during junja process

nettoolkit.j2config.cmn.common_fn.ipv6_urpf_acl_network(subnet)[source]

provides ipv6 address network ip

Parameters:

subnet (str) – ipv6 address

Returns:

network address value for provided ipv6 address

Return type:

str

nettoolkit.j2config.cmn.common_fn.list_append(lst, item)[source]

append an item to list

Parameters:
  • lst (list) – input list

  • item (str, number) – item to be appeneded to list

Returns:

updated list

Return type:

list

nettoolkit.j2config.cmn.common_fn.list_extend(lst, item)[source]

Extend the list of items to list

Parameters:
  • lst (list) – input list

  • item (list) – list of items to be extended to input list

Returns:

updated list

Return type:

list

nettoolkit.j2config.cmn.common_fn.list_sorted(lst)[source]

provided sorted elements in list

Parameters:

lst (list) – input list

Returns:

updated list

Return type:

list

nettoolkit.j2config.cmn.common_fn.mask(net)[source]

get the subnet mask for given network (eg: 24)

Parameters:

net (str) – input ipv4 address

Returns:

subnet mask

Return type:

str

nettoolkit.j2config.cmn.common_fn.netmask(net)[source]

get network mask for given network (eg: 255.255.255.0)

Parameters:

net (str) – input ipv4 address

Returns:

subnet mask

Return type:

str

nettoolkit.j2config.cmn.common_fn.nth_ip(net, n, withMask=False)[source]

get n-th ip address of given network. withMask: will return value along with mask otherwise only subnet

Parameters:
  • net (str) – input ipv4 address

  • n (int) – number (number of ip address to be return from subnet)

  • withMask (bool, optional) – return with mask or without mask. Defaults to False.

Returns:

nth ip address from subnet

Return type:

str

nettoolkit.j2config.cmn.common_fn.physical_if_allowed(vlan, table)[source]

condition: checks for filter==physical and vlan in vlan_members

Parameters:
  • vlan (str, int) – vlan number

  • table (dict) – dataframe dictionary

Returns:

interface value of matching row

Return type:

int

nettoolkit.j2config.cmn.common_fn.remove_trailing_zeros(net)[source]

removes the trailing zeros from given ipv6 address

Parameters:

net (str) – input ipv6 address

Returns:

updated ipv6 address by removing trailing zeros

Return type:

str

nettoolkit.j2config.cmn.common_fn.space_separated(items)[source]

joins provided items (iterables) by spaces

Parameters:

items (list) – input items

Returns:

joins items by space

Return type:

str

nettoolkit.j2config.cmn.common_fn.str_to_list(item)[source]

splits string and returns list, items separated by either comma, enter

Parameters:

item (str, int, float) – input string or number value(s)

Returns:

separated list of input items

Return type:

list

nettoolkit.j2config.cmn.common_fn.string(s)[source]
nettoolkit.j2config.cmn.common_fn.string_as_is(s)[source]
nettoolkit.j2config.cmn.common_fn.v4addressing(ip, mask='32')[source]

get the IPv4 objetct for given ip/mask (default mask=32)

Parameters:
  • ip (str) – input ip address/mask value

  • mask (str, optional) – ip_mask. Defaults to “32”.

Returns:

IPv4 object

Return type:

IPv4