Example #1
0
    def _assure_subnet_snats(self, assure_bigips, service, subnetinfo):
        # Ensure snat for subnet exists on bigips
        tenant_id = service['loadbalancer']['tenant_id']
        subnet = subnetinfo['subnet']
        snats_per_subnet = self.conf.f5_snat_addresses_per_subnet
        lb_id = service['loadbalancer']['id']

        assure_bigips = \
            [bigip for bigip in assure_bigips
                if tenant_id not in bigip.assured_tenant_snat_subnets or
                subnet['id'] not in
                bigip.assured_tenant_snat_subnets[tenant_id]]

        LOG.debug("_assure_subnet_snats: getting snat addrs for: %s" %
                  subnet['id'])
        if len(assure_bigips):
            snat_addrs = self.bigip_snat_manager.get_snat_addrs(
                subnetinfo, tenant_id, snats_per_subnet, lb_id)

            if len(snat_addrs) != snats_per_subnet:
                raise f5_ex.SNATCreationException(
                    "Unable to satisfy request to allocate %d "
                    "snats.  Actual SNAT count: %d SNATs" %
                    (snats_per_subnet, len(snat_addrs)))
            for assure_bigip in assure_bigips:
                self.bigip_snat_manager.assure_bigip_snats(
                    assure_bigip, subnetinfo, snat_addrs, tenant_id)
Example #2
0
    def _assure_bigip_snats(self, bigip, subnetinfo, snat_info, tenant_id):
        # Configure the ip addresses for snat
        network = subnetinfo['network']
        subnet = subnetinfo['subnet']

        if tenant_id not in bigip.assured_tenant_snat_subnets:
            bigip.assured_tenant_snat_subnets[tenant_id] = []
        if subnet['id'] in bigip.assured_tenant_snat_subnets[tenant_id]:
            return

        snat_name = self._get_snat_name(subnet, tenant_id)
        for i, snat_address in enumerate(snat_info['addrs']):
            ip_address = snat_address + \
                '%' + str(network['route_domain_id'])
            index_snat_name = snat_name + "_" + str(i)

            snat_traffic_group = self._get_snat_traffic_group(tenant_id)
            # snat.create() did  the following in LBaaSv1
            # Creates the SNAT
            #   * if the traffic_group is empty it uses a const
            #     but this seems like it should be an error see message
            #     in this file about this
            # Create a SNAT Pool if a name was passed in
            #   * Add the snat to the list of members
            model = {
                "name": index_snat_name,
                "partition": snat_info['network_folder'],
                "address": ip_address,
                "trafficGroup": snat_traffic_group
            }
            try:
                if not self.snat_translation_manager.exists(
                        bigip,
                        name=index_snat_name,
                        partition=snat_info['network_folder']):
                    self.snat_translation_manager.create(bigip, model)
            except Exception as err:
                LOG.exception(err)
                raise f5_ex.SNATCreationException(
                    "Error creating snat translation manager %s" %
                    index_snat_name)

            model = {
                "name": snat_info['pool_name'],
                "partition": snat_info['network_folder'],
            }
            snatpool_member = ('/' + model["partition"] + '/' +
                               index_snat_name)
            model["members"] = [snatpool_member]
            try:
                if not self.snatpool_manager.exists(
                        bigip,
                        name=model['name'],
                        partition=model['partition']):
                    LOG.debug("Creating SNAT pool: %s" % model)
                    self.snatpool_manager.create(bigip, model)
                else:
                    LOG.debug("Updating SNAT pool")
                    snatpool = self.snatpool_manager.load(
                        bigip,
                        name=model["name"],
                        partition=model["partition"]
                    )
                    snatpool.members.append(snatpool_member)
                    snatpool.modify(members=snatpool.members)

            except Exception as err:
                LOG.error("Create SNAT pool failed %s" % err.message)
                raise f5_ex.SNATCreationException(
                    "Failed to create SNAT pool")

            if self.l3_binding:
                self.l3_binding.bind_address(subnet_id=subnet['id'],
                                             ip_address=ip_address)

        bigip.assured_tenant_snat_subnets[tenant_id].append(subnet['id'])