def execute(self, member, nat_flavor=None, nat_pool=None):
        if nat_flavor is None:
            return

        if nat_pool is None:
            try:
                addr_list = a10_utils.get_natpool_addr_list(nat_flavor)
                if not CONF.vthunder.slb_no_snat_support:
                    amphorae = a10_task_utils.attribute_search(
                        member, 'amphorae')
                else:
                    amphorae = None
                port = self.network_driver.reserve_subnet_addresses(
                    member.subnet_id, addr_list, amphorae)
                LOG.debug(
                    "Successfully allocated addresses for nat pool %s on port %s",
                    nat_flavor['pool_name'], port.id)
                return port
            except neutron_exceptions.InvalidIpForSubnetClient as e:
                # The NAT pool addresses is not in member subnet, a10-octavia will allow it but
                # will not able to reserve address for it. (since we don't know the subnet)
                LOG.exception(
                    "Failed to reserve addresses in NAT pool %s from subnet %s: %s",
                    nat_flavor['pool_name'], member.subnet_id, str(e))
            except Exception as e:
                LOG.exception(
                    "Failed to reserve addresses in NAT pool %s from subnet %s",
                    nat_flavor['pool_name'], member.subnet_id)
                raise e
        return
    def execute(self, vthunder, vrid_list, subnet, use_device_flavor,
                lb_count_subnet, member_count, lb_count_thunder,
                member_count_thunder, lb_resource):
        vrid = None
        vrid_floating_ip_list = []
        existing_fips = []
        if use_device_flavor:
            resource_count = lb_count_thunder + member_count_thunder
        else:
            resource_count = lb_count_subnet + member_count
        if resource_count <= 1 and vthunder:
            for vr in vrid_list:
                try:
                    vrid_summary = self.axapi_client.vrrpa.get(vr.vrid)
                except Exception as e:
                    vrid_summary = {}
                    LOG.exception(
                        "Failed to get existing VRID summary due to: %s",
                        str(e))

                if vrid_summary and 'floating-ip' in vrid_summary['vrid']:
                    vrid_fip = vrid_summary['vrid']['floating-ip']
                    if vthunder.partition_name != 'shared':
                        for i in range(len(vrid_fip['ip-address-part-cfg'])):
                            existing_fips.append(
                                vrid_fip['ip-address-part-cfg'][i]
                                ['ip-address-partition'])
                    else:
                        for i in range(len(vrid_fip['ip-address-cfg'])):
                            existing_fips.append(
                                vrid_fip['ip-address-cfg'][i]['ip-address'])
                if vr.subnet_id == subnet.id:
                    vrid = vr
                elif vr.vrid_floating_ip in existing_fips:
                    vrid_floating_ip_list.append(vr.vrid_floating_ip)
            if vrid:
                try:
                    amphorae = a10_task_utils.attribute_search(
                        lb_resource, 'amphorae')
                    self.network_driver.deallocate_vrid_fip(
                        vrid, subnet, amphorae)
                    if not vthunder.partition_name or vthunder.partition_name == 'shared':
                        self.axapi_client.vrrpa.update(
                            vrid.vrid, floating_ips=vrid_floating_ip_list)
                    else:
                        self.axapi_client.vrrpa.update(
                            vrid.vrid,
                            floating_ips=vrid_floating_ip_list,
                            is_partition=True)
                    LOG.info("VRID floating IP: %s deleted",
                             vrid.vrid_floating_ip)
                    return vrid, True
                except Exception as e:
                    LOG.exception("Failed to delete vrid floating ip : %s",
                                  str(e))
                    raise e
        return None, False
 def execute(self, lb_resource):
     flavor_id = a10_task_utils.attribute_search(lb_resource, 'flavor_id')
     if flavor_id:
         flavor = self.flavor_repo.get(db_apis.get_session(), id=flavor_id)
         if flavor and flavor.flavor_profile_id:
             flavor_profile = self.flavor_profile_repo.get(
                 db_apis.get_session(), id=flavor.flavor_profile_id)
             flavor_data = json.loads(flavor_profile.flavor_data)
             return self._format_keys(flavor_data)
    def execute(self, vthunder, vrid_list, subnet_list, lb_resource):
        try:
            if subnet_list and vthunder and vrid_list:
                amphorae = a10_task_utils.attribute_search(
                    lb_resource, 'amphorae')
                vrids = []
                vrid_floating_ip_list = []
                existing_fips = []
                for vrid in vrid_list:
                    try:
                        vrid_summary = self.axapi_client.vrrpa.get(vrid.vrid)
                    except Exception as e:
                        vrid_summary = {}
                        LOG.exception(
                            "Failed to get existing VRID summary due to: %s",
                            str(e))

                    if vrid_summary and 'floating-ip' in vrid_summary['vrid']:
                        vrid_fip = vrid_summary['vrid']['floating-ip']
                        if vthunder.partition_name != 'shared':
                            for i in range(len(
                                    vrid_fip['ip-address-part-cfg'])):
                                existing_fips.append(
                                    vrid_fip['ip-address-part-cfg'][i]
                                    ['ip-address-partition'])
                        else:
                            for i in range(len(vrid_fip['ip-address-cfg'])):
                                existing_fips.append(vrid_fip['ip-address-cfg']
                                                     [i]['ip-address'])

                    subnet_matched = list(
                        filter(lambda x: x == vrid.subnet_id, subnet_list))
                    if subnet_matched:
                        vrids.append(vrid)
                        subnet = self.network_driver.get_subnet(vrid.subnet_id)
                        self.network_driver.deallocate_vrid_fip(
                            vrid, subnet, amphorae)
                    elif vrid.vrid_floating_ip in existing_fips:
                        vrid_floating_ip_list.append(vrid.vrid_floating_ip)
                if not vthunder.partition_name or vthunder.partition_name == 'shared':
                    self.axapi_client.vrrpa.update(
                        vrid.vrid, floating_ips=vrid_floating_ip_list)
                else:
                    self.axapi_client.vrrpa.update(
                        vrid.vrid,
                        floating_ips=vrid_floating_ip_list,
                        is_partition=True)
                LOG.info("VRID floating IP: %s deleted", vrid_floating_ip_list)
                return vrids
        except Exception as e:
            LOG.exception("Failed to delete vrid floating ip : %s", str(e))
            raise e
示例#5
0
    def execute(self, member, nat_flavor=None, nat_pool=None):
        if nat_flavor is None or nat_pool is None:
            return

        if nat_pool.member_ref_count == 1:
            try:
                self.network_driver.delete_port(nat_pool.port_id)
                if not CONF.vthunder.slb_no_snat_support:
                    addr_list = a10_utils.get_natpool_addr_list(nat_flavor)
                    amphorae = a10_task_utils.attribute_search(member, 'amphorae')
                    if amphorae is not None:
                        self.network_driver.release_subnet_addresses(
                            member.subnet_id, addr_list, amphorae)
            except Exception as e:
                LOG.exception("Failed to release addresses in NAT pool %s from subnet %s",
                              nat_flavor['pool_name'], member.subnet_id)
                raise e
示例#6
0
    def _replace_vrid_port(self, vrid, subnet, lb_resource, conf_floating_ip=None):
        if vrid.vrid_port_id:
            self._delete_vrid_port(vrid.vrid_port_id)

        try:
            amphorae = a10_task_utils.attribute_search(lb_resource, 'amphorae')
            fip_obj = self.network_driver.allocate_vrid_fip(
                vrid, subnet.network_id, amphorae,
                fixed_ip=conf_floating_ip)
            vrid.vrid_port_id = fip_obj.id
            vrid.vrid_floating_ip = fip_obj.fixed_ips[0].ip_address
            self.added_fip_ports.append(fip_obj)
        except Exception as e:
            msg = "Failed to create neutron port for SLB resource: %s "
            if conf_floating_ip:
                msg += "with floating IP {}".format(conf_floating_ip)
            LOG.error(msg, lb_resource.id)
            raise e
        return vrid