예제 #1
0
    def update_subnet(self, subnet_request):
        """Update subnet info in the IPAM driver.

        Do the update only if the specific change is supported by the backend
        """
        nsx_pool_id = nsx_db.get_nsx_ipam_pool_for_subnet(
            self._context.session, subnet_request.subnet_id)
        if not nsx_pool_id:
            # Unsupported (or pre-upgrade) network
            return self.default_ipam.update_subnet(
                subnet_request)

        # get the current pool data
        curr_subnet = self._subnet_class.load(
            subnet_request.subnet_id, nsx_pool_id,
            self._context, tenant_id=subnet_request.tenant_id).get_details()

        # check if the gateway changed
        gateway_changed = False
        if (str(subnet_request.gateway_ip) != str(curr_subnet.gateway_ip)):
            if not self.support_update_gateway:
                self._raise_update_not_supported()
            gateway_changed = True

        # check that the prefix / cidr / pools changed
        pools_changed = False
        if subnet_request.prefixlen != curr_subnet.prefixlen:
            if not self.support_update_pools:
                self._raise_update_not_supported()
            pools_changed = True

        if subnet_request.subnet_cidr[0] != curr_subnet.subnet_cidr[0]:
            if not self.support_update_pools:
                self._raise_update_not_supported()
            pools_changed = True

        if (len(subnet_request.allocation_pools) !=
            len(curr_subnet.allocation_pools)):
            if not self.support_update_pools:
                self._raise_update_not_supported()
            pools_changed = True

        if (len(subnet_request.allocation_pools) !=
            len(curr_subnet.allocation_pools)):
            if not self.support_update_pools:
                self._raise_update_not_supported()
            pools_changed = True
        else:
            for pool_ind in range(len(subnet_request.allocation_pools)):
                pool_req = subnet_request.allocation_pools[pool_ind]
                curr_pool = curr_subnet.allocation_pools[pool_ind]
                if (pool_req.first != curr_pool.first or
                    pool_req.last != curr_pool.last):
                    if not self.support_update_pools:
                        self._raise_update_not_supported()
                    pools_changed = True

        # update the relevant attributes at the backend pool
        if gateway_changed or pools_changed:
            self.update_backend_pool(nsx_pool_id, subnet_request)
예제 #2
0
    def get_subnet(self, subnet_id):
        """Retrieve an IPAM subnet."""
        nsx_pool_id = nsx_db.get_nsx_ipam_pool_for_subnet(
            self._context.session, subnet_id)
        if not nsx_pool_id:
            # Unsupported (or pre-upgrade) network
            return self.default_ipam.get_subnet(subnet_id)

        return self._subnet_class.load(subnet_id, nsx_pool_id, self._context)
예제 #3
0
    def get_subnet(self, subnet_id):
        """Retrieve an IPAM subnet."""
        nsx_pool_id = nsx_db.get_nsx_ipam_pool_for_subnet(
            self._context.session, subnet_id)
        if not nsx_pool_id:
            # Unsupported (or pre-upgrade) network
            return self.default_ipam.get_subnet(subnet_id)

        return self._subnet_class.load(subnet_id, nsx_pool_id, self._context)
예제 #4
0
    def remove_subnet(self, subnet_id):
        """Delete an IPAM subnet pool from backend & DB."""
        nsx_pool_id = nsx_db.get_nsx_ipam_pool_for_subnet(
            self._context.session, subnet_id)
        if not nsx_pool_id:
            # Unsupported (or pre-upgrade) network
            self.default_ipam.remove_subnet(subnet_id)
            return

        # Delete from backend
        self.delete_backend_pool(nsx_pool_id)

        # delete pool from DB
        nsx_db.del_nsx_ipam_subnet_pool(self._context.session, subnet_id,
                                        nsx_pool_id)
예제 #5
0
    def remove_subnet(self, subnet_id):
        """Delete an IPAM subnet pool from backend & DB."""
        nsx_pool_id = nsx_db.get_nsx_ipam_pool_for_subnet(
            self._context.session, subnet_id)
        if not nsx_pool_id:
            # Unsupported (or pre-upgrade) network
            self.default_ipam.remove_subnet(subnet_id)
            return

        # Delete from backend
        self.delete_backend_pool(nsx_pool_id)

        # delete pool from DB
        nsx_db.del_nsx_ipam_subnet_pool(self._context.session,
                                        subnet_id, nsx_pool_id)