Esempio n. 1
0
    def post(self, pool):
        """Creates a pool on a load balancer or listener.

        Note that this can optionally take a listener_id with which the pool
        should be associated as the listener's default_pool. If specified,
        the pool creation will fail if the listener specified already has
        a default_pool.
        """
        # For some API requests the listener_id will be passed in the
        # pool_dict:
        context = pecan.request.context.get('octavia_context')
        pool_dict = db_prepare.create_pool(pool.to_dict(render_unsets=True))
        if 'listener_id' in pool_dict:
            if pool_dict['listener_id'] is not None:
                self.listener_id = pool_dict.pop('listener_id')
            else:
                del pool_dict['listener_id']
        if self.listener_id and self.repositories.listener.has_default_pool(
                context.session, self.listener_id):
            raise exceptions.DuplicatePoolEntry()
        self._test_lb_and_listener_statuses(context.session)

        pool_dict['operating_status'] = constants.OFFLINE
        pool_dict['load_balancer_id'] = self.load_balancer_id

        return self._validate_create_pool(context.session, pool_dict)
Esempio n. 2
0
    def post(self, pool_):
        """Creates a pool on a load balancer or listener.

        Note that this can optionally take a listener_id with which the pool
        should be associated as the listener's default_pool. If specified,
        the pool creation will fail if the listener specified already has
        a default_pool.
        """
        # For some API requests the listener_id will be passed in the
        # pool_dict:
        pool = pool_.pool
        context = pecan.request.context.get('octavia_context')

        if pool.loadbalancer_id:
            pool.project_id = self._get_lb_project_id(context.session,
                                                      pool.loadbalancer_id)
        elif pool.listener_id:
            listener = self.repositories.listener.get(context.session,
                                                      id=pool.listener_id)
            pool.project_id = listener.project_id
            pool.loadbalancer_id = listener.load_balancer_id
        else:
            msg = _("Must provide at least one of: "
                    "loadbalancer_id, listener_id")
            raise exceptions.ValidationException(detail=msg)

        self._auth_validate_action(context, pool.project_id,
                                   constants.RBAC_POST)

        lock_session = db_api.get_session(autocommit=False)
        if self.repositories.check_quota_met(context.session, lock_session,
                                             data_models.Pool,
                                             pool.project_id):
            lock_session.rollback()
            raise exceptions.QuotaException

        listener_repo = self.repositories.listener
        pool_dict = db_prepare.create_pool(pool.to_dict(render_unsets=True))

        listener_id = pool_dict.pop('listener_id', None)
        if listener_id:
            if listener_repo.has_default_pool(lock_session, listener_id):
                raise exceptions.DuplicatePoolEntry()

        try:
            self._test_lb_and_listener_statuses(
                lock_session,
                lb_id=pool_dict['load_balancer_id'],
                listener_ids=[listener_id] if listener_id else [])

            db_pool = self._validate_create_pool(lock_session, pool_dict,
                                                 listener_id)
            lock_session.commit()
        except Exception:
            with excutils.save_and_reraise_exception():
                lock_session.rollback()

        return self._send_pool_to_handler(context.session,
                                          db_pool,
                                          listener_id=listener_id)
Esempio n. 3
0
    def _graph_create(self, session, lock_session, pool_dict):
        load_balancer_id = pool_dict['load_balancer_id']
        pool_dict = db_prepare.create_pool(pool_dict, load_balancer_id)
        members = pool_dict.pop('members', []) or []
        hm = pool_dict.pop('health_monitor', None)
        db_pool = self._validate_create_pool(lock_session, pool_dict)

        # Check quotas for healthmonitors
        if hm and self.repositories.check_quota_met(session, lock_session,
                                                    data_models.HealthMonitor,
                                                    db_pool.project_id):
            raise exceptions.QuotaException(
                resource=data_models.HealthMonitor._name())

        # Now possibly create a healthmonitor
        if hm:
            hm[constants.POOL_ID] = db_pool.id
            hm[constants.PROJECT_ID] = db_pool.project_id
            new_hm = health_monitor.HealthMonitorController()._graph_create(
                lock_session, hm)
            if db_pool.protocol in (constants.PROTOCOL_UDP,
                                    lib_consts.PROTOCOL_SCTP):
                health_monitor.HealthMonitorController(
                )._validate_healthmonitor_request_for_udp_sctp(
                    new_hm, db_pool)
            else:
                if new_hm.type in (constants.HEALTH_MONITOR_UDP_CONNECT,
                                   lib_consts.HEALTH_MONITOR_SCTP):
                    raise exceptions.ValidationException(
                        detail=_(
                            "The %(type)s type is only supported for pools of "
                            "type %(protocol)s.") % {
                                'type':
                                new_hm.type,
                                'protocol':
                                '/'.join((constants.PROTOCOL_UDP,
                                          lib_consts.PROTOCOL_SCTP))
                            })
            db_pool.health_monitor = new_hm

        # Now check quotas for members
        if members and self.repositories.check_quota_met(session,
                                                         lock_session,
                                                         data_models.Member,
                                                         db_pool.project_id,
                                                         count=len(members)):
            raise exceptions.QuotaException(
                resource=data_models.Member._name())

        # Now create members
        new_members = []
        for m in members:
            validate.ip_not_reserved(m["ip_address"])

            m['project_id'] = db_pool.project_id
            new_members.append(
                member.MembersController(db_pool.id)._graph_create(
                    lock_session, m))
        db_pool.members = new_members
        return db_pool
Esempio n. 4
0
    def post(self, pool):
        """Creates a pool on a load balancer or listener.

        Note that this can optionally take a listener_id with which the pool
        should be associated as the listener's default_pool. If specified,
        the pool creation will fail if the listener specified already has
        a default_pool.
        """
        # For some API requests the listener_id will be passed in the
        # pool_dict:
        context = pecan.request.context.get('octavia_context')
        pool_dict = db_prepare.create_pool(pool.to_dict(render_unsets=True))
        if 'listener_id' in pool_dict:
            if pool_dict['listener_id'] is not None:
                self.listener_id = pool_dict.pop('listener_id')
            else:
                del pool_dict['listener_id']
        if self.listener_id and self.repositories.listener.has_default_pool(
                context.session, self.listener_id):
            raise exceptions.DuplicatePoolEntry()
        self._test_lb_and_listener_statuses(context.session)

        pool_dict['operating_status'] = constants.OFFLINE
        pool_dict['load_balancer_id'] = self.load_balancer_id

        return self._validate_create_pool(context.session, pool_dict)
Esempio n. 5
0
    def _graph_create(self, session, lock_session, pool_dict):
        load_balancer_id = pool_dict['load_balancer_id']
        pool_dict = db_prepare.create_pool(pool_dict, load_balancer_id)
        members = pool_dict.pop('members', []) or []
        hm = pool_dict.pop('health_monitor', None)
        db_pool = self._validate_create_pool(lock_session, pool_dict)

        # Check cluster quotas for healthmonitors
        if hm and self.repositories.check_clusterquota_met(
                lock_session, data_models.HealthMonitor,
                base_res_id=db_pool.id):
            raise exceptions.ClusterQuotaException(
                resource=data_models.HealthMonitor._name())

        # Check quotas for healthmonitors
        if hm and self.repositories.check_quota_met(session, lock_session,
                                                    data_models.HealthMonitor,
                                                    db_pool.project_id):
            raise exceptions.QuotaException(
                resource=data_models.HealthMonitor._name())

        # Now possibly create a healthmonitor
        new_hm = None
        if hm:
            hm['pool_id'] = db_pool.id
            hm['project_id'] = db_pool.project_id
            new_hm = health_monitor.HealthMonitorController()._graph_create(
                lock_session, hm)
            db_pool.health_monitor = new_hm

        # Now check cluster quotas for members
        if members and self.repositories.check_clusterquota_met(
                lock_session,
                data_models.Member,
                base_res_id=db_pool.id,
                count=len(members)):
            raise exceptions.ClusterQuotaException(
                resource=data_models.Member._name())

        # Now check quotas for members
        if members and self.repositories.check_quota_met(session,
                                                         lock_session,
                                                         data_models.Member,
                                                         db_pool.project_id,
                                                         count=len(members)):
            raise exceptions.QuotaException(
                resource=data_models.Member._name())

        # Now create members
        new_members = []
        for m in members:
            validate.ip_not_reserved(m["ip_address"])

            m['project_id'] = db_pool.project_id
            new_members.append(
                member.MembersController(db_pool.id)._graph_create(
                    lock_session, m))
        db_pool.members = new_members
        return db_pool
Esempio n. 6
0
    def post(self, pool):
        """Creates a pool on a load balancer or listener.

        Note that this can optionally take a listener_id with which the pool
        should be associated as the listener's default_pool. If specified,
        the pool creation will fail if the listener specified already has
        a default_pool.
        """
        # For some API requests the listener_id will be passed in the
        # pool_dict:
        context = pecan.request.context.get('octavia_context')

        pool.project_id = self._get_lb_project_id(context.session,
                                                  self.load_balancer_id)

        lock_session = db_api.get_session(autocommit=False)
        if self.repositories.check_quota_met(
                context.session,
                lock_session,
                data_models.Pool,
                pool.project_id):
            lock_session.rollback()
            raise exceptions.QuotaException(
                resource=data_models.Pool._name())

        try:
            pool_dict = db_prepare.create_pool(
                pool.to_dict(render_unsets=True))
            if 'listener_id' in pool_dict:
                if pool_dict['listener_id'] is not None:
                    self.listener_id = pool_dict.pop('listener_id')
                else:
                    del pool_dict['listener_id']
            listener_repo = self.repositories.listener
            if self.listener_id and listener_repo.has_default_pool(
                    lock_session, self.listener_id):
                raise exceptions.DuplicatePoolEntry()
            self._test_lb_and_listener_statuses(lock_session)

            pool_dict['operating_status'] = constants.OFFLINE
            pool_dict['load_balancer_id'] = self.load_balancer_id

            db_pool = self._validate_create_pool(lock_session, pool_dict)
            lock_session.commit()
        except Exception:
            with excutils.save_and_reraise_exception():
                lock_session.rollback()

        return self._send_pool_to_handler(context.session, db_pool)
Esempio n. 7
0
    def _graph_create(self, session, lock_session, pool_dict):
        load_balancer_id = pool_dict['load_balancer_id']
        pool_dict = db_prepare.create_pool(
            pool_dict, load_balancer_id)
        members = pool_dict.pop('members', []) or []
        hm = pool_dict.pop('health_monitor', None)
        db_pool = self._validate_create_pool(
            lock_session, pool_dict)

        # Check quotas for healthmonitors
        if hm and self.repositories.check_quota_met(
                session, lock_session, data_models.HealthMonitor,
                db_pool.project_id):
            raise exceptions.QuotaException(
                resource=data_models.HealthMonitor._name())

        # Now possibly create a healthmonitor
        new_hm = None
        if hm:
            hm['pool_id'] = db_pool.id
            hm['project_id'] = db_pool.project_id
            new_hm = health_monitor.HealthMonitorController()._graph_create(
                lock_session, hm)
            db_pool.health_monitor = new_hm

        # Now check quotas for members
        if members and self.repositories.check_quota_met(
                session, lock_session, data_models.Member,
                db_pool.project_id, count=len(members)):
            raise exceptions.QuotaException(
                resource=data_models.Member._name())

        # Now create members
        new_members = []
        for m in members:
            validate.ip_not_reserved(m["ip_address"])

            m['project_id'] = db_pool.project_id
            new_members.append(
                member.MembersController(db_pool.id)._graph_create(
                    lock_session, m))
        db_pool.members = new_members
        return db_pool
Esempio n. 8
0
    def _graph_create(self, session, lock_session, pool_dict):
        load_balancer_id = pool_dict['load_balancer_id']
        pool_dict = db_prepare.create_pool(pool_dict, load_balancer_id)
        members = pool_dict.pop('members', []) or []
        hm = pool_dict.pop('health_monitor', None)
        db_pool = self._validate_create_pool(lock_session, pool_dict)

        # Check quotas for healthmonitors
        if hm and self.repositories.check_quota_met(session, lock_session,
                                                    data_models.HealthMonitor,
                                                    db_pool.project_id):
            raise exceptions.QuotaException

        # Now possibly create a healthmonitor
        new_hm = None
        if hm:
            hm['pool_id'] = db_pool.id
            hm['project_id'] = db_pool.project_id
            new_hm = health_monitor.HealthMonitorController()._graph_create(
                lock_session, hm)

        # Now check quotas for members
        if members and self.repositories.check_quota_met(session,
                                                         lock_session,
                                                         data_models.Member,
                                                         db_pool.project_id,
                                                         count=len(members)):
            raise exceptions.QuotaException

        # Now create members
        new_members = []
        for m in members:
            m['project_id'] = db_pool.project_id
            new_members.append(
                member.MembersController(db_pool.id)._graph_create(
                    lock_session, m))
        return db_pool, new_hm, new_members
Esempio n. 9
0
    def post(self, pool_):
        """Creates a pool on a load balancer or listener.

        Note that this can optionally take a listener_id with which the pool
        should be associated as the listener's default_pool. If specified,
        the pool creation will fail if the listener specified already has
        a default_pool.
        """
        # For some API requests the listener_id will be passed in the
        # pool_dict:
        pool = pool_.pool
        context = pecan.request.context.get('octavia_context')

        if pool.loadbalancer_id:
            pool.project_id, provider = self._get_lb_project_id_provider(
                context.session, pool.loadbalancer_id)
        elif pool.listener_id:
            listener = self.repositories.listener.get(context.session,
                                                      id=pool.listener_id)
            pool.loadbalancer_id = listener.load_balancer_id
            pool.project_id, provider = self._get_lb_project_id_provider(
                context.session, pool.loadbalancer_id)
        else:
            msg = _("Must provide at least one of: "
                    "loadbalancer_id, listener_id")
            raise exceptions.ValidationException(detail=msg)

        self._auth_validate_action(context, pool.project_id,
                                   constants.RBAC_POST)

        if pool.session_persistence:
            sp_dict = pool.session_persistence.to_dict(render_unsets=False)
            validate.check_session_persistence(sp_dict)

        # Load the driver early as it also provides validation
        driver = driver_factory.get_driver(provider)

        lock_session = db_api.get_session(autocommit=False)
        try:
            if self.repositories.check_quota_met(context.session, lock_session,
                                                 data_models.Pool,
                                                 pool.project_id):
                raise exceptions.QuotaException(
                    resource=data_models.Pool._name())

            listener_repo = self.repositories.listener
            pool_dict = db_prepare.create_pool(
                pool.to_dict(render_unsets=True))

            listener_id = pool_dict.pop('listener_id', None)
            if listener_id:
                if listener_repo.has_default_pool(lock_session, listener_id):
                    raise exceptions.DuplicatePoolEntry()

            self._test_lb_and_listener_statuses(
                lock_session,
                lb_id=pool_dict['load_balancer_id'],
                listener_ids=[listener_id] if listener_id else [])

            db_pool = self._validate_create_pool(lock_session, pool_dict,
                                                 listener_id)

            # Prepare the data for the driver data model
            provider_pool = (driver_utils.db_pool_to_provider_pool(db_pool))

            # Dispatch to the driver
            LOG.info("Sending create Pool %s to provider %s", db_pool.id,
                     driver.name)
            driver_utils.call_provider(driver.name, driver.pool_create,
                                       provider_pool)

            lock_session.commit()
        except Exception:
            with excutils.save_and_reraise_exception():
                lock_session.rollback()

        db_pool = self._get_db_pool(context.session, db_pool.id)
        result = self._convert_db_to_type(db_pool, pool_types.PoolResponse)
        return pool_types.PoolRootResponse(pool=result)
Esempio n. 10
0
    def post(self, pool_):
        """Creates a pool on a load balancer or listener.

        Note that this can optionally take a listener_id with which the pool
        should be associated as the listener's default_pool. If specified,
        the pool creation will fail if the listener specified already has
        a default_pool.
        """
        # For some API requests the listener_id will be passed in the
        # pool_dict:
        pool = pool_.pool
        context = pecan.request.context.get('octavia_context')
        if pool.protocol == constants.PROTOCOL_UDP:
            self._validate_pool_request_for_udp(pool)
        else:
            if (pool.session_persistence and (
                    pool.session_persistence.persistence_timeout or
                    pool.session_persistence.persistence_granularity)):
                raise exceptions.ValidationException(detail=_(
                    "persistence_timeout and persistence_granularity "
                    "is only for UDP protocol pools."))
        if pool.loadbalancer_id:
            pool.project_id, provider = self._get_lb_project_id_provider(
                context.session, pool.loadbalancer_id)
        elif pool.listener_id:
            listener = self.repositories.listener.get(
                context.session, id=pool.listener_id)
            pool.loadbalancer_id = listener.load_balancer_id
            pool.project_id, provider = self._get_lb_project_id_provider(
                context.session, pool.loadbalancer_id)
        else:
            msg = _("Must provide at least one of: "
                    "loadbalancer_id, listener_id")
            raise exceptions.ValidationException(detail=msg)

        self._auth_validate_action(context, pool.project_id,
                                   constants.RBAC_POST)

        if pool.session_persistence:
            sp_dict = pool.session_persistence.to_dict(render_unsets=False)
            validate.check_session_persistence(sp_dict)

        # Load the driver early as it also provides validation
        driver = driver_factory.get_driver(provider)

        lock_session = db_api.get_session(autocommit=False)
        try:
            if self.repositories.check_quota_met(
                    context.session,
                    lock_session,
                    data_models.Pool,
                    pool.project_id):
                raise exceptions.QuotaException(
                    resource=data_models.Pool._name())

            listener_repo = self.repositories.listener
            pool_dict = db_prepare.create_pool(
                pool.to_dict(render_unsets=True))

            listener_id = pool_dict.pop('listener_id', None)
            if listener_id:
                if listener_repo.has_default_pool(lock_session,
                                                  listener_id):
                    raise exceptions.DuplicatePoolEntry()

            self._test_lb_and_listener_statuses(
                lock_session, lb_id=pool_dict['load_balancer_id'],
                listener_ids=[listener_id] if listener_id else [])

            db_pool = self._validate_create_pool(
                lock_session, pool_dict, listener_id)

            # Prepare the data for the driver data model
            provider_pool = (
                driver_utils.db_pool_to_provider_pool(db_pool))

            # Dispatch to the driver
            LOG.info("Sending create Pool %s to provider %s",
                     db_pool.id, driver.name)
            driver_utils.call_provider(
                driver.name, driver.pool_create, provider_pool)

            lock_session.commit()
        except Exception:
            with excutils.save_and_reraise_exception():
                lock_session.rollback()

        db_pool = self._get_db_pool(context.session, db_pool.id)
        result = self._convert_db_to_type(db_pool, pool_types.PoolResponse)
        return pool_types.PoolRootResponse(pool=result)