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

« back to all changes in this revision

Viewing changes to src/maasserver/server_address.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez, Jeroen Vermeulen, Andres Rodriguez, Jason Hobbs, Raphaël Badin, Louis Bouchard, Gavin Panella
  • Date: 2014-08-21 19:36:30 UTC
  • mfrom: (1.3.1)
  • Revision ID: package-import@ubuntu.com-20140821193630-kertpu5hd8yyss8h
Tags: 1.7.0~beta7+bzr3266-0ubuntu1
* New Upstream Snapshot, Beta 7 bzr3266

[ Jeroen Vermeulen ]
* debian/extras/99-maas-sudoers
  debian/maas-dhcp.postinst
  debian/rules
  - Add second DHCP server instance for IPv6.
* debian/maas-region-controller-min.install
  debian/maas-region-controller-min.lintian-overrides
  - Install deployment user-data: maas_configure_interfaces.py script.
* debian/maas-cluster-controller.links
  debian/maas-cluster-controller.install
  debian/maas-cluster-controller.postinst
  - Reflect Celery removal changes made in trunk r3067.
  - Don't install celeryconfig_cluster.py any longer. 
  - Don't install maas_local_celeryconfig_cluster.py any longer.
  - Don't symlink maas_local_celeryconfig_cluster.py from /etc to /usr.
  - Don't insert UUID into maas_local_celeryconfig_cluster.py.

[ Andres Rodriguez ]
* debian/maas-region-controller-min.postrm: Cleanup lefover files.
* debian/maas-dhcp.postrm: Clean leftover configs.
* Provide new maas-proxy package that replaces the usage of
  squid-deb-proxy:
  - debian/control: New maas-proxy package that replaces the usage
    of squid-deb-proxy; Drop depends on squid-deb-proxy.
  - Add upstrart job.
  - Ensure squid3 is stopped as maas-proxy uses a caching proxy.
* Remove Celery references to cluster controller:
  - Rename upstart job from maas-pserv to maas-cluster; rename
    maas-cluster-celery to maas-cluster-register. Ensure services
    are stopped on upgrade.
  - debian/maintscript: Cleanup config files.
  - Remove all references to the MAAS celery daemon and config
    files as we don't use it like that anymore
* Move some entries in debian/maintscript to
  debian/maas-cluster-controller.maintscript
* Remove usage of txlongpoll and rabbitmq-server. Handle upgrades
  to ensure these are removed correctly.

[ Jason Hobbs ]
* debian/maas-region-controller-min.install: Install
  maas-generate-winrm-cert script.

[ Raphaël Badin ]
* debian/extras/maas-region-admin: Bypass django-admin as it prints
  spurious messages to stdout (LP: #1365130).

[Louis Bouchard]
* debian/maas-cluster-controller.postinst:
  - Exclude /var/log/maas/rsyslog when changing ownership
    (LP: #1346703)

[Gavin Panella]
* debian/maas-cluster-controller.maas-clusterd.upstart:
  - Don't start-up the cluster controller unless a shared-secret has
    been installed.
* debian/maas-cluster-controller.maas-cluster-register.upstart: Drop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2012 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2012-2014 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Helper to obtain the MAAS server's address."""
18
18
    ]
19
19
 
20
20
 
21
 
from socket import (
22
 
    AF_INET,
23
 
    AF_INET6,
24
 
    gaierror,
25
 
    getaddrinfo,
26
 
    )
27
21
from urlparse import urlparse
28
22
 
29
23
from django.conf import settings
30
 
from maasserver.exceptions import (
31
 
    NoAddressFoundForHost,
32
 
    UnresolvableHost,
 
24
from maasserver.exceptions import UnresolvableHost
 
25
from netaddr import (
 
26
    valid_ipv4,
 
27
    valid_ipv6,
33
28
    )
34
 
from netaddr import IPAddress
35
 
 
36
 
# Arbitrary non-privileged port
37
 
PORT = 33360
 
29
from provisioningserver.utils.network import resolve_hostname
38
30
 
39
31
 
40
32
def get_maas_facing_server_host(nodegroup=None):
52
44
    return urlparse(maas_url).hostname
53
45
 
54
46
 
55
 
def get_maas_facing_server_address(nodegroup=None):
 
47
def get_maas_facing_server_address(nodegroup=None, ipv4=True, ipv6=True):
56
48
    """Return address where nodes and workers can reach the MAAS server.
57
49
 
58
 
    The address is taken from DEFAULT_MAAS_URL or nodegroup.maas_url.
 
50
    The address is taken from `DEFAULT_MAAS_URL` or `nodegroup.maas_url`.
59
51
    If there is more than one IP address for the host, the addresses
60
52
    will be sorted and the first IP address in the sorted set will be
61
 
    returned. IPv4 addresses will be sorted before IPv6 addresses, so
62
 
    IPv4 addresses will be preferred if both exist.
 
53
    returned.  IPv4 addresses will be sorted before IPv6 addresses, so
 
54
    this prefers IPv4 addresses over IPv6 addresses.  It also prefers global
 
55
    IPv6 addresses over link-local IPv6 addresses or IPv6-mapped IPv4
 
56
    addresses.
63
57
 
64
58
    :param nodegroup: The nodegroup from the point of view of which the
65
59
        server address should be computed.
 
60
    :param ipv4: Include IPv4 addresses?  Defaults to `True`.
 
61
    :param ipv6: Include IPv6 addresses?  Defaults to `True`.
66
62
    :return: An IP address as a unicode string.  If the configured URL
67
63
        uses a hostname, this function will resolve that hostname.
 
64
    :raise UnresolvableHost: if no IP addresses could be found for
 
65
        the hostname.
68
66
    """
 
67
    hostname = get_maas_facing_server_host(nodegroup)
69
68
    addresses = set()
70
 
    hostname = get_maas_facing_server_host(nodegroup)
71
 
    try:
72
 
        address_info = getaddrinfo(hostname, PORT)
73
 
    except gaierror:
74
 
        raise UnresolvableHost("Unable to resolve host %s" % hostname)
75
 
 
76
 
    for (family, socktype, proto, canonname, sockaddr) in address_info:
77
 
        if family not in (AF_INET, AF_INET6):
78
 
            # We're not interested in anything other than IPv4 and v6
79
 
            # addresses, so bail out of this loop.
80
 
            continue
81
 
        # The contents of sockaddr differ for IPv6 and IPv4, but the
82
 
        # first elemment is always the address, and that's all we care
83
 
        # about.
84
 
        addresses.add(IPAddress(sockaddr[0]))
 
69
    if valid_ipv6(hostname):
 
70
        if ipv6:
 
71
            addresses.add(hostname)
 
72
    elif valid_ipv4(hostname):
 
73
        if ipv4:
 
74
            addresses.add(hostname)
 
75
    else:
 
76
        if ipv4:
 
77
            addresses = addresses.union(resolve_hostname(hostname, 4))
 
78
        if ipv6:
 
79
            addresses = addresses.union(resolve_hostname(hostname, 6))
85
80
    if len(addresses) == 0:
86
 
        raise NoAddressFoundForHost(
87
 
            "No address found for host %s." % hostname)
 
81
        raise UnresolvableHost("No address found for host %s." % hostname)
88
82
    return min(addresses).format().decode("ascii")