1
# Copyright 2014 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Generic helpers for `netaddr` and network-related types."""
6
from __future__ import (
20
from netaddr import IPNetwork
23
def make_network(ip_address, netmask_or_bits, **kwargs):
24
"""Construct an `IPNetwork` with the given address and netmask or width.
26
This is a thin wrapper for the `IPNetwork` constructor. It's here because
27
the constructor for `IPNetwork` is easy to get wrong. If you pass it an
28
IP address and a netmask, or an IP address and a bit size, it will seem to
29
work... but it will pick a default netmask, not the one you specified.
32
:param netmask_or_bits:
33
:param kwargs: Any other (keyword) arguments you want to pass to the
34
`IPNetwork` constructor.
35
:raise netaddr.core.AddrFormatError: If the network specification is
37
:return: An `IPNetwork` of the given base address and netmask or bit width.
39
return IPNetwork("%s/%s" % (ip_address, netmask_or_bits), **kwargs)