Example #1
0
    def create(self, context, pool, completor):
        lb_id = pool['loadbalancer_id']
        pool_client = self.core_plugin.nsxlib.load_balancer.pool
        pool_name = utils.get_name_and_uuid(pool['name'] or 'pool', pool['id'])
        tags = self._get_pool_tags(context, pool)
        description = pool.get('description')
        lb_algorithm = lb_const.LB_POOL_ALGORITHM_MAP.get(pool['lb_algorithm'])
        if pool.get('listeners') and len(pool['listeners']) > 1:
            completor(success=False)
            msg = (_('Failed to create pool: Multiple listeners are not '
                     'supported.'))
            raise n_exc.BadRequest(resource='lbaas-pool', msg=msg)

        # NOTE(salv-orlando): Guard against accidental compat breakages
        try:
            listener = pool['listener'] or pool['listeners'][0]
        except IndexError:
            # If listeners is an empty list we hit this exception
            listener = None
        # Perform additional validation for session persistence before
        # creating resources in the backend
        lb_common.validate_session_persistence(pool, listener, completor)
        try:
            kwargs = self._get_pool_kwargs(pool_name, tags, lb_algorithm,
                                           description)
            lb_pool = pool_client.create(**kwargs)
            nsx_db.add_nsx_lbaas_pool_binding(context.session, lb_id,
                                              pool['id'], lb_pool['id'])
        except nsxlib_exc.ManagerError:
            completor(success=False)
            msg = (_('Failed to create pool on NSX backend: %(pool)s') % {
                'pool': pool['id']
            })
            raise n_exc.BadRequest(resource='lbaas-pool', msg=msg)

        # The pool object can be created with either --listener or
        # --loadbalancer option. If listener is present, the virtual server
        # will be updated with the pool. Otherwise, just return. The binding
        # will be added later when the pool is associated with layer7 rule.
        # FIXME(salv-orlando): This two-step process can leave a zombie pool on
        # NSX if the VS update operation fails
        if listener:
            listener_id = listener['id']
            binding = nsx_db.get_nsx_lbaas_listener_binding(
                context.session, lb_id, listener_id)
            if binding:
                vs_id = binding['lb_vs_id']
                self._process_vs_update(context, pool, listener, lb_pool['id'],
                                        vs_id, completor)
                nsx_db.update_nsx_lbaas_pool_binding(context.session, lb_id,
                                                     pool['id'], vs_id)
            else:
                completor(success=False)
                msg = (_("Couldn't find binding on the listener: %s") %
                       listener['id'])
                raise nsx_exc.NsxPluginException(err_msg=msg)
        completor(success=True)
Example #2
0
    def create(self, context, pool):
        lb_id = pool.loadbalancer_id
        pool_client = self.core_plugin.nsxlib.load_balancer.pool
        vs_client = self.core_plugin.nsxlib.load_balancer.virtual_server
        pool_name = utils.get_name_and_uuid(pool.name, pool.id)
        tags = lb_utils.get_tags(self.core_plugin, pool.id,
                                 lb_const.LB_POOL_TYPE, pool.tenant_id,
                                 context.project_name)
        lb_algorithm = lb_const.LB_POOL_ALGORITHM_MAP.get(pool.lb_algorithm)
        try:
            snat_translation = {'type': "LbSnatAutoMap"}
            lb_pool = pool_client.create(display_name=pool_name,
                                         tags=tags,
                                         algorithm=lb_algorithm,
                                         snat_translation=snat_translation)
            nsx_db.add_nsx_lbaas_pool_binding(context.session, lb_id, pool.id,
                                              lb_pool['id'])
        except nsxlib_exc.ManagerError:
            self.lbv2_driver.pool.failed_completion(context, pool)
            msg = (_('Failed to create pool on NSX backend: %(pool)s') % {
                'pool': pool.id
            })
            raise n_exc.BadRequest(resource='lbaas-pool', msg=msg)

        # The pool object can be created with either --listener or
        # --loadbalancer option. If listener is present, the virtual server
        # will be updated with the pool. Otherwise, just return. The binding
        # will be added later when the pool is associated with layer7 rule.
        if pool.listener:
            listener_id = pool.listener.id
            binding = nsx_db.get_nsx_lbaas_listener_binding(
                context.session, lb_id, listener_id)
            if binding:
                vs_id = binding['lb_vs_id']
                try:
                    vs_client.update(vs_id, pool_id=lb_pool['id'])
                except nsxlib_exc.ManagerError:
                    with excutils.save_and_reraise_exception():
                        self.lbv2_driver.pool.failed_completion(context, pool)
                        LOG.error(
                            'Failed to attach pool %s to virtual '
                            'server %s', lb_pool['id'], vs_id)
                nsx_db.update_nsx_lbaas_pool_binding(context.session, lb_id,
                                                     pool.id, vs_id)
            else:
                msg = (_("Couldn't find binding on the listener: %s") %
                       listener_id)
                raise nsx_exc.NsxPluginException(err_msg=msg)
        self.lbv2_driver.pool.successful_completion(context, pool)
Example #3
0
    def create(self, context, pool, completor):
        lb_id = pool['loadbalancer_id']
        pool_client = self.core_plugin.nsxlib.load_balancer.pool
        vs_client = self.core_plugin.nsxlib.load_balancer.virtual_server
        pool_name = utils.get_name_and_uuid(pool['name'] or 'pool', pool['id'])
        tags = self._get_pool_tags(context, pool)
        description = pool.get('description')
        lb_algorithm = lb_const.LB_POOL_ALGORITHM_MAP.get(pool['lb_algorithm'])
        try:
            kwargs = self._get_pool_kwargs(pool_name, tags, lb_algorithm,
                                           description)
            lb_pool = pool_client.create(**kwargs)
            nsx_db.add_nsx_lbaas_pool_binding(
                context.session, lb_id, pool['id'], lb_pool['id'])
        except nsxlib_exc.ManagerError:
            completor(success=False)
            msg = (_('Failed to create pool on NSX backend: %(pool)s') %
                   {'pool': pool['id']})
            raise n_exc.BadRequest(resource='lbaas-pool', msg=msg)

        # The pool object can be created with either --listener or
        # --loadbalancer option. If listener is present, the virtual server
        # will be updated with the pool. Otherwise, just return. The binding
        # will be added later when the pool is associated with layer7 rule.
        if pool['listener']:
            listener_id = pool['listener']['id']
            binding = nsx_db.get_nsx_lbaas_listener_binding(
                context.session, lb_id, listener_id)
            if binding:
                vs_id = binding['lb_vs_id']
                try:
                    vs_client.update(vs_id, pool_id=lb_pool['id'])
                except nsxlib_exc.ManagerError:
                    with excutils.save_and_reraise_exception():
                        completor(success=False)
                        LOG.error('Failed to attach pool %s to virtual '
                                  'server %s', lb_pool['id'], vs_id)
                nsx_db.update_nsx_lbaas_pool_binding(
                    context.session, lb_id, pool['id'], vs_id)
            else:
                msg = (_("Couldn't find binding on the listener: %s") %
                       listener_id)
                raise nsx_exc.NsxPluginException(err_msg=msg)

        completor(success=True)