Example #1
0
    def delete(self, context, lb):
        # Discard any ports which are associated with LB
        filters = {
            'device_id': [lb.id],
            'device_owner': [constants.DEVICE_OWNER_NEUTRON_PREFIX + 'LB']
        }
        lb_ports = self.core_plugin.get_ports(context.elevated(),
                                              filters=filters)
        for lb_port in lb_ports:
            self.core_plugin.delete_port(context.elevated(), lb_port['id'])

        binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb.id)
        if binding:
            edge_binding = nsxv_db.get_nsxv_router_binding_by_edge(
                context.session, binding['edge_id'])

            # set LB default rule
            lb_common.set_lb_firewall_default_rule(self.vcns,
                                                   binding['edge_id'], 'deny')
            if edge_binding:
                old_lb = lb_common.is_lb_on_router_edge(
                    context, self.core_plugin, binding['edge_id'])
                if not old_lb:
                    resource_id = lb_common.get_lb_resource_id(lb.id)
                    self.core_plugin.edge_manager.delete_lrouter(context,
                                                                 resource_id,
                                                                 dist=False)
                else:
                    # Edge was created on an exclusive router with the old code
                    try:
                        lb_common.del_vip_fw_rule(self.vcns,
                                                  binding['edge_id'],
                                                  binding['edge_fw_rule_id'])
                    except nsxv_exc.VcnsApiException as e:
                        LOG.error(
                            'Failed to delete loadbalancer %(lb)s '
                            'FW rule. exception is %(exc)s', {
                                'lb': lb.id,
                                'exc': e
                            })
                    try:
                        lb_common.del_vip_as_secondary_ip(
                            self.vcns, binding['edge_id'], lb.vip_address)
                    except Exception as e:
                        LOG.error(
                            'Failed to delete loadbalancer %(lb)s '
                            'interface IP. exception is %(exc)s', {
                                'lb': lb.id,
                                'exc': e
                            })

            nsxv_db.del_nsxv_lbaas_loadbalancer_binding(context.session, lb.id)
        self.lbv2_driver.load_balancer.successful_completion(context,
                                                             lb,
                                                             delete=True)
    def test_del_vip_as_secondary_ip(self):
        update_if = if_maker(['10.0.0.6'])

        with self._mock_edge_driver_vcns('get_interfaces') as mock_get_if,\
                self._mock_edge_driver_vcns(
                    'update_interface') as mock_update_if:

            mock_get_if.return_value = (None, if_list_maker(['10.0.0.6',
                                                             '10.0.0.8']))

            lb_common.del_vip_as_secondary_ip(
                self.edge_driver.vcns, EDGE_ID, '10.0.0.8')
            mock_update_if.assert_called_with(EDGE_ID, update_if)
 def delete(self, context, lb):
     try:
         binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
             context.session, lb.id)
         if binding:
             lb_common.del_vip_fw_rule(self.vcns, binding['edge_id'],
                                       binding['edge_fw_rule_id'])
             lb_common.del_vip_as_secondary_ip(self.vcns,
                                               binding['edge_id'],
                                               lb.vip_address)
             nsxv_db.del_nsxv_lbaas_loadbalancer_binding(context.session,
                                                         lb.id)
         self.lbv2_driver.load_balancer.successful_completion(
             context, lb, delete=True)
     except nsxv_exc.VcnsApiException:
         with excutils.save_and_reraise_exception():
             self.lbv2_driver.load_balancer.failed_completion(context, lb)
             LOG.error(_LE('Failed to delete pool %s'), lb.id)
 def delete(self, context, lb):
     try:
         binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
             context.session, lb.id)
         if binding:
             lb_common.del_vip_fw_rule(self.vcns, binding['edge_id'],
                                       binding['edge_fw_rule_id'])
             lb_common.del_vip_as_secondary_ip(self.vcns,
                                               binding['edge_id'],
                                               lb.vip_address)
             nsxv_db.del_nsxv_lbaas_loadbalancer_binding(
                 context.session, lb.id)
         self.lbv2_driver.load_balancer.successful_completion(context,
                                                              lb,
                                                              delete=True)
     except nsxv_exc.VcnsApiException:
         with excutils.save_and_reraise_exception():
             self.lbv2_driver.load_balancer.failed_completion(context, lb)
             LOG.error(_LE('Failed to delete pool %s'), lb.id)
    def delete_vip(self, context, vip, vip_mapping):
        LOG.debug('Deleting VIP %s', vip)

        if not vip_mapping:
            LOG.error(_LE('No mapping found for vip %s'), vip['id'])
        else:
            edge_id = vip_mapping['edge_id']
            edge_vse_id = vip_mapping['edge_vse_id']
            app_profile_id = vip_mapping['edge_app_profile_id']

            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.delete_vip(edge_id, edge_vse_id)
                lb_common.del_vip_as_secondary_ip(self.vcns, edge_id,
                                                  vip['address'])
                lb_common.del_vip_fw_rule(self.vcns, edge_id,
                                          vip_mapping['edge_fw_rule_id'])

            except nsxv_exc.ResourceNotFound:
                LOG.error(_LE('vip not found on edge: %s'), edge_id)
            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv1_driver.vip_failed(context, vip)
                    LOG.error(
                        _LE('Failed to delete vip on edge: %s'), edge_id)

            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.delete_app_profile(edge_id, app_profile_id)
            except nsxv_exc.ResourceNotFound:
                LOG.error(_LE('app profile not found on edge: %s'), edge_id)
            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv1_driver.vip_failed(context, vip)
                    LOG.error(
                        _LE('Failed to delete app profile on Edge: %s'),
                        edge_id)

        self.lbv1_driver.delete_vip_successful(context, vip)
    def delete(self, context, lb):
        binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb.id)
        if binding:
            try:
                lb_common.del_vip_fw_rule(self.vcns, binding['edge_id'],
                                          binding['edge_fw_rule_id'])
            except nsxv_exc.VcnsApiException as e:
                LOG.error(_LE('Failed to delete loadbalancer %(lb)s FW rule. '
                              'exception is %(exc)s'), {'lb': lb.id, 'exc': e})
            try:
                lb_common.del_vip_as_secondary_ip(self.vcns,
                                                  binding['edge_id'],
                                                  lb.vip_address)
            except Exception as e:
                LOG.error(_LE('Failed to delete loadbalancer %(lb)s interface'
                              ' IP. exception is %(exc)s'),
                          {'lb': lb.id, 'exc': e})

            nsxv_db.del_nsxv_lbaas_loadbalancer_binding(context.session, lb.id)
        self.lbv2_driver.load_balancer.successful_completion(context, lb,
                                                             delete=True)
    def delete_vip(self, context, vip, vip_mapping):
        LOG.debug('Deleting VIP %s', vip)

        if not vip_mapping:
            LOG.error(_LE('No mapping found for vip %s'), vip['id'])
        else:
            edge_id = vip_mapping['edge_id']
            edge_vse_id = vip_mapping['edge_vse_id']
            app_profile_id = vip_mapping['edge_app_profile_id']

            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.delete_vip(edge_id, edge_vse_id)
                lb_common.del_vip_as_secondary_ip(self.vcns, edge_id,
                                                  vip['address'])
                lb_common.del_vip_fw_rule(self.vcns, edge_id,
                                          vip_mapping['edge_fw_rule_id'])

            except nsxv_exc.ResourceNotFound:
                LOG.error(_LE('vip not found on edge: %s'), edge_id)
            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv1_driver.vip_failed(context, vip)
                    LOG.error(_LE('Failed to delete vip on edge: %s'), edge_id)

            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.delete_app_profile(edge_id, app_profile_id)
            except nsxv_exc.ResourceNotFound:
                LOG.error(_LE('app profile not found on edge: %s'), edge_id)
            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv1_driver.vip_failed(context, vip)
                    LOG.error(_LE('Failed to delete app profile on Edge: %s'),
                              edge_id)

        self.lbv1_driver.delete_vip_successful(context, vip)