~rackspace-ozone/rackspace-nova/development

« back to all changes in this revision

Viewing changes to nova/network/manager.py

  • Committer: paul at openstack
  • Date: 2011-09-26 18:57:03 UTC
  • mfrom: (1098.1.519 nova)
  • Revision ID: paul@openstack.org-20110926185703-ad3bthrj309itbrw
merging Diablo

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
import itertools
49
49
import math
50
50
import netaddr
 
51
import re
51
52
import socket
52
53
from eventlet import greenpool
53
54
 
110
111
                    'Network host to use for ip allocation in flat modes')
111
112
flags.DEFINE_bool('fake_call', False,
112
113
                  'If True, skip using the queue and make local calls')
 
114
flags.DEFINE_bool('force_dhcp_release', False,
 
115
                  'If True, send a dhcp release on instance termination')
113
116
 
114
117
 
115
118
class AddressAlreadyAllocated(exception.Error):
289
292
 
290
293
        self.db.floating_ip_fixed_ip_associate(context,
291
294
                                               floating_address,
292
 
                                               fixed_address)
 
295
                                               fixed_address,
 
296
                                               self.host)
293
297
        self.driver.bind_floating_ip(floating_address)
294
298
        self.driver.ensure_floating_forward(floating_address, fixed_address)
295
299
 
396
400
        self.compute_api.trigger_security_group_members_refresh(admin_context,
397
401
                                                                    group_ids)
398
402
 
 
403
    def get_vifs_by_instance(self, context, instance_id):
 
404
        vifs = self.db.virtual_interface_get_by_instance(context,
 
405
                                                         instance_id)
 
406
        return vifs
 
407
 
 
408
    def get_instance_uuids_by_ip_filter(self, context, filters):
 
409
        fixed_ip_filter = filters.get('fixed_ip')
 
410
        ip_filter = re.compile(str(filters.get('ip')))
 
411
        ipv6_filter = re.compile(str(filters.get('ip6')))
 
412
 
 
413
        # NOTE(jkoelker) Should probably figure out a better way to do
 
414
        #                this. But for now it "works", this could suck on
 
415
        #                large installs.
 
416
 
 
417
        vifs = self.db.virtual_interface_get_all(context)
 
418
        results = []
 
419
 
 
420
        for vif in vifs:
 
421
            if vif['instance_id'] is None:
 
422
                continue
 
423
 
 
424
            fixed_ipv6 = vif.get('fixed_ipv6')
 
425
            if fixed_ipv6 and ipv6_filter.match(fixed_ipv6):
 
426
                # NOTE(jkoelker) Will need to update for the UUID flip
 
427
                results.append({'instance_id': vif['instance_id'],
 
428
                                'ip': fixed_ipv6})
 
429
 
 
430
            for fixed_ip in vif['fixed_ips']:
 
431
                if not fixed_ip or not fixed_ip['address']:
 
432
                    continue
 
433
                if fixed_ip['address'] == fixed_ip_filter:
 
434
                    results.append({'instance_id': vif['instance_id'],
 
435
                                    'ip': fixed_ip['address']})
 
436
                    continue
 
437
                if ip_filter.match(fixed_ip['address']):
 
438
                    results.append({'instance_id': vif['instance_id'],
 
439
                                    'ip': fixed_ip['address']})
 
440
                    continue
 
441
                for floating_ip in fixed_ip.get('floating_ips', []):
 
442
                    if not floating_ip or not floating_ip['address']:
 
443
                        continue
 
444
                    if ip_filter.match(floating_ip['address']):
 
445
                        results.append({'instance_id': vif['instance_id'],
 
446
                                        'ip': floating_ip['address']})
 
447
                        continue
 
448
 
 
449
        # NOTE(jkoelker) Until we switch over to instance_uuid ;)
 
450
        ids = [res['instance_id'] for res in results]
 
451
        uuid_map = self.db.instance_get_id_to_uuid_mapping(context, ids)
 
452
        for res in results:
 
453
            res['instance_uuid'] = uuid_map.get(res['instance_id'])
 
454
        return results
 
455
 
399
456
    def _get_networks_for_instance(self, context, instance_id, project_id,
400
457
                                   requested_networks=None):
401
458
        """Determine & return which networks an instance should connect to."""
689
746
        instance_id = instance_ref['id']
690
747
        self._do_trigger_security_group_members_refresh_for_instance(
691
748
                                                                   instance_id)
 
749
        if FLAGS.force_dhcp_release:
 
750
            dev = self.driver.get_dev(fixed_ip_ref['network'])
 
751
            vif = self.db.virtual_interface_get_by_instance_and_network(
 
752
                    context, instance_ref['id'], fixed_ip_ref['network']['id'])
 
753
            self.driver.release_dhcp(dev, address, vif['address'])
692
754
 
693
755
    def lease_fixed_ip(self, context, address):
694
756
        """Called by dhcp-bridge when ip is leased."""