~ubuntu-branches/ubuntu/utopic/maas/utopic-security

« back to all changes in this revision

Viewing changes to src/maasserver/utils/network.py

  • Committer: Package Import Robot
  • Author(s): Julian Edwards, Julian Edwards, Andres Rodriguez
  • Date: 2014-08-21 18:38:27 UTC
  • mfrom: (1.2.34)
  • Revision ID: package-import@ubuntu.com-20140821183827-9xyb5u2o4l8g3zxj
Tags: 1.6.1+bzr2550-0ubuntu1
* New upstream bugfix release:
  - Auto-link node MACs to Networks (LP: #1341619)

[ Julian Edwards ]
* debian/maas-region-controller.postinst: Don't restart RabbitMQ on
  upgrades, just ensure it's running.  Should prevent a race with the
  cluster celery restarting.
* debian/rules: Pull upstream branch from the right place.

[ Andres Rodriguez ]
* debian/maas-region-controller.postinst: Ensure cluster celery is
  started if it also runs on the region.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2014 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Generic helpers for `netaddr` and network-related types."""
5
 
 
6
 
from __future__ import (
7
 
    absolute_import,
8
 
    print_function,
9
 
    unicode_literals,
10
 
    )
11
 
 
12
 
str = None
13
 
 
14
 
__metaclass__ = type
15
 
__all__ = [
16
 
    'make_network',
17
 
    ]
18
 
 
19
 
 
20
 
from netaddr import IPNetwork
21
 
 
22
 
 
23
 
def make_network(ip_address, netmask_or_bits, **kwargs):
24
 
    """Construct an `IPNetwork` with the given address and netmask or width.
25
 
 
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.
30
 
 
31
 
    :param ip_address:
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
36
 
        malformed.
37
 
    :return: An `IPNetwork` of the given base address and netmask or bit width.
38
 
    """
39
 
    return IPNetwork("%s/%s" % (ip_address, netmask_or_bits), **kwargs)