Exemplo n.º 1
0
    def allocate_subnet(self, subnet_request):
        """Create an IPAMSubnet object for the provided request."""
        if not self._is_supported_net(subnet_request=subnet_request):
            # fallback to the neutron internal driver implementation
            return self.default_ipam.allocate_subnet(subnet_request)

        if self._subnetpool:
            subnet = super(NsxAbstractIpamDriver,
                           self).allocate_subnet(subnet_request)
            subnet_request = subnet.get_details()

        # SubnetRequest must be an instance of SpecificSubnet
        if not isinstance(subnet_request, ipam_req.SpecificSubnetRequest):
            raise ipam_exc.InvalidSubnetRequestType(
                subnet_type=type(subnet_request))

        # Add the pool to the NSX backend
        nsx_pool_id = self.allocate_backend_pool(subnet_request)

        # Add the pool to the DB
        nsx_db.add_nsx_ipam_subnet_pool(self._context.session,
                                        subnet_request.subnet_id, nsx_pool_id)
        # return the subnet object
        return self._subnet_class.load(subnet_request.subnet_id,
                                       nsx_pool_id,
                                       self._context,
                                       tenant_id=subnet_request.tenant_id)
Exemplo n.º 2
0
    def allocate_subnet(self, subnet_request):
        """Create an IPAM Subnet object for the provided cidr.

        :param cidr: subnet's CIDR
        :returns: a RomanaDbSubnet instance
        """
        LOG.debug("RomanaDbPool.allocate_subnet(%s)" % subnet_request)
        if not isinstance(subnet_request, ipam_req.SpecificSubnetRequest):
            raise ipam_exc.InvalidSubnetRequestType(
                subnet_type=type(subnet_request))
        return RomanaDbSubnet.create_from_subnet_request(
            subnet_request, self._context)
Exemplo n.º 3
0
    def allocate_subnet(self, rollback_list, subnet_request):
        """Create an IPAM subnet from the subnet request which contains cidr.

        Allocates a subnet to the Infoblox backend.
        :param subnet_request: instance of SubnetRequest child
        :returns: a InfobloxSubnet instance
        """
        # if subnetpool is defined, the request is AnySubnetRequest, so
        # we need to convert it to SpecificSubnetRequest calling
        # SubnetAllocator; however, calling this will not pass custom
        # parameters we defined so we need to get them back from the original
        # subnet_request.
        if self._subnetpool:
            orig_request = {
                'name': subnet_request.name,
                'network_id': subnet_request.network_id,
                'subnetpool_id': subnet_request.subnetpool_id,
                'enable_dhcp': subnet_request.enable_dhcp,
                'dns_nameservers': subnet_request.dns_nameservers
            }
            subnet = super(InfobloxPool, self).allocate_subnet(subnet_request)
            subnet_request = subnet.get_details()
            subnet_request.name = orig_request['name']
            subnet_request.network_id = orig_request['network_id']
            subnet_request.subnetpool_id = orig_request['subnetpool_id']
            subnet_request.enable_dhcp = orig_request['enable_dhcp']
            subnet_request.dns_nameservers = orig_request['dns_nameservers']

        # SubnetRequest must be SpecificSubnet at this point
        if not isinstance(subnet_request, ipam_req.SpecificSubnetRequest):
            raise ipam_exc.InvalidSubnetRequestType(
                subnet_type=type(subnet_request))

        neutron_subnet = self._build_subnet_from_request(subnet_request)
        ib_cxt = ib_context.InfobloxContext(self._context,
                                            self._context.user_id,
                                            None,
                                            neutron_subnet,
                                            self._grid_config,
                                            plugin=self._plugin)

        ipam_controller = ipam.IpamSyncController(ib_cxt)
        dns_controller = dns.DnsController(ib_cxt)

        ib_network = self._create_ib_network(rollback_list, ipam_controller)
        if ib_network:
            dns_controller.create_dns_zones(rollback_list)
            LOG.info("Created DNS zones.")

        return InfobloxSubnet(subnet_request, neutron_subnet, ib_network,
                              ib_cxt)
Exemplo n.º 4
0
    def allocate_subnet(self, subnet_request):
        """Create an IPAMSubnet object for the provided cidr.

        This method does not actually do any operation in the driver, given
        its simplified nature.

        :param cidr: subnet's CIDR
        :returns: a NeutronDbSubnet instance
        """
        if self._subnetpool:
            subnet = super(NeutronDbPool, self).allocate_subnet(subnet_request)
            subnet_request = subnet.get_details()

        # SubnetRequest must be an instance of SpecificSubnet
        if not isinstance(subnet_request, ipam_req.SpecificSubnetRequest):
            raise ipam_exc.InvalidSubnetRequestType(
                subnet_type=type(subnet_request))
        return NeutronDbSubnet.create_from_subnet_request(
            subnet_request, self._context)
Exemplo n.º 5
0
    def allocate_subnet(self, subnet_request):
        """Create an IPAMSubnet object for the provided cidr.

        This method does not actually do any operation in the driver, given
        its simplified nature.

        :param cidr: subnet's CIDR
        :returns: a NeutronDbSubnet instance
        """

        paramsBAM = getBCNConfig(BC_configFileName, "BAM")

        if self._subnetpool:
            tmpName = subnet_request.name

            subnet = super(NeutronDbPool, self).allocate_subnet(subnet_request)
            subnet_request = subnet.get_details()

            subnet_request.name = tmpName

        # SubnetRequest must be an instance of SpecificSubnet
        if not isinstance(subnet_request, ipam_req.SpecificSubnetRequest):
            raise ipam_exc.InvalidSubnetRequestType(
                subnet_type=type(subnet_request))

        if not hasattr(subnet_request, '_subnet_cidr') :
            subnet_request = ipam_req.SpecificSubnetRequest(
                            subnet_request._tenant_id,
                            subnet_request._subnet_id,
                            paramsBAM['bam_ipv4_private_network'],
                            allocation_pools=[netaddr.IPRange(paramsBAM['bam_ipv4_private_iprange_startip'], paramsBAM['bam_ipv4_private_iprange_endip'])],
                            gateway_ip=paramsBAM['bam_ipv4_private_iprange_gw']
                            )
                            
        #  BlueCat additions
        soap_client = _bam_login(paramsBAM)

        config = soap_client.service.getEntityByName(0, paramsBAM['bam_config_name'], 'Configuration')
        configID = config['id']
        LOG.info("BCN: Got configID %s" % (configID))

        LOG.info("BCN: Getting ParentBlockID Info ...")

        blockType = ""
        if subnet_request._subnet_cidr.version == 4:
            blockType = "IP4Block"
        else:
            blockType = "IP6Block"

        LOG.info("BCN: blockType : %s" % (blockType))

        # This needs polishing ...
        parentBlockId = ""        
        tenNet= netaddr.IPNetwork(paramsBAM['bam_ipv4_private_block'])

        if str(subnet_request._subnet_cidr.ip) in tenNet:
            parentBlockId = apiGetBlockID( configID, paramsBAM['bam_ipv4_private_block'], blockType)
        elif str(subnet_request._subnet_cidr.version) == "6":
            IP6GlobalUni = netaddr.IPNetwork(paramsBAM['bam_ipv6_public_block'])
            IP6UniqLocal = netaddr.IPNetwork(paramsBAM['bam_ipv6_private_block'])

            if subnet_request._subnet_cidr.ip in IP6UniqLocal:
                LOG.info("BCN: Getting "+paramsBAM['bam_ipv6_private_block'] +" blockID ...")
                parentBlockId = apiGetBlockID(configID, paramsBAM['bam_ipv6_private_block'], blockType)
            elif subnet_request._subnet_cidr.ip in IP6GlobalUni:
                    LOG.info("BCN: Getting " +paramsBAM['bam_ipv6_public_block'] +"blockID ...")
                    parentBlockId = apiGetBlockID(configID, paramsBAM['bam_ipv6_public_block'], blockType)
            else:
                    LOG.error("BCN: [Error] : Unsupported IPv6 Address Range: %s"  % (subnet_request._subnet_cidr.ip))
        else:
            LOG.info("BCN: IP4Block : " +paramsBAM['bam_ipv4_public_block'])
            parentBlockId = apiGetBlockID(configID, paramsBAM['bam_ipv4_public_block'], blockType)

        LOG.info("BCN: parentBlockId = %s"  % (parentBlockId))

        cidr = str(subnet_request._subnet_cidr.ip) +"/" +str(subnet_request._subnet_cidr.prefixlen)
        LOG.info("BCN: Creating Network %s in BAM  ..." % (cidr))

        bcNetID = addBCNetwork(parentBlockId, cidr, subnet_request.name, subnet_request._subnet_id, str(subnet_request._subnet_cidr.version))

        LOG.info("BCN: Network Added, NetworkId = %s, Name = %s UUID = %s\n" % (bcNetID, subnet_request.name, subnet_request._subnet_id))
        
        _bam_logout(paramsBAM, soap_client)

        return NeutronDbSubnet.create_from_subnet_request(subnet_request,
                                                          self._context)