Пример #1
0
    def create(self, context, lb):
        edge_id = lb_common.get_lbaas_edge_id_for_subnet(
            context, self.core_plugin, lb.vip_subnet_id, lb.tenant_id)

        if not edge_id:
            msg = _(
                'No suitable Edge found for subnet %s') % lb.vip_subnet_id
            raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)

        try:
            if not nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge(
                    context.session, edge_id):
                lb_common.enable_edge_acceleration(self.vcns, edge_id)

            lb_common.add_vip_as_secondary_ip(self.vcns, edge_id,
                                              lb.vip_address)
            edge_fw_rule_id = lb_common.add_vip_fw_rule(
                self.vcns, edge_id, lb.id, lb.vip_address)

            nsxv_db.add_nsxv_lbaas_loadbalancer_binding(
                context.session, lb.id, edge_id, edge_fw_rule_id,
                lb.vip_address)
            self.lbv2_driver.load_balancer.successful_completion(context, lb)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                self.lbv2_driver.load_balancer.failed_completion(context, lb)
                LOG.error(_LE('Failed to create pool %s'), lb.id)
Пример #2
0
    def create(self, context, lb):
        edge_id = lb_common.get_lbaas_edge_id_for_subnet(
            context, self.core_plugin, lb.vip_subnet_id, lb.tenant_id)

        if not edge_id:
            msg = _(
                'No suitable Edge found for subnet %s') % lb.vip_subnet_id
            raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)

        try:
            if not nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge(
                    context.session, edge_id):
                lb_common.enable_edge_acceleration(self.vcns, edge_id)

            lb_common.add_vip_as_secondary_ip(self.vcns, edge_id,
                                              lb.vip_address)
            edge_fw_rule_id = lb_common.add_vip_fw_rule(
                self.vcns, edge_id, lb.id, lb.vip_address)

            nsxv_db.add_nsxv_lbaas_loadbalancer_binding(
                context.session, lb.id, edge_id, edge_fw_rule_id,
                lb.vip_address)
            self.lbv2_driver.load_balancer.successful_completion(context, lb)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                self.lbv2_driver.load_balancer.failed_completion(context, lb)
                LOG.error(_LE('Failed to create pool %s'), lb.id)
Пример #3
0
def router_binding_obj_exist(context, binding, net_ids, rtr_ids, plr_tlr_ids):
    """Check if the object responsible for the router binding entry exists

    Check if the relevant router/network/loadbalancer exists in the neutron DB
    """
    router_id = binding.router_id

    if router_id.startswith(vcns_const.BACKUP_ROUTER_PREFIX):
        # no neutron object that should match backup edges
        return True

    if router_id.startswith(vcns_const.DHCP_EDGE_PREFIX):
        # should have a network starting with this id
        # get the id. and look for a network with this id
        net_id_prefix = _get_obj_id_from_binding(router_id,
                                                 vcns_const.DHCP_EDGE_PREFIX)
        if _is_id_prefix_in_list(net_id_prefix, net_ids):
            return True
        else:
            LOG.warning("Network for binding entry %s not found", router_id)
            return False

    if router_id.startswith(vcns_const.PLR_EDGE_PREFIX):
        # Look for the TLR that matches this PLR
        # and check if it exists in the neutron DB
        if router_id in plr_tlr_ids:
            tlr_id = plr_tlr_ids[router_id]
            if _is_id_prefix_in_list(tlr_id, rtr_ids):
                return True
            else:
                LOG.warning("TLR Router %s for PLR binding entry %s not found",
                            tlr_id, router_id)
                return False
        else:
            LOG.warning(
                "TLR Router binding for PLR binding entry %s not "
                "found", router_id)
            return False

    if router_id.startswith(lb_common.RESOURCE_ID_PFX):
        # should have a load balancer starting with this id on the same edge
        if nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge(
                context.session, binding.edge_id):
            return True
        else:
            LOG.warning("Loadbalancer for binding entry %s not found",
                        router_id)
            return False

    # regular router
    # get the id. and look for a router with this id
    if _is_id_prefix_in_list(router_id, rtr_ids):
        return True
    else:
        LOG.warning("Router for binding entry %s not found", router_id)
        return False
Пример #4
0
def router_binding_obj_exist(context, binding, net_ids, rtr_ids, plr_tlr_ids):
    """Check if the object responsible for the router binding entry exists

    Check if the relevant router/network/loadbalancer exists in the neutron DB
    """
    router_id = binding.router_id

    if router_id.startswith(vcns_const.BACKUP_ROUTER_PREFIX):
        # no neutron object that should match backup edges
        return True

    if router_id.startswith(vcns_const.DHCP_EDGE_PREFIX):
        # should have a network starting with this id
        # get the id. and look for a network with this id
        net_id_prefix = _get_obj_id_from_binding(
            router_id, vcns_const.DHCP_EDGE_PREFIX)
        if _is_id_prefix_in_list(net_id_prefix, net_ids):
            return True
        else:
            LOG.warning("Network for binding entry %s not found", router_id)
            return False

    if router_id.startswith(vcns_const.PLR_EDGE_PREFIX):
        # Look for the TLR that matches this PLR
        # and check if it exists in the neutron DB
        if router_id in plr_tlr_ids:
            tlr_id = plr_tlr_ids[router_id]
            if _is_id_prefix_in_list(tlr_id, rtr_ids):
                return True
            else:
                LOG.warning("TLR Router %s for PLR binding entry %s not found",
                            tlr_id, router_id)
                return False
        else:
            LOG.warning("TLR Router binding for PLR binding entry %s not "
                        "found", router_id)
            return False

    if router_id.startswith(lb_common.RESOURCE_ID_PFX):
        # should have a load balancer starting with this id on the same edge
        if nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge(
            context.session, binding.edge_id):
            return True
        else:
            LOG.warning("Loadbalancer for binding entry %s not found",
                        router_id)
            return False

    # regular router
    # get the id. and look for a router with this id
    if _is_id_prefix_in_list(router_id, rtr_ids):
        return True
    else:
        LOG.warning("Router for binding entry %s not found", router_id)
        return False
    def _check_lb_on_subnet(self, context, subnet_id, router_id):
        # Check lbaas
        dev_owner_v1 = n_consts.DEVICE_OWNER_LOADBALANCER
        dev_owner_v2 = n_consts.DEVICE_OWNER_LOADBALANCERV2
        dev_owner_oct = oct_const.DEVICE_OWNER_OCTAVIA
        filters = {'device_owner': [dev_owner_v1, dev_owner_v2, dev_owner_oct],
                   'fixed_ips': {'subnet_id': [subnet_id]}}
        ports = super(nsx_v.NsxVPluginV2, self.plugin).get_ports(
            context, filters=filters)

        edge_id = self._get_router_edge_id(context, router_id)
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge(
            context.session, edge_id)
        return (len(ports) >= 1) and lb_binding
Пример #6
0
    def create(self, context, lb, completor):
        sub_id = lb['vip_subnet_id']
        if cfg.CONF.nsxv.use_routers_as_lbaas_platform:
            edge_id = lb_common.get_lbaas_edge_id_for_subnet(
                context, self.core_plugin, sub_id, lb['tenant_id'])
            if not edge_id:
                msg = _('No suitable Edge found for subnet %s') % sub_id
                raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
        else:
            lb_size = self._get_lb_flavor_size(context, lb.get('flavor_id'))
            edge_id = lb_common.get_lbaas_edge_id(context, self.core_plugin,
                                                  lb['id'], lb['vip_address'],
                                                  sub_id, lb['tenant_id'],
                                                  lb_size)

        if not edge_id:
            msg = _('Failed to allocate Edge on subnet %(sub)s for '
                    'loadbalancer %(lb)s') % {
                        'sub': sub_id,
                        'lb': lb['id']
                    }
            raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)

        try:
            if cfg.CONF.nsxv.use_routers_as_lbaas_platform:
                if not nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge(
                        context.session, edge_id):
                    lb_common.enable_edge_acceleration(self.vcns, edge_id)
                lb_common.add_vip_as_secondary_ip(self.vcns, edge_id,
                                                  lb['vip_address'])
            else:
                lb_common.enable_edge_acceleration(self.vcns, edge_id)

            edge_fw_rule_id = lb_common.add_vip_fw_rule(
                self.vcns, edge_id, lb['id'], lb['vip_address'])

            # set LB default rule
            if not cfg.CONF.nsxv.use_routers_as_lbaas_platform:
                lb_common.set_lb_firewall_default_rule(self.vcns, edge_id,
                                                       'accept')

            nsxv_db.add_nsxv_lbaas_loadbalancer_binding(
                context.session, lb['id'], edge_id, edge_fw_rule_id,
                lb['vip_address'])
            completor(success=True)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to create loadbalancer %s', lb['id'])
    def _check_lb_on_subnet(self, context, subnet_id, router_id):
        # Check lbaas
        dev_owner_v1 = 'neutron:' + plugin_const.LOADBALANCER
        dev_owner_v2 = 'neutron:' + plugin_const.LOADBALANCERV2
        filters = {
            'device_owner': [dev_owner_v1, dev_owner_v2],
            'fixed_ips': {
                'subnet_id': [subnet_id]
            }
        }
        ports = super(nsx_v.NsxVPluginV2,
                      self.plugin).get_ports(context, filters=filters)

        edge_id = self._get_router_edge_id(context, router_id)
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge(
            context.session, edge_id)
        return (len(ports) >= 1) and lb_binding