~rvb/maas/ssfilter

« back to all changes in this revision

Viewing changes to src/maasserver/dhcp.py

[r=jtv][bug=1283114][author=julian-edwards] Make sure the DHCP config is rewritten when all a cluster's interfaces go unmanaged.  Previously, this condition was ignored so the DHCP server carried on serving when it should not be.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
def get_interfaces_managed_by(nodegroup):
30
30
    """Return `NodeGroupInterface` objects for which `nodegroup` manages DHCP.
31
31
 
32
 
    Returns only interfaces for which MAAS is supposed to serve DHCP.  If DHCP
33
 
    is disabled, or the node group is not accepted, an empty list will be
34
 
    returned.  Interfaces whose DHCP is not managed are not returned in any
35
 
    case.
 
32
    Returns only interfaces for which MAAS is supposed to serve DHCP.
 
33
    If the node group is not accepted, an empty list will be returned.
 
34
    Interfaces whose DHCP is not managed are not returned in any case.
36
35
    """
37
 
    if settings.DHCP_CONNECT and nodegroup.status == NODEGROUP_STATUS.ACCEPTED:
 
36
    if nodegroup.status == NODEGROUP_STATUS.ACCEPTED:
38
37
        return nodegroup.get_managed_interfaces()
39
 
    else:
40
 
        return []
 
38
 
 
39
    return None
41
40
 
42
41
 
43
42
def configure_dhcp(nodegroup):
44
43
    """Write the DHCP configuration file and restart the DHCP server."""
 
44
    # Let's get this out of the way first up shall we?
 
45
    if not settings.DHCP_CONNECT:
 
46
        # For the uninitiated, DHCP_CONNECT is set, by default, to False
 
47
        # in all tests and True in non-tests.  This avoids unnecessary
 
48
        # calls to async tasks.
 
49
        return
 
50
 
45
51
    # Circular imports.
46
52
    from maasserver.dns import get_dns_server_address
47
53
 
48
54
    interfaces = get_interfaces_managed_by(nodegroup)
49
 
    if interfaces == []:
 
55
    if interfaces is None:
50
56
        return
51
57
 
52
58
    # Make sure this nodegroup has a key to communicate with the dhcp