~corey.bryant/ubuntu/trusty/neutron/lp1318721

« back to all changes in this revision

Viewing changes to neutron/agent/linux/dhcp.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Corey Bryant
  • Date: 2014-10-06 09:15:06 UTC
  • mfrom: (28.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20141006091506-cesvev43moce4y74
Tags: 1:2014.1.3-0ubuntu1
[ Corey Bryant ]
* Resynchronize with stable/icehouse (4a0210e) (LP: #1377136):
  - [3a30d19] Deletes floating ip related connection states
  - [dd4b77f] Forbid regular users to reset admin-only attrs to default values
  - [dc2c893] Add delete operations for the ODL MechanismDriver
  - [b51e2c7] Add missing ml2 plugin to migration 1fcfc149aca4
  - [a17a500] Don't convert numeric protocol values to int
  - [3a85946] NSX: Optionally not enforce nat rule match length check
  - [645f984] Don't spawn metadata-proxy for non-isolated nets
  - [b464d89] Big Switch: Check for 'id' in port before lookup
  - [3116ffa] use TRUE in SQL for boolean var
  - [3520e66] call security_groups_member_updated in port_update
  - [50e1534] Don't allow user to set firewall rule with port and no protocol
  - [0061533] BSN: Add context to backend request for debugging
  - [6de6d61] Improve ODL ML2 Exception Handling
  - [2a4153d] Send network name and uuid to subnet create
  - [b5e3c9a] BSN: Allow concurrent reads to consistency DB
  - [b201432] Big Switch: Retry on 503 errors from backend
  - [f6c47ee] NSX: log request body to NSX as debug
  - [97d622a] Fix metadata agent's auth info caching
  - [255df45] NSX: Correct allowed_address_pair return value on create_port
  - [5bea041] Neutron should not use the neutronclient utils module for import_class
  - [d5314e2] Cisco N1kv plugin to send subtype on network profile creation
  - [f32d1ce] Pass object to policy when finding fields to strip
  - [8b5f6be] Call policy.init() once per API request
  - [9a6d811] Perform policy checks only once on list responses
  - [c48db90] Datacenter moid should not be tuple
  - [161d465] Allow unsharing a network used as gateway/floatingip
  - [9574a2f] Add support for router scheduling in Cisco N1kv Plugin
  - [6f54565] Fix func job hook script permission problems
  - [ea43103] Add hook scripts for the functional infra job
  - [8161cb7] Fixes Hyper-V agent issue on Hyper-V 2008 R2
  - [8e99cfd] Fixes Hyper-V issue due to ML2 RPC versioning
  - [69f9121] Ensure ip6tables are used only if ipv6 is enabled in kernel
  - [399b809] Remove explicit dependency on amqplib
  - [a872143] Clear entries in Cisco N1KV specific tables on rollback
  - [ad82fad] Verify ML2 type driver exists before calling del
  - [af2cc98] Big Switch: Only update hash header on success
  - [b1e5eec] Ignore variable column widths in ovsdb functional tests
  - [4a0210e] VMWare: don't notify on disassociate_floatingips()

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
 
149
149
        raise NotImplementedError
150
150
 
 
151
    @classmethod
 
152
    def get_isolated_subnets(cls, network):
 
153
        """Returns a dict indicating whether or not a subnet is isolated."""
 
154
        raise NotImplementedError
 
155
 
 
156
    @classmethod
 
157
    def should_enable_metadata(cls, conf, network):
 
158
        """True if the metadata-proxy should be enabled for the network."""
 
159
        raise NotImplementedError
 
160
 
151
161
 
152
162
class DhcpLocalProcess(DhcpBase):
153
163
    PORTS = []
514
524
 
515
525
        options = []
516
526
 
 
527
        isolated_subnets = self.get_isolated_subnets(self.network)
517
528
        dhcp_ips = collections.defaultdict(list)
518
529
        subnet_idx_map = {}
519
530
        for i, subnet in enumerate(self.network.subnets):
538
549
 
539
550
            # Add host routes for isolated network segments
540
551
 
541
 
            if self._enable_metadata(subnet):
 
552
            if (isolated_subnets[subnet.id] and
 
553
                    self.conf.enable_isolated_metadata and
 
554
                    subnet.ip_version == 4):
542
555
                subnet_dhcp_ip = subnet_to_interface_ip[subnet.id]
543
556
                host_routes.append(
544
557
                    '%s/32,%s' % (METADATA_DEFAULT_IP, subnet_dhcp_ip)
623
636
 
624
637
        return ','.join((set_tag + tag, '%s' % option) + args)
625
638
 
626
 
    def _enable_metadata(self, subnet):
627
 
        '''Determine if the metadata route will be pushed to hosts on subnet.
628
 
 
629
 
        If subnet has a Neutron router attached, we want the hosts to get
630
 
        metadata from the router's proxy via their default route instead.
631
 
        '''
632
 
        if self.conf.enable_isolated_metadata and subnet.ip_version == 4:
633
 
            if subnet.gateway_ip is None:
634
 
                return True
635
 
            else:
636
 
                for port in self.network.ports:
637
 
                    if port.device_owner == constants.DEVICE_OWNER_ROUTER_INTF:
638
 
                        for alloc in port.fixed_ips:
639
 
                            if alloc.subnet_id == subnet.id:
640
 
                                return False
641
 
                return True
642
 
        else:
 
639
    @classmethod
 
640
    def get_isolated_subnets(cls, network):
 
641
        """Returns a dict indicating whether or not a subnet is isolated
 
642
 
 
643
        A subnet is considered non-isolated if there is a port connected to
 
644
        the subnet, and the port's ip address matches that of the subnet's
 
645
        gateway. The port must be owned by a nuetron router.
 
646
        """
 
647
        isolated_subnets = collections.defaultdict(lambda: True)
 
648
        subnets = dict((subnet.id, subnet) for subnet in network.subnets)
 
649
 
 
650
        for port in network.ports:
 
651
            if port.device_owner != constants.DEVICE_OWNER_ROUTER_INTF:
 
652
                continue
 
653
            for alloc in port.fixed_ips:
 
654
                if subnets[alloc.subnet_id].gateway_ip == alloc.ip_address:
 
655
                    isolated_subnets[alloc.subnet_id] = False
 
656
 
 
657
        return isolated_subnets
 
658
 
 
659
    @classmethod
 
660
    def should_enable_metadata(cls, conf, network):
 
661
        """True if there exists a subnet for which a metadata proxy is needed
 
662
        """
 
663
        if not conf.use_namespaces or not conf.enable_isolated_metadata:
643
664
            return False
644
665
 
 
666
        isolated_subnets = cls.get_isolated_subnets(network)
 
667
        return any(isolated_subnets[subnet.id] for subnet in network.subnets)
 
668
 
645
669
    @classmethod
646
670
    def lease_update(cls):
647
671
        network_id = os.environ.get(cls.NEUTRON_NETWORK_ID_KEY)