~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to nova/network/manager.py

  • Committer: Tushar Patil
  • Date: 2011-09-08 18:47:56 UTC
  • mfrom: (1532 nova)
  • mto: This revision was merged to the branch mainline in revision 1535.
  • Revision ID: tushar.vitthal.patil@gmail.com-20110908184756-166gwihyeokz4v3b
Merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
                    'Bridge for simple network instances')
75
75
flags.DEFINE_string('flat_network_dns', '8.8.4.4',
76
76
                    'Dns for simple network')
77
 
flags.DEFINE_bool('flat_injected', True,
 
77
flags.DEFINE_bool('flat_injected', False,
78
78
                  'Whether to attempt to inject network setup into guest')
79
79
flags.DEFINE_string('flat_interface', None,
80
80
                    'FlatDhcp will bridge into this interface if set')
448
448
        try:
449
449
            fixed_ips = kwargs.get('fixed_ips') or \
450
450
                  self.db.fixed_ip_get_by_instance(context, instance_id)
451
 
        except exceptions.FixedIpNotFoundForInstance:
 
451
        except exception.FixedIpNotFoundForInstance:
452
452
            fixed_ips = []
453
453
        LOG.debug(_("network deallocation for instance |%s|"), instance_id,
454
454
                                                               context=context)
484
484
        for vif in vifs:
485
485
            network = vif['network']
486
486
 
 
487
            if network is None:
 
488
                continue
 
489
 
487
490
            # determine which of the instance's IPs belong to this network
488
491
            network_IPs = [fixed_ip['address'] for fixed_ip in fixed_ips if
489
492
                           fixed_ip['network_id'] == network['id']]
546
549
    def _allocate_mac_addresses(self, context, instance_id, networks):
547
550
        """Generates mac addresses and creates vif rows in db for them."""
548
551
        for network in networks:
549
 
            vif = {'address': self.generate_mac_address(),
 
552
            self.add_virtual_interface(context, instance_id, network['id'])
 
553
 
 
554
    def add_virtual_interface(self, context, instance_id, network_id):
 
555
        vif = {'address': self.generate_mac_address(),
550
556
                   'instance_id': instance_id,
551
 
                   'network_id': network['id'],
 
557
                   'network_id': network_id,
552
558
                   'uuid': str(utils.gen_uuid())}
553
 
            # try FLAG times to create a vif record with a unique mac_address
554
 
            for i in range(FLAGS.create_unique_mac_address_attempts):
555
 
                try:
556
 
                    self.db.virtual_interface_create(context, vif)
557
 
                    break
558
 
                except exception.VirtualInterfaceCreateException:
559
 
                    vif['address'] = self.generate_mac_address()
560
 
            else:
561
 
                self.db.virtual_interface_delete_by_instance(context,
 
559
        # try FLAG times to create a vif record with a unique mac_address
 
560
        for _ in xrange(FLAGS.create_unique_mac_address_attempts):
 
561
            try:
 
562
                return self.db.virtual_interface_create(context, vif)
 
563
            except exception.VirtualInterfaceCreateException:
 
564
                vif['address'] = self.generate_mac_address()
 
565
        else:
 
566
            self.db.virtual_interface_delete_by_instance(context,
562
567
                                                             instance_id)
563
 
                raise exception.VirtualInterfaceMacAddressException()
 
568
            raise exception.VirtualInterfaceMacAddressException()
564
569
 
565
570
    def generate_mac_address(self):
566
571
        """Generate an Ethernet MAC address."""
789
794
                self._create_fixed_ips(context, network['id'])
790
795
        return networks
791
796
 
 
797
    def delete_network(self, context, fixed_range, require_disassociated=True):
 
798
 
 
799
        network = db.network_get_by_cidr(context, fixed_range)
 
800
 
 
801
        if require_disassociated and network.project_id is not None:
 
802
            raise ValueError(_('Network must be disassociated from project %s'
 
803
                               ' before delete' % network.project_id))
 
804
        db.network_delete_safe(context, network.id)
 
805
 
792
806
    @property
793
807
    def _bottom_reserved_ips(self):  # pylint: disable=R0201
794
808
        """Number of reserved ips at the bottom of the range."""