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)
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)
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)
def post(self, pool): """Creates a pool on a listener. This does not allow more than one pool to be on a listener so once one is created, another cannot be created until the first one has been deleted. """ session = db_api.get_session() if self.repositories.listener.has_pool(session, self.listener_id): raise exceptions.DuplicatePoolEntry() # Verify load balancer is in a mutable status. If so it can be assumed # that the listener is also in a mutable status because a load balancer # will only be ACTIVE when all it's listeners as ACTIVE. self._test_lb_status(session) pool_dict = pool.to_dict() sp_dict = pool_dict.pop('session_persistence', None) pool_dict['operating_status'] = constants.OFFLINE return self._validate_create_pool(session, sp_dict, pool_dict)
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)