Example #1
0
    def delete(self, context, pool):
        listener = pool.listener
        lb_id = listener.loadbalancer_id
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
            context.session, lb_id, listener.id, pool.id)
        listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
            context.session, lb_id, listener.id)

        edge_id = lb_binding['edge_id']
        edge_pool_id = pool_binding['edge_pool_id']

        try:
            vse = listener_mgr.listener_to_edge_vse(
                listener,
                lb_binding['vip_address'],
                None,
                listener_binding['app_profile_id'])
            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_vip(edge_id, listener_binding['vse_id'], vse)
                self.vcns.delete_pool(edge_id, edge_pool_id)
            self.lbv2_driver.pool.successful_completion(
                context, pool, delete=True)
            nsxv_db.del_nsxv_lbaas_pool_binding(
                context.session, lb_id, listener.id, pool.id)
        except nsxv_exc.VcnsApiException:
            self.lbv2_driver.pool.failed_completion(context, pool)
            LOG.error(_LE('Failed to delete pool %s'), pool['id'])
Example #2
0
 def _get_vse_id(self, context, pol):
     lb_id = pol.listener.loadbalancer_id
     list_id = pol.listener.id
     listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
         context.session, lb_id, list_id)
     if listener_binding:
         return listener_binding['vse_id']
Example #3
0
    def update(self,
               context,
               old_listener,
               new_listener,
               completor,
               certificate=None):
        default_pool = None
        if (new_listener.get('default_pool')
                and new_listener['default_pool'].get('id')):
            pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
                context.session, new_listener['loadbalancer_id'],
                new_listener['default_pool']['id'])
            if pool_binding:
                default_pool = pool_binding['edge_pool_id']
            else:
                LOG.error("Couldn't find pool binding for pool %s",
                          new_listener['default_pool']['id'])

        lb_id = new_listener['loadbalancer_id']
        listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
            context.session, lb_id, new_listener['id'])
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        edge_id = lb_binding['edge_id']

        edge_cert_id = None
        if certificate:
            if (old_listener['default_tls_container_id'] !=
                    new_listener['default_tls_container_id']):
                try:
                    edge_cert_id = self._upload_certificate(
                        context, edge_id,
                        new_listener['default_tls_container_id'], certificate)
                except Exception:
                    with excutils.save_and_reraise_exception():
                        completor(success=False)
            else:
                cert_binding = nsxv_db.get_nsxv_lbaas_certificate_binding(
                    context.session, new_listener['default_tls_container_id'],
                    edge_id)
                edge_cert_id = cert_binding['edge_cert_id']

        try:
            app_profile_id = update_app_profile(self.vcns,
                                                context,
                                                new_listener,
                                                edge_id,
                                                edge_cert_id=edge_cert_id)
            vse = listener_to_edge_vse(context, new_listener,
                                       lb_binding['vip_address'], default_pool,
                                       app_profile_id)

            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_vip(edge_id, listener_binding['vse_id'], vse)

            completor(success=True)
        except vcns_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to update app profile on edge: %s', edge_id)
Example #4
0
    def update(self, context, old_listener, new_listener, certificate=None):

        default_pool = None
        if new_listener.default_pool and new_listener.default_pool.id:
            pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
                context.session, new_listener.loadbalancer_id,
                new_listener.default_pool.id)
            if pool_binding:
                default_pool = pool_binding['edge_pool_id']
            else:
                LOG.error(_LE("Couldn't find pool binding for pool %s"),
                          new_listener.default_pool.id)

        lb_id = new_listener.loadbalancer_id
        listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
            context.session, lb_id, new_listener.id)
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        edge_id = lb_binding['edge_id']

        edge_cert_id = None
        if certificate:
            if (old_listener.default_tls_container_id !=
                    new_listener.default_tls_container_id):
                try:
                    edge_cert_id = self._upload_certificate(
                        context, edge_id,
                        new_listener.default_tls_container_id, certificate)
                except Exception:
                    with excutils.save_and_reraise_exception():
                        self.lbv2_driver.listener.failed_completion(
                            context, new_listener)
            else:
                cert_binding = nsxv_db.get_nsxv_lbaas_certificate_binding(
                    context.session, new_listener.default_tls_container_id,
                    edge_id)
                edge_cert_id = cert_binding['edge_cert_id']

        app_profile_id = listener_binding['app_profile_id']
        app_profile = listener_to_edge_app_profile(new_listener, edge_cert_id)

        try:
            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_app_profile(edge_id, app_profile_id,
                                             app_profile)

            vse = listener_to_edge_vse(new_listener, lb_binding['vip_address'],
                                       default_pool, app_profile_id)

            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_vip(edge_id, listener_binding['vse_id'], vse)

            self.lbv2_driver.listener.successful_completion(
                context, new_listener)
        except vcns_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                self.lbv2_driver.listener.failed_completion(
                    context, new_listener)
                LOG.error(_LE('Failed to update app profile on edge: %s'),
                          edge_id)
Example #5
0
    def delete(self, context, pool, completor):
        lb_id = pool['loadbalancer_id']

        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
            context.session, lb_id, pool['id'])

        edge_id = lb_binding['edge_id']
        if not pool_binding:
            completor(success=True)
            return

        edge_pool_id = pool_binding['edge_pool_id']

        listeners_to_update = []
        try:
            if pool['listeners']:
                for listener in pool['listeners']:
                    # the pool session persistence may affect the associated
                    # pool application profile
                    if (pool['session_persistence'] and
                        listener['default_pool'] and
                        listener['default_pool']['id'] == pool['id']):
                        listeners_to_update.append(listener)

                    listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
                        context.session, lb_id, listener['id'])
                    vse = listener_mgr.listener_to_edge_vse(
                        context,
                        listener,
                        lb_binding['vip_address'],
                        None,
                        listener_binding['app_profile_id'])
                    with locking.LockManager.get_lock(edge_id):
                        self.vcns.update_vip(
                            edge_id, listener_binding['vse_id'], vse)
            self.vcns.delete_pool(edge_id, edge_pool_id)
            completor(success=True)
            nsxv_db.del_nsxv_lbaas_pool_binding(
                context.session, lb_id, pool['id'])

            for listener in listeners_to_update:
                # need to update the listeners too, now with no default pool
                listener['default_pool'] = None
                listener_mgr.update_app_profile(
                    self.vcns, context, listener, edge_id)

            old_lb = lb_common.is_lb_on_router_edge(
                context, self.core_plugin, lb_binding['edge_id'])

            if old_lb:
                lb_common.update_pool_fw_rule(self.vcns, pool['id'],
                                              edge_id,
                                              self._get_lbaas_fw_section_id(),
                                              [])

        except nsxv_exc.VcnsApiException:
            completor(success=False)
            LOG.error('Failed to delete pool %s', pool['id'])
Example #6
0
    def delete(self, context, listener, completor):
        lb_id = listener['loadbalancer_id']
        listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
            context.session, lb_id, listener['id'])
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)

        if lb_binding and listener_binding:
            edge_id = lb_binding['edge_id']
            edge_vse_id = listener_binding['vse_id']
            app_profile_id = listener_binding['app_profile_id']

            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.delete_vip(edge_id, edge_vse_id)

            except (vcns_exc.ResourceNotFound, vcns_exc.RequestBad):
                LOG.error('vip not found on edge: %s', edge_id)
            except vcns_exc.VcnsApiException:
                LOG.error('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 (vcns_exc.ResourceNotFound, vcns_exc.RequestBad):
                    LOG.error('app profile not found on edge: %s', edge_id)
            except vcns_exc.VcnsApiException:
                LOG.error('Failed to delete app profile on Edge: %s', edge_id)

            nsxv_db.del_nsxv_lbaas_listener_binding(context.session, lb_id,
                                                    listener['id'])

        completor(success=True)
Example #7
0
    def delete(self, context, pool):
        listener = pool.listener
        lb_id = listener.loadbalancer_id
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
            context.session, lb_id, listener.id, pool.id)
        listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
            context.session, lb_id, listener.id)

        edge_id = lb_binding['edge_id']
        edge_pool_id = pool_binding['edge_pool_id']

        try:
            vse = listener_mgr.listener_to_edge_vse(
                listener, lb_binding['vip_address'], None,
                listener_binding['app_profile_id'])
            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_vip(edge_id, listener_binding['vse_id'], vse)
                self.vcns.delete_pool(edge_id, edge_pool_id)
            self.lbv2_driver.pool.successful_completion(context,
                                                        pool,
                                                        delete=True)
            nsxv_db.del_nsxv_lbaas_pool_binding(context.session, lb_id,
                                                listener.id, pool.id)
        except nsxv_exc.VcnsApiException:
            self.lbv2_driver.pool.failed_completion(context, pool)
            LOG.error(_LE('Failed to delete pool %s'), pool['id'])
Example #8
0
    def delete(self, context, pool, completor):
        lb_id = pool['loadbalancer_id']

        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
            context.session, lb_id, pool['id'])

        edge_id = lb_binding['edge_id']
        if not pool_binding:
            completor(success=True)
            return

        edge_pool_id = pool_binding['edge_pool_id']

        listeners_to_update = []
        try:
            if pool['listeners']:
                for listener in pool['listeners']:
                    # the pool session persistence may affect the associated
                    # pool application profile
                    if (pool['session_persistence'] and
                        listener['default_pool'] and
                        listener['default_pool']['id'] == pool['id']):
                        listeners_to_update.append(listener)

                    listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
                        context.session, lb_id, listener['id'])
                    vse = listener_mgr.listener_to_edge_vse(
                        context,
                        listener,
                        lb_binding['vip_address'],
                        None,
                        listener_binding['app_profile_id'])
                    with locking.LockManager.get_lock(edge_id):
                        self.vcns.update_vip(
                            edge_id, listener_binding['vse_id'], vse)
            self.vcns.delete_pool(edge_id, edge_pool_id)
            completor(success=True)
            nsxv_db.del_nsxv_lbaas_pool_binding(
                context.session, lb_id, pool['id'])

            for listener in listeners_to_update:
                # need to update the listeners too, now with no default pool
                listener['default_pool'] = None
                listener_mgr.update_app_profile(
                    self.vcns, context, listener, edge_id)

            old_lb = lb_common.is_lb_on_router_edge(
                context, self.core_plugin, lb_binding['edge_id'])

            if old_lb:
                lb_common.update_pool_fw_rule(self.vcns, pool['id'],
                                              edge_id,
                                              self._get_lbaas_fw_section_id(),
                                              [])

        except nsxv_exc.VcnsApiException:
            completor(success=False)
            LOG.error('Failed to delete pool %s', pool['id'])
Example #9
0
 def _get_vse_id(self, context, pol):
     lb_id = pol['listener']['loadbalancer_id']
     list_id = pol['listener']['id']
     listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
         context.session, lb_id, list_id)
     if listener_binding:
         return listener_binding['vse_id']
Example #10
0
    def delete(self, context, listener, completor):
        lb_id = listener['loadbalancer_id']
        listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
            context.session, lb_id, listener['id'])
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)

        if lb_binding and listener_binding:
            edge_id = lb_binding['edge_id']
            edge_vse_id = listener_binding['vse_id']
            app_profile_id = listener_binding['app_profile_id']

            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.delete_vip(edge_id, edge_vse_id)

            except (vcns_exc.ResourceNotFound, vcns_exc.RequestBad):
                LOG.error('vip not found on edge: %s', edge_id)
            except vcns_exc.VcnsApiException:
                LOG.error('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 (vcns_exc.ResourceNotFound, vcns_exc.RequestBad):
                LOG.error('app profile not found on edge: %s', edge_id)
            except vcns_exc.VcnsApiException:
                LOG.error('Failed to delete app profile on Edge: %s', edge_id)

            nsxv_db.del_nsxv_lbaas_listener_binding(context.session, lb_id,
                                                    listener['id'])

        completor(success=True)
Example #11
0
    def update(self, context, old_listener, new_listener, certificate=None):

        default_pool = None
        if new_listener.default_pool and new_listener.default_pool.id:
            pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
                context.session, new_listener.default_pool.id)
            if pool_binding:
                default_pool = pool_binding['edge_pool_id']

        lb_id = new_listener.loadbalancer_id
        listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
            context.session, lb_id, new_listener.id)
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        edge_id = lb_binding['edge_id']

        edge_cert_id = None
        if certificate:
            if (old_listener.default_tls_container_id !=
                    new_listener.default_tls_container_id):
                try:
                    edge_cert_id = self._upload_certificate(
                        context, edge_id,
                        new_listener.default_tls_container_id,
                        certificate)
                except Exception:
                    with excutils.save_and_reraise_exception():
                        self.lbv2_driver.listener.failed_completion(
                            context, new_listener)
            else:
                cert_binding = nsxv_db.get_nsxv_lbaas_certificate_binding(
                    context.session, new_listener.default_tls_container_id,
                    edge_id)
                edge_cert_id = cert_binding['edge_cert_id']

        app_profile_id = listener_binding['app_profile_id']
        app_profile = listener_to_edge_app_profile(new_listener, edge_cert_id)

        try:
            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_app_profile(
                    edge_id, app_profile_id, app_profile)

            vse = listener_to_edge_vse(new_listener,
                                       lb_binding['vip_address'],
                                       default_pool,
                                       app_profile_id)

            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_vip(edge_id, listener_binding['vse_id'], vse)

            self.lbv2_driver.listener.successful_completion(context,
                                                            new_listener)
        except vcns_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                self.lbv2_driver.listener.failed_completion(context,
                                                          new_listener)
                LOG.error(_LE('Failed to update app profile on edge: %s'),
                          edge_id)
Example #12
0
def update_app_profile(vcns, context, listener, edge_id, edge_cert_id=None):
    lb_id = listener['loadbalancer_id']
    listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
        context.session, lb_id, listener['id'])
    app_profile_id = listener_binding['app_profile_id']
    app_profile = listener_to_edge_app_profile(listener, edge_cert_id)
    with locking.LockManager.get_lock(edge_id):
        vcns.update_app_profile(edge_id, app_profile_id, app_profile)
    return app_profile_id
Example #13
0
    def update(self, context, old_listener, new_listener, completor,
               certificate=None):
        default_pool = None
        if (new_listener.get('default_pool') and
            new_listener['default_pool'].get('id')):
            pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
                context.session, new_listener['loadbalancer_id'],
                new_listener['default_pool']['id'])
            if pool_binding:
                default_pool = pool_binding['edge_pool_id']
            else:
                LOG.error("Couldn't find pool binding for pool %s",
                          new_listener['default_pool']['id'])

        lb_id = new_listener['loadbalancer_id']
        listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
            context.session, lb_id, new_listener['id'])
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        edge_id = lb_binding['edge_id']

        edge_cert_id = None
        if certificate:
            if (old_listener['default_tls_container_id'] !=
                    new_listener['default_tls_container_id']):
                try:
                    edge_cert_id = self._upload_certificate(
                        context, edge_id,
                        new_listener['default_tls_container_id'],
                        certificate)
                except Exception:
                    with excutils.save_and_reraise_exception():
                        completor(success=False)
            else:
                cert_binding = nsxv_db.get_nsxv_lbaas_certificate_binding(
                    context.session, new_listener['default_tls_container_id'],
                    edge_id)
                edge_cert_id = cert_binding['edge_cert_id']

        try:
            app_profile_id = update_app_profile(
                self.vcns, context, new_listener,
                edge_id, edge_cert_id=edge_cert_id)
            vse = listener_to_edge_vse(context, new_listener,
                                       lb_binding['vip_address'],
                                       default_pool,
                                       app_profile_id)

            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_vip(edge_id, listener_binding['vse_id'], vse)

            completor(success=True)
        except vcns_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to update app profile on edge: %s',
                          edge_id)
Example #14
0
def update_app_profile(vcns, context, listener, edge_id, edge_cert_id=None):
    lb_id = listener['loadbalancer_id']
    listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
        context.session, lb_id, listener['id'])
    app_profile_id = listener_binding['app_profile_id']
    app_profile = listener_to_edge_app_profile(listener, edge_cert_id)
    with locking.LockManager.get_lock(edge_id):
        vcns.update_app_profile(
            edge_id, app_profile_id, app_profile)
    return app_profile_id
Example #15
0
    def create(self, context, pool, completor):

        pool_id = pool['id']
        edge_pool = {
            'name': 'pool_' + pool_id,
            'description': pool.get('description', pool.get('name')),
            'algorithm': lb_const.BALANCE_MAP.get(pool['lb_algorithm'],
                                                  'round-robin'),
            'transparent': False
        }

        lb_id = pool['loadbalancer_id']
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        if not lb_binding:
            msg = _(
                'No suitable Edge found for pool %s') % pool_id
            raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
        edge_id = lb_binding['edge_id']

        try:
            with locking.LockManager.get_lock(edge_id):
                h = self.vcns.create_pool(edge_id, edge_pool)[0]
                edge_pool_id = lb_common.extract_resource_id(h['location'])
            nsxv_db.add_nsxv_lbaas_pool_binding(context.session, lb_id,
                                                pool_id,
                                                edge_pool_id)

            if pool['listener']:
                listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
                    context.session, lb_id, pool['listener']['id'])
                # Associate listener with pool
                vse = listener_mgr.listener_to_edge_vse(
                    context,
                    pool['listener'],
                    lb_binding['vip_address'],
                    edge_pool_id,
                    listener_binding['app_profile_id'])
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.update_vip(edge_id, listener_binding['vse_id'],
                                         vse)
                # This action also set this pool as the default pool of the
                # listener, so the application profile may need to be updated
                if pool['session_persistence']:
                    listener_mgr.update_app_profile(
                        self.vcns, context, pool['listener'], edge_id)

            completor(success=True)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to create pool %s', pool['id'])
Example #16
0
    def create(self, context, pool, completor):

        pool_id = pool['id']
        edge_pool = {
            'name': 'pool_' + pool_id,
            'description': pool.get('description', pool.get('name')),
            'algorithm': lb_const.BALANCE_MAP.get(pool['lb_algorithm'],
                                                  'round-robin'),
            'transparent': False
        }

        lb_id = pool['loadbalancer_id']
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        if not lb_binding:
            msg = _(
                'No suitable Edge found for pool %s') % pool_id
            raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
        edge_id = lb_binding['edge_id']

        try:
            with locking.LockManager.get_lock(edge_id):
                h = self.vcns.create_pool(edge_id, edge_pool)[0]
                edge_pool_id = lb_common.extract_resource_id(h['location'])
            nsxv_db.add_nsxv_lbaas_pool_binding(context.session, lb_id,
                                                pool_id,
                                                edge_pool_id)

            if pool['listener']:
                listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
                    context.session, lb_id, pool['listener']['id'])
                # Associate listener with pool
                vse = listener_mgr.listener_to_edge_vse(
                    context,
                    pool['listener'],
                    lb_binding['vip_address'],
                    edge_pool_id,
                    listener_binding['app_profile_id'])
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.update_vip(edge_id, listener_binding['vse_id'],
                                         vse)
                # This action also set this pool as the default pool of the
                # listener, so the application profile may need to be updated
                if pool['session_persistence']:
                    listener_mgr.update_app_profile(
                        self.vcns, context, pool['listener'], edge_id)

            completor(success=True)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to create pool %s', pool['id'])
Example #17
0
    def delete(self, context, pool):
        lb_id = pool.loadbalancer_id

        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
            context.session, lb_id, pool.id)

        edge_id = lb_binding['edge_id']
        if not pool_binding:
            self.lbv2_driver.pool.successful_completion(context,
                                                        pool,
                                                        delete=True)
            return

        edge_pool_id = pool_binding['edge_pool_id']

        listeners_to_update = []
        try:
            if pool.listeners:
                for listener in pool.listeners:
                    # the pool session persistence may affect the associated
                    # pool application profile
                    if (pool.session_persistence and listener.default_pool
                            and listener.default_pool.id == pool.id):
                        listeners_to_update.append(listener)

                    listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
                        context.session, lb_id, listener.id)
                    vse = listener_mgr.listener_to_edge_vse(
                        context, listener, lb_binding['vip_address'], None,
                        listener_binding['app_profile_id'])
                    with locking.LockManager.get_lock(edge_id):
                        self.vcns.update_vip(edge_id,
                                             listener_binding['vse_id'], vse)
            self.vcns.delete_pool(edge_id, edge_pool_id)
            self.lbv2_driver.pool.successful_completion(context,
                                                        pool,
                                                        delete=True)
            nsxv_db.del_nsxv_lbaas_pool_binding(context.session, lb_id,
                                                pool.id)

            for listener in listeners_to_update:
                # need to update the listeners too, now with no default pool
                listener.default_pool = None
                listener_mgr.update_app_profile(self.vcns, context, listener,
                                                edge_id)

        except nsxv_exc.VcnsApiException:
            self.lbv2_driver.pool.failed_completion(context, pool)
            LOG.error('Failed to delete pool %s', pool.id)
Example #18
0
    def delete(self, context, listener):
        lb_id = listener.loadbalancer_id
        listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
            context.session, lb_id, listener.id)
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)

        if lb_binding and listener_binding:
            edge_id = lb_binding['edge_id']
            edge_vse_id = listener_binding['vse_id']
            app_profile_id = listener_binding['app_profile_id']

            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.delete_vip(edge_id, edge_vse_id)

            except vcns_exc.ResourceNotFound:
                LOG.error(_LE('vip not found on edge: %s'), edge_id)
            except vcns_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv2_driver.listener.failed_completion(context,
                                                                listener)
                    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 vcns_exc.ResourceNotFound:
                LOG.error(_LE('app profile not found on edge: %s'), edge_id)
            except vcns_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv2_driver.listener.failed_completion(context,
                                                                listener)
                    LOG.error(
                        _LE('Failed to delete app profile on Edge: %s'),
                        edge_id)

            nsxv_db.del_nsxv_lbaas_listener_binding(context.session, lb_id,
                                                    listener.id)

        self.lbv2_driver.listener.successful_completion(
            context, listener, delete=True)
Example #19
0
    def create(self, context, pool):

        edge_pool = {
            'name': 'pool_' + pool.id,
            'description': getattr(pool, 'description', getattr(pool, 'name')),
            'algorithm': lb_const.BALANCE_MAP.get(pool.lb_algorithm,
                                                  'round-robin'),
            'transparent': False
        }

        lb_id = pool.loadbalancer_id
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)

        edge_id = lb_binding['edge_id']

        try:
            with locking.LockManager.get_lock(edge_id):
                h = self.vcns.create_pool(edge_id, edge_pool)[0]
                edge_pool_id = lb_common.extract_resource_id(h['location'])
            nsxv_db.add_nsxv_lbaas_pool_binding(context.session, lb_id,
                                                pool.id,
                                                edge_pool_id)

            if pool.listener:
                listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
                    context.session, lb_id, pool.listener.id)
                # Associate listener with pool
                vse = listener_mgr.listener_to_edge_vse(
                    pool.listener,
                    lb_binding['vip_address'],
                    edge_pool_id,
                    listener_binding['app_profile_id'])
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.update_vip(edge_id, listener_binding['vse_id'],
                                         vse)

            self.lbv2_driver.pool.successful_completion(context, pool)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                self.lbv2_driver.pool.failed_completion(context, pool)
                LOG.error(_LE('Failed to create pool %s'), pool['id'])
Example #20
0
    def create(self, context, pool):

        edge_pool = {
            'name': 'pool_' + pool.id,
            'description': getattr(pool, 'description', getattr(pool, 'name')),
            'algorithm': lb_const.BALANCE_MAP.get(pool.lb_algorithm,
                                                  'round-robin'),
            'transparent': False
        }

        listener = pool.listener
        lb_id = listener.loadbalancer_id
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
            context.session, lb_id, listener.id)

        edge_id = lb_binding['edge_id']

        try:
            with locking.LockManager.get_lock(edge_id):
                h = self.vcns.create_pool(edge_id, edge_pool)[0]
                edge_pool_id = lb_common.extract_resource_id(h['location'])
            nsxv_db.add_nsxv_lbaas_pool_binding(context.session, lb_id,
                                                listener.id,
                                                pool.id,
                                                edge_pool_id)

            # Associate listener with pool
            vse = listener_mgr.listener_to_edge_vse(
                listener,
                lb_binding['vip_address'],
                edge_pool_id,
                listener_binding['app_profile_id'])
            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_vip(edge_id, listener_binding['vse_id'], vse)

            self.lbv2_driver.pool.successful_completion(context, pool)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                self.lbv2_driver.pool.failed_completion(context, pool)
                LOG.error(_LE('Failed to create pool %s'), pool['id'])
Example #21
0
    def delete(self, context, listener):
        lb_id = listener.loadbalancer_id
        listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
            context.session, lb_id, listener.id)
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)

        if lb_binding and listener_binding:
            edge_id = lb_binding['edge_id']
            edge_vse_id = listener_binding['vse_id']
            app_profile_id = listener_binding['app_profile_id']

            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.delete_vip(edge_id, edge_vse_id)

            except vcns_exc.ResourceNotFound:
                LOG.error('vip not found on edge: %s', edge_id)
            except vcns_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv2_driver.listener.failed_completion(context,
                                                                listener)
                    LOG.error('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 vcns_exc.ResourceNotFound:
                LOG.error('app profile not found on edge: %s', edge_id)
            except vcns_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv2_driver.listener.failed_completion(context,
                                                                listener)
                    LOG.error(
                        'Failed to delete app profile on Edge: %s',
                        edge_id)

            nsxv_db.del_nsxv_lbaas_listener_binding(context.session, lb_id,
                                                    listener.id)

        self.lbv2_driver.listener.successful_completion(
            context, listener, delete=True)