~ubuntu-branches/ubuntu/saucy/maas/saucy-updates

« back to all changes in this revision

Viewing changes to src/provisioningserver/dhcp/leases.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez, Julian Edwards, Raphaël Badin, Jeroen Vermeulen, Andres Rodriguez, Robie Basak, Scott Moser, Diogo Matsubara
  • Date: 2012-10-08 13:10:23 UTC
  • mfrom: (1.1.18)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20121008131023-68glibh0pbqrgtfq
Tags: 0.1+bzr1223+dfsg-0ubuntu1
* New upstream release. (LP: #1062518)

[ Julian Edwards ]
* Split packaging of 'maas' into maas-{region,cluster}-controller
  - debian/control: Update accordingly.
  - debian/*.install: Move files accordingly
  - debian/*.{postinst,postrm,preinst}: Move files accordingly.
* Ensure isc-dhcp-server is disabled when installing maas-dhcp.
* Ensure maas-dns creates the maas user before trying to chown files.
* Make maas-cluster-controller autoconfigure itself when upgrading from the
  old maas package. (LP: #1059416)
* Add missing prerm file for maas-cluster-controller so that .pyc files
  are cleaned up. (LP: #1059973)

[ Raphaël Badin ]
* Install maas_local_celeryconfig.py in /etc/maas and symlink to
  /usr/share/maas.
* debian/maas.postinst: Create rabbitmq celery user/vhost.
* debian/maas.postinst: Update BROKER_URL in maas_local_celeryconfig.py.
* Use maas_local_celeryconfig_cluster.py as the local celery
  configuration file for the cluster worker.
* debian/maas-region-controller.maas-region-celery.upstart: Add region
  worker upstart script.
* Rename cluster worker upstart script into
  maas-cluster-controller.maas-clluster-celery.upstart.
* maas-cluster-controller.maas-celery.upstart: use "celeryconfig_cluster"
  as the Celery config module.
* debian/maas-common.install: Install celeryconfig_common.py.
* debian/maas-cluster-controller.install: Install celeryconfig_cluster.py.
* debian/maas-region-controller.install: Install celeryconfig.py.
* Split celery config into cluster and region configs.
* Add region celeryd upstart config.
* Define CELERY_CONFIG_MODULE in
  maas-cluster-controller.maas-cluster-celery.upstart

[ Jeroen Vermeulen ]
* Make maas_local_celery_config.py non-world readable.
* Make maas_local_celeryconfig_cluster.py non-world readable.
* Set root:maas ownership of local cluster config only *after*
  the maas user/group have been created

[ Andres Rodriguez ]
* debian/maas.postinst:
  - Always restart apache2.
  - Handle upgrades for new upstream release.
  - Handle upgrades for celery rabbitmq worker.
* Add binary package to install client tool.
  - debian/extras/maas-cli: Add binary.
  - debian/maas-cli.install: Add. Install maascli and apiclient.
  - debian/control: Add binary package.
* debian/control:
  - Depends on freeipmi-tools instead of ipmitool.
  - Conflicts/Replaces on maas for python-maas-client.
  - Depends on python-netifaces, python-lxml.
* Add python-maas-client binary package:
  - debian/python-maas-client.install: Add. Install 'apiclient' python module.
  - debian/control: Add package. python-django-maas and maas-cli now
    Depend on it.
* debian/rules: Install maas-dhcp-server upstart job.
* debian/maas.postrm: Remove celery worker rabbitmq user and host.
* debian/extras/99-maas-sudoers: Add for maas-dhcp-server upstart job
  instead of isc-dhcp-server (LP: #1055951)
* debian/maas-region-controller.postinst: Cleanup upgrade rules.
* debian/maas-cluster-controller.postinst: Fix 'local' usage.
* debian/maas-common.install: Install celeryconfig in appropriate location.
* debian/maas-cluster-controller.postrm: Add and delete maas user.
* debian/maas-dhcp.postinst: Stop isc-dhcp-server not isc_dhcp_server.
* debian/maas-region-controller.postinst:
  - Always update passwords on upgrade. No longer check versioning. (LP: #1060094).
  - Add MAAS server to allowed mirror in squid-deb-proxy
  - Source dbconfig conf file for maas-region-controller on upgrade because
    it writes a new config file and no longer preservers the previous password.
* debian/maas-cluster-controller.maas-cluster-celery.upstart: Remove set{uid/gid}.
* debian/maas-region-controller.install: Install maas-import-squashfs
* Handle removal of non existant files (LP: #1059556):
  - debian/maintscript: Added to handle removal of conffiles.
  - debian/control: Add Pre-depends and bump debhelper version.
* update po files for the templates.
* debian/extras/99-maas: Install in usr/share/maas/conf and symlink to the
  appropriate etc dir.
* debian/maas-cluster-controller.config: Source debconf at the beginning of the
  script. (LP: #1063857)
* debian/patches/99-temporary-fix-constraints.patch: Fix constraints maaping
  when deploying with juju. Temporary until it gets merged upstream

[ Robie Basak ]
* Add maas-cluster-controller dependency on uuid-runtime, needed for uuidgen
  by postinst.

[ Scott Moser ]
* debian/maas-dhcp.{install,apparmor,postrm} install apparmor profile into
  /etc/apparmor.d/dhcpd.d (LP: #1049177), and update apparmor profile for
  /usr/sbin/dhcpd on install/remove
* get the ip address for the dhcp server in config

[ Diogo Matsubara ]
* Add initial tests to be run by autotests:
  - debian/control: XS-Testsuite: autopkgtest
  - debian/tests/control: Add
  - debian/tests/maas-package-test: Add
  - tests/maas-integration.py: Add

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    ]
33
33
 
34
34
 
 
35
import errno
35
36
import json
36
37
from os import (
37
38
    fstat,
43
44
    MAASDispatcher,
44
45
    MAASOAuth,
45
46
    )
46
 
from celeryconfig import DHCP_LEASES_FILE
 
47
from celery.app import app_or_default
47
48
from provisioningserver import cache
48
49
from provisioningserver.auth import (
49
50
    get_recorded_api_credentials,
50
51
    get_recorded_maas_url,
51
 
    get_recorded_nodegroup_name,
 
52
    get_recorded_nodegroup_uuid,
52
53
    )
53
54
from provisioningserver.dhcp.leases_parser import parse_leases
54
55
from provisioningserver.logging import task_logger
61
62
LEASES_CACHE_KEY = 'recorded_leases'
62
63
 
63
64
 
 
65
def get_leases_file():
 
66
    """Get the location of the DHCP leases file from the config."""
 
67
    return app_or_default().conf.DHCP_LEASES_FILE
 
68
 
 
69
 
64
70
def get_leases_timestamp():
65
 
    """Return the last modification timestamp of the DHCP leases file."""
66
 
    return stat(DHCP_LEASES_FILE).st_mtime
 
71
    """Return the last modification timestamp of the DHCP leases file.
 
72
 
 
73
    None will be returned if the DHCP lease file cannot be found.
 
74
    """
 
75
    try:
 
76
        return stat(get_leases_file()).st_mtime
 
77
    except OSError as exception:
 
78
        # Return None only if the exception is a "No such file or
 
79
        # directory" exception.
 
80
        if exception.errno == errno.ENOENT:
 
81
            return None
 
82
        else:
 
83
            raise
67
84
 
68
85
 
69
86
def parse_leases_file():
72
89
    :return: A tuple: (timestamp, leases).  The `timestamp` is the last
73
90
        modification time of the leases file, and `leases` is a dict
74
91
        mapping leased IP addresses to their associated MAC addresses.
 
92
        None will be returned if the DHCP lease file cannot be found.
75
93
    """
76
 
    with open(DHCP_LEASES_FILE, 'rb') as leases_file:
77
 
        contents = leases_file.read().decode('utf-8')
78
 
        return fstat(leases_file.fileno()).st_mtime, parse_leases(contents)
 
94
    try:
 
95
        with open(get_leases_file(), 'rb') as leases_file:
 
96
            contents = leases_file.read().decode('utf-8')
 
97
            return fstat(leases_file.fileno()).st_mtime, parse_leases(contents)
 
98
    except IOError as exception:
 
99
        # Return None only if the exception is a "No such file or
 
100
        # directory" exception.
 
101
        if exception.errno == errno.ENOENT:
 
102
            return None
 
103
        else:
 
104
            raise
79
105
 
80
106
 
81
107
def check_lease_changes():
88
114
 
89
115
    if get_leases_timestamp() == previous_leases_time:
90
116
        return None
91
 
    timestamp, leases = parse_leases_file()
92
 
    if leases == previous_leases:
93
 
        return None
 
117
    parse_result = parse_leases_file()
 
118
    if parse_result is not None:
 
119
        timestamp, leases = parse_result
 
120
        if leases == previous_leases:
 
121
            return None
 
122
        else:
 
123
            return timestamp, leases
94
124
    else:
95
 
        return timestamp, leases
 
125
        return None
96
126
 
97
127
 
98
128
def record_lease_state(last_change, leases):
118
148
    knowledge = {
119
149
        'maas_url': get_recorded_maas_url(),
120
150
        'api_credentials': get_recorded_api_credentials(),
121
 
        'nodegroup_name': get_recorded_nodegroup_name(),
 
151
        'nodegroup_uuid': get_recorded_nodegroup_uuid(),
122
152
    }
123
153
    if None in knowledge.values():
124
154
        # The MAAS server hasn't sent us enough information for us to do
130
160
            % ', '.join(list_missing_items(knowledge)))
131
161
        return
132
162
 
133
 
    api_path = 'api/1.0/nodegroups/%s/' % knowledge['nodegroup_name']
 
163
    api_path = 'api/1.0/nodegroups/%s/' % knowledge['nodegroup_uuid']
134
164
    oauth = MAASOAuth(*knowledge['api_credentials'])
135
165
    MAASClient(oauth, MAASDispatcher(), knowledge['maas_url']).post(
136
166
        api_path, 'update_leases', leases=json.dumps(leases))
150
180
    server restarts, or zone-file update commands getting lost on their
151
181
    way to the DNS server.
152
182
    """
153
 
    timestamp, leases = parse_leases_file()
154
 
    process_leases(timestamp, leases)
 
183
    parse_result = parse_leases_file()
 
184
    if parse_result:
 
185
        timestamp, leases = parse_result
 
186
        process_leases(timestamp, leases)
 
187
    else:
 
188
        task_logger.info(
 
189
            "The DHCP leases file does not exist.  This is only a problem if "
 
190
            "this cluster controller is managing its DHCP server.  If that's "
 
191
            "the case then you need to install the 'maas-dhcp' package on "
 
192
            "this cluster controller.")
155
193
 
156
194
 
157
195
def update_leases():