~midokura/nova/network-service

« back to all changes in this revision

Viewing changes to nova/network/flat_vlan/network.py

  • Committer: Ryu Ishimoto
  • Date: 2011-04-16 17:43:56 UTC
  • Revision ID: ryu@midokura.jp-20110416174356-29f4nel2tx64e9ax
Renamed virtual_nics.py to ethernet_cards.py for openstack API controller module.  Fixed a few bugs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import collections
19
19
import datetime
20
 
import os
21
20
 
22
21
from nova import context
 
22
from nova import exception
23
23
from nova import log as logging
24
24
from nova import manager as nova_manager
25
25
from nova import rpc
106
106
                                                               self.host,
107
107
                                                               time)
108
108
            if num:
109
 
                LOG.debug(_("Dissassociated %s stale fixed ip(s)"), num)
 
109
                LOG.debug("Dissassociated %s stale fixed ip(s)", num)
110
110
 
111
111
    def _set_vlan_host(self, context, network_id):
112
112
        """Sets up VLAN networking service host.
265
265
           mac: MAC address to lease the IP address against.
266
266
           address: IP address to lease.
267
267
        """
268
 
        LOG.debug(_("Leasing IP %s"), address, context=context)
 
268
        LOG.debug("Leasing IP %s", address, context=context)
269
269
        fixed_ip_ref = self.db.fixed_ip_get_by_address(context, address)
270
270
        ethernet_card = fixed_ip_ref['ethernet_card']
271
271
 
328
328
           mac: MAC address to release the IP against.
329
329
           address: IP address to release
330
330
        """
331
 
        LOG.debug(_("Releasing IP %s"), address, context=context)
 
331
        LOG.debug("Releasing IP %s", address, context=context)
332
332
        fixed_ip_ref = self.db.fixed_ip_get_by_address(context, address)
333
333
        ethernet_card = fixed_ip_ref['ethernet_card']
334
334
        instance = nova_db_api.instance_get_by_virtual_nic(context,
335
335
                                                           ethernet_card['id'])
336
336
        if not instance:
337
 
            raise exception.Error(_("IP %s released that isn't associated") %
 
337
            raise exception.Error("IP %s released that isn't associated" %
338
338
                                  address)
339
339
 
340
340
        if nova_db_api.is_user_context(context):
342
342
            nova_db_api.authorize_project_context(context, instance.project_id)
343
343
 
344
344
        if ethernet_card['mac_address'] != mac:
345
 
            raise exception.Error(_("IP %(address)s leased to bad"
346
 
                    " mac %s vs %s") % (ethernet_card['mac_address'], mac))
 
345
            raise exception.Error("IP %(address)s leased to bad"
 
346
                    " mac %s vs %s" % (ethernet_card['mac_address'], mac))
347
347
 
348
348
        if not fixed_ip_ref['leased']:
349
 
            LOG.warn(_("IP %s released that was not leased"), address,
 
349
            LOG.warn("IP %s released that was not leased", address,
350
350
                     context=context)
351
351
        self.db.fixed_ip_update(context,
352
352
                                fixed_ip_ref['address'],
357
357
            #             means there will stale entries in the conf file
358
358
            #             the code below will update the file if necessary
359
359
            if FLAGS.net_flat_vlan_update_dhcp_on_disassociate:
360
 
                network_ref = fixed_ip['network']
 
360
                network_ref = fixed_ip_ref['network']
361
361
                hosts = self._get_dhcp_hosts(context, network_ref['id'])
362
362
                self.dhcp_driver.update_dhcp(network_ref['bridge'],
363
363
                                             network_ref['gateway'],
407
407
        """Get the list of hosts for an interface."""
408
408
        ctxt = context.get_admin_context()
409
409
        if FLAGS.fake_rabbit:
410
 
            LOG_DHCP.debug(_("initializing leases"))
 
410
            LOG_DHCP.debug("initializing leases")
411
411
            return NetworkService().get_dhcp_host_leases(ctxt, interface)
412
412
        else:
413
413
            return rpc.cast(ctxt,
421
421
        """Set the IP that was assigned by the DHCP server."""
422
422
        ctxt = context.get_admin_context()
423
423
        if FLAGS.fake_rabbit:
424
 
            LOG_DHCP.debug(_("leasing ip"))
 
424
            LOG_DHCP.debug("leasing ip")
425
425
            return NetworkService().lease_fixed_ip(ctxt, mac, ip_address)
426
426
        else:
427
427
            rpc.cast(ctxt,
434
434
    @classmethod
435
435
    def old_lease(cls, mac, ip_address, hostname, interface):
436
436
        """Update just as add lease."""
437
 
        LOG_DHCP.debug(_("Adopted old lease or got a change of mac/hostname"))
 
437
        LOG_DHCP.debug("Adopted old lease or got a change of mac/hostname")
438
438
        cls.add_lease(mac, ip_address, hostname, interface)
439
439
 
440
440
    @classmethod
442
442
        """Called when a lease expires."""
443
443
        ctxt = context.get_admin_context()
444
444
        if FLAGS.fake_rabbit:
445
 
            LOG_DHCP.debug(_("releasing ip"))
 
445
            LOG_DHCP.debug("releasing ip")
446
446
            NetworkService().release_fixed_ip(ctxt, mac, ip_address)
447
447
        else:
448
448
            rpc.cast(ctxt,