~zulcss/ubuntu/precise/quantum/trunk

« back to all changes in this revision

Viewing changes to quantum/agent/dhcp_agent.py

  • Committer: Chuck Short
  • Date: 2012-11-26 19:51:11 UTC
  • mfrom: (26.1.1 raring-proposed)
  • Revision ID: zulcss@ubuntu.com-20121126195111-jnz2cr4xi6whemw2
* New upstream release for the Ubuntu Cloud Archive.
* debian/patches/*: Refreshed for opening of Grizzly.
* New upstream release.
* debian/rules: FTFBS if there is missing binaries.
* debian/quantum-server.install: Add quantum-debug.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    License for the specific language governing permissions and limitations
16
16
#    under the License.
17
17
 
18
 
import logging
19
18
import os
20
 
import re
21
19
import socket
22
20
import sys
23
21
import uuid
25
23
import eventlet
26
24
import netaddr
27
25
 
28
 
from quantum.agent import rpc as agent_rpc
29
26
from quantum.agent.common import config
30
27
from quantum.agent.linux import dhcp
31
28
from quantum.agent.linux import interface
32
29
from quantum.agent.linux import ip_lib
33
 
from quantum.api.v2 import attributes
 
30
from quantum.agent import rpc as agent_rpc
34
31
from quantum.common import exceptions
35
32
from quantum.common import topics
 
33
from quantum import context
36
34
from quantum.openstack.common import cfg
37
 
from quantum.openstack.common import context
38
35
from quantum.openstack.common import importutils
39
36
from quantum.openstack.common import jsonutils
 
37
from quantum.openstack.common import log as logging
40
38
from quantum.openstack.common.rpc import proxy
 
39
from quantum.openstack.common import uuidutils
41
40
 
42
41
LOG = logging.getLogger(__name__)
43
42
NS_PREFIX = 'qdhcp-'
60
59
        self.cache = NetworkCache()
61
60
 
62
61
        self.dhcp_driver_cls = importutils.import_class(conf.dhcp_driver)
63
 
        ctx = context.RequestContext('quantum', 'quantum', is_admin=True)
 
62
        ctx = context.get_admin_context_without_session()
64
63
        self.plugin_rpc = DhcpPluginApi(topics.PLUGIN, ctx)
65
64
 
66
65
        self.device_manager = DeviceManager(self.conf, self.plugin_rpc)
500
499
        else:
501
500
            os.makedirs(dirname, 0755)
502
501
 
503
 
    def _validate_field(self, value, regex):
504
 
        """Validate value against a regular expression and return if valid."""
505
 
        match = re.match(regex, value)
506
 
 
507
 
        if match:
508
 
            return value
509
 
        raise ValueError(_("Value %s does not match regex: %s") %
510
 
                         (value, regex))
511
 
 
512
502
    def _handler(self, client_sock, client_addr):
513
503
        """Handle incoming lease relay stream connection.
514
504
 
521
511
            data = jsonutils.loads(msg)
522
512
            client_sock.close()
523
513
 
524
 
            network_id = self._validate_field(data['network_id'],
525
 
                                              attributes.UUID_PATTERN)
 
514
            network_id = data['network_id']
 
515
            if not uuidutils.is_uuid_like(network_id):
 
516
                raise ValueError(_("Network ID %s is not a valid UUID") %
 
517
                                 (network_id))
526
518
            ip_address = str(netaddr.IPAddress(data['ip_address']))
527
519
            lease_remaining = int(data['lease_remaining'])
528
520
            self.callback(network_id, ip_address, lease_remaining)
552
544
 
553
545
    mgr = DhcpAgent(cfg.CONF)
554
546
    mgr.run()
555
 
 
556
 
 
557
 
if __name__ == '__main__':
558
 
    main()