示例#1
0
 def _test_lb_and_listener_statuses(
         self,
         session,
         lb_id,
         id=None,
         listener_status=constants.PENDING_UPDATE):
     """Verify load balancer is in a mutable state."""
     lb_repo = self.repositories.load_balancer
     if id:
         if not self.repositories.test_and_set_lb_and_listeners_prov_status(
                 session,
                 lb_id,
                 constants.PENDING_UPDATE,
                 listener_status,
                 listener_ids=[id]):
             LOG.info(_LI("Load Balancer %s is immutable."), lb_id)
             db_lb = lb_repo.get(session, id=lb_id)
             raise exceptions.ImmutableObject(resource=db_lb._name(),
                                              id=lb_id)
     else:
         if not lb_repo.test_and_set_provisioning_status(
                 session, lb_id, constants.PENDING_UPDATE):
             db_lb = lb_repo.get(session, id=lb_id)
             LOG.info(_LI("Load Balancer %s is immutable."), db_lb.id)
             raise exceptions.ImmutableObject(resource=db_lb._name(),
                                              id=lb_id)
示例#2
0
 def delete(self, id):
     """Deletes a pool member."""
     session = db_api.get_session()
     db_member = self.repositories.member.get(session, id=id)
     if not db_member:
         LOG.info(_LI("Member %s not found"), id)
         raise exceptions.NotFound(resource=data_models.Member._name(),
                                   id=id)
     # 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 its listeners as ACTIVE.
     if not self.repositories.test_and_set_lb_and_listener_prov_status(
             session, self.load_balancer_id, self.listener_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE):
         LOG.info(
             _LI("Member %s cannot be deleted because its Load "
                 "Balancer is in an immutable state."), id)
         lb_repo = self.repositories.load_balancer
         db_lb = lb_repo.get(session, id=self.load_balancer_id)
         raise exceptions.ImmutableObject(resource=db_lb._name(),
                                          id=self.load_balancer_id)
     db_member = self.repositories.member.get(session, id=id)
     try:
         LOG.info(_LI("Sending Deletion of Member %s to handler"),
                  db_member.id)
         self.handler.delete(db_member)
     except Exception:
         with excutils.save_and_reraise_exception(reraise=False):
             self.repositories.listener.update(
                 session,
                 self.listener_id,
                 operating_status=constants.ERROR)
     db_member = self.repositories.member.get(session, id=id)
     return self._convert_db_to_type(db_member, member_types.MemberResponse)
示例#3
0
 def put(self, id, load_balancer):
     """Updates a load balancer."""
     session = db_api.get_session()
     # Purely to make lines smaller length
     lb_repo = self.repositories.load_balancer
     db_lb = self.repositories.load_balancer.get(session, id=id)
     if not db_lb:
         LOG.info(_LI("Load Balancer %s was not found."), id)
         raise exceptions.NotFound(
             resource=data_models.LoadBalancer._name(), id=id)
     # Check load balancer is in a mutable status
     if not lb_repo.test_and_set_provisioning_status(
             session, id, constants.PENDING_UPDATE):
         LOG.info(_LI("Load Balancer %s is immutable."), id)
         raise exceptions.ImmutableObject(resource=db_lb._name(),
                                          id=id)
     try:
         LOG.info(_LI("Sending updated Load Balancer %s to the handler"),
                  id)
         self.handler.update(db_lb, load_balancer)
     except Exception:
         with excutils.save_and_reraise_exception(reraise=False):
             self.repositories.load_balancer.update(
                 session, id, provisioning_status=constants.ERROR)
     lb = self.repositories.load_balancer.get(session, id=id)
     return self._convert_db_to_type(lb, lb_types.LoadBalancerResponse)
示例#4
0
 def _test_lb_status(self, session, id, lb_status=constants.PENDING_UPDATE):
     """Verify load balancer is in a mutable state."""
     lb_repo = self.repositories.load_balancer
     if not lb_repo.test_and_set_provisioning_status(
             session, id, lb_status):
         LOG.info(_LI("Load Balancer %s is immutable."), id)
         db_lb = lb_repo.get(session, id=id)
         raise exceptions.ImmutableObject(resource=db_lb._name(), id=id)
示例#5
0
 def _test_lb_listener_policy_statuses(self, session):
     """Verify load balancer is in a mutable state."""
     l7policy = self._get_db_l7policy(session, self.l7policy_id)
     listener_id = l7policy.listener_id
     load_balancer_id = l7policy.listener.load_balancer_id
     # Check the parent is not locked for some reason (ERROR, etc.)
     if l7policy.provisioning_status not in constants.MUTABLE_STATUSES:
         raise exceptions.ImmutableObject(resource='L7Policy',
                                          id=self.l7policy_id)
     if not self.repositories.test_and_set_lb_and_listeners_prov_status(
             session, load_balancer_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE,
             listener_ids=[listener_id], l7policy_id=self.l7policy_id):
         LOG.info("L7Rule cannot be created or modified because the "
                  "Load Balancer is in an immutable state")
         raise exceptions.ImmutableObject(resource='Load Balancer',
                                          id=load_balancer_id)
示例#6
0
 def _test_lb_status_post(self, session, lb_repo):
     """Verify load balancer is in a mutable status for post method."""
     if not lb_repo.test_and_set_provisioning_status(
             session, self.load_balancer_id, constants.PENDING_UPDATE):
         db_lb = lb_repo.get(session, id=self.load_balancer_id)
         LOG.info(_LI("Load Balancer %s is immutable."), db_lb.id)
         raise exceptions.ImmutableObject(resource=db_lb._name(),
                                          id=self.load_balancer_id)
示例#7
0
 def _test_lb_and_listener_and_pool_statuses(self, session, member=None):
     """Verify load balancer is in a mutable state."""
     # We need to verify that any listeners referencing this member's
     # pool are also mutable
     pool = self._get_db_pool(session, self.pool_id)
     # Check the parent is not locked for some reason (ERROR, etc.)
     if pool.provisioning_status not in constants.MUTABLE_STATUSES:
         raise exceptions.ImmutableObject(resource='Pool', id=self.pool_id)
     load_balancer_id = pool.load_balancer_id
     if not self.repositories.test_and_set_lb_and_listeners_prov_status(
             session, load_balancer_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE,
             listener_ids=self._get_affected_listener_ids(session, member),
             pool_id=self.pool_id):
         LOG.info("Member cannot be created or modified because the "
                  "Load Balancer is in an immutable state")
         raise exceptions.ImmutableObject(resource='Load Balancer',
                                          id=load_balancer_id)
示例#8
0
 def _test_lb_and_listener_statuses(self, session, lb_id, listener_ids):
     """Verify load balancer is in a mutable state."""
     if not self.repositories.test_and_set_lb_and_listeners_prov_status(
             session, lb_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE,
             listener_ids=listener_ids):
         LOG.info("L7Policy cannot be created or modified because the "
                  "Load Balancer is in an immutable state")
         raise exceptions.ImmutableObject(resource='Load Balancer',
                                          id=lb_id)
示例#9
0
 def _test_lb_status_put(self, session, id):
     """Test load balancer status for put method."""
     if not self.repositories.test_and_set_lb_and_listener_prov_status(
             session, self.load_balancer_id, id, constants.PENDING_UPDATE,
             constants.PENDING_UPDATE):
         LOG.info(_LI("Load Balancer %s is immutable."),
                  self.load_balancer_id)
         lb_repo = self.repositories.load_balancer
         db_lb = lb_repo.get(session, id=self.load_balancer_id)
         raise exceptions.ImmutableObject(resource=db_lb._name(),
                                          id=self.load_balancer_id)
示例#10
0
 def post(self, health_monitor):
     """Creates a health monitor on a pool."""
     session = db_api.get_session()
     try:
         db_hm = self.repositories.health_monitor.get(session,
                                                      pool_id=self.pool_id)
         if db_hm:
             raise exceptions.DuplicateHealthMonitor()
     except exceptions.NotFound:
         pass
     hm_dict = health_monitor.to_dict()
     hm_dict['pool_id'] = self.pool_id
     # 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.
     if not self.repositories.test_and_set_lb_and_listener_prov_status(
             session, self.load_balancer_id, self.listener_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE):
         LOG.info(
             _LI("Health Monitor for Pool %s cannot be updated "
                 "because the Load Balancer is immutable."), self.pool_id)
         lb_repo = self.repositories.load_balancer
         db_lb = lb_repo.get(session, id=self.load_balancer_id)
         raise exceptions.ImmutableObject(resource=db_lb._name(),
                                          id=self.load_balancer_id)
     try:
         db_hm = self.repositories.health_monitor.create(session, **hm_dict)
     except odb_exceptions.DBError:
         # Setting LB and Listener back to active because this is just a
         # validation failure
         self.repositories.load_balancer.update(
             session,
             self.load_balancer_id,
             provisioning_status=constants.ACTIVE)
         self.repositories.listener.update(
             session,
             self.listener_id,
             provisioning_status=constants.ACTIVE)
         raise exceptions.InvalidOption(value=hm_dict.get('type'),
                                        option='type')
     try:
         LOG.info(
             _LI("Sending Creation of Health Monitor for Pool %s to "
                 "handler"), self.pool_id)
         self.handler.create(db_hm)
     except Exception:
         with excutils.save_and_reraise_exception(reraise=False):
             self.repositories.listener.update(
                 session,
                 self.listener_id,
                 operating_status=constants.ERROR)
     db_hm = self.repositories.health_monitor.get(session,
                                                  pool_id=self.pool_id)
     return self._convert_db_to_type(db_hm, hm_types.HealthMonitorResponse)
示例#11
0
 def _test_lb_and_listener_statuses(self, session):
     """Verify load balancer is in a mutable state."""
     if not self.repositories.test_and_set_lb_and_listeners_prov_status(
             session, self.load_balancer_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE,
             listener_ids=[self.listener_id]):
         LOG.info("L7Policy cannot be created or modified because the "
                  "Load Balancer is in an immutable state")
         lb_repo = self.repositories.load_balancer
         db_lb = lb_repo.get(session, id=self.load_balancer_id)
         raise exceptions.ImmutableObject(resource=db_lb._name(),
                                          id=self.load_balancer_id)
示例#12
0
文件: pool.py 项目: zongzw/octavia
 def _test_lb_and_listener_statuses(self, session, lb_id, listener_ids):
     """Verify load balancer is in a mutable state."""
     # We need to verify that any listeners referencing this pool are also
     # mutable
     if not self.repositories.test_and_set_lb_and_listeners_prov_status(
             session, lb_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE,
             listener_ids=listener_ids):
         LOG.info("Pool cannot be created or modified because the Load "
                  "Balancer is in an immutable state")
         raise exceptions.ImmutableObject(resource=_('Load Balancer'),
                                          id=lb_id)
示例#13
0
文件: pool.py 项目: kaurikim/octavia
 def _test_lb_status(self, session):
     """Verify load balancer is in a mutable status."""
     if not self.repositories.test_and_set_lb_and_listener_prov_status(
             session, self.load_balancer_id, self.listener_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE):
         LOG.info(
             _LI("Pool cannot be created because the Load "
                 "Balancer is in an immutable state"))
         lb_repo = self.repositories.load_balancer
         db_lb = lb_repo.get(session, id=self.load_balancer_id)
         raise exceptions.ImmutableObject(resource=db_lb._name(),
                                          id=self.load_balancer_id)
示例#14
0
 def _test_lb_listener_policy_statuses(self, session):
     """Verify load balancer is in a mutable state."""
     l7policy = self._get_db_l7policy(session, self.l7policy_id)
     listener_id = l7policy.listener_id
     load_balancer_id = l7policy.listener.load_balancer_id
     if not self.repositories.test_and_set_lb_and_listeners_prov_status(
             session, load_balancer_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE,
             listener_ids=[listener_id], l7policy_id=self.l7policy_id):
         LOG.info("L7Rule cannot be created or modified because the "
                  "Load Balancer is in an immutable state")
         raise exceptions.ImmutableObject(resource='Load Balancer',
                                          id=load_balancer_id)
示例#15
0
 def post(self, member):
     """Creates a pool member on a pool."""
     session = db_api.get_session()
     member_dict = member.to_dict()
     member_dict['pool_id'] = self.pool_id
     member_dict['operating_status'] = constants.OFFLINE
     # 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 its listeners as ACTIVE.
     if not self.repositories.test_and_set_lb_and_listener_prov_status(
             session, self.load_balancer_id, self.listener_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE):
         LOG.info(
             _LI("Member cannot be created because its Load "
                 "Balancer is in an immutable state."))
         lb_repo = self.repositories.load_balancer
         db_lb = lb_repo.get(session, id=self.load_balancer_id)
         raise exceptions.ImmutableObject(resource=db_lb._name(),
                                          id=self.load_balancer_id)
     try:
         db_member = self.repositories.member.create(session, **member_dict)
     except oslo_exc.DBDuplicateEntry as de:
         # Setting LB and Listener back to active because this is just a
         # validation failure
         self.repositories.load_balancer.update(
             session,
             self.load_balancer_id,
             provisioning_status=constants.ACTIVE)
         self.repositories.listener.update(
             session,
             self.listener_id,
             provisioning_status=constants.ACTIVE)
         if ['id'] == de.columns:
             raise exceptions.IDAlreadyExists()
         elif (set(['pool_id', 'ip_address',
                    'protocol_port']) == set(de.columns)):
             raise exceptions.DuplicateMemberEntry(
                 ip_address=member_dict.get('ip_address'),
                 port=member_dict.get('protocol_port'))
     try:
         LOG.info(_LI("Sending Creation of Member %s to handler"),
                  db_member.id)
         self.handler.create(db_member)
     except Exception:
         with excutils.save_and_reraise_exception(reraise=False):
             self.repositories.listener.update(
                 session,
                 self.listener_id,
                 operating_status=constants.ERROR)
     db_member = self.repositories.member.get(session, id=db_member.id)
     return self._convert_db_to_type(db_member, member_types.MemberResponse)
示例#16
0
 def _test_lb_and_listener_statuses(self, session, pool=None):
     """Verify load balancer is in a mutable state."""
     # We need to verify that any listeners referencing this pool are also
     # mutable
     if not self.repositories.test_and_set_lb_and_listeners_prov_status(
             session, self.load_balancer_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE,
             listener_ids=self._get_affected_listener_ids(session, pool)):
         LOG.info("Pool cannot be created or modified because the Load "
                  "Balancer is in an immutable state")
         lb_repo = self.repositories.load_balancer
         db_lb = lb_repo.get(session, id=self.load_balancer_id)
         raise exceptions.ImmutableObject(resource=db_lb._name(),
                                          id=self.load_balancer_id)
示例#17
0
 def _test_lb_and_listener_and_pool_statuses(self, session, member=None):
     """Verify load balancer is in a mutable state."""
     # We need to verify that any listeners referencing this member's
     # pool are also mutable
     pool = self._get_db_pool(session, self.pool_id)
     load_balancer_id = pool.load_balancer_id
     if not self.repositories.test_and_set_lb_and_listeners_prov_status(
             session, load_balancer_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE,
             listener_ids=self._get_affected_listener_ids(session, member),
             pool_id=self.pool_id):
         LOG.info(_LI("Member cannot be created or modified because the "
                      "Load Balancer is in an immutable state"))
         raise exceptions.ImmutableObject(resource='Load Balancer',
                                          id=load_balancer_id)
示例#18
0
 def _test_lb_and_listener_and_pool_statuses(self, session, hm):
     """Verify load balancer is in a mutable state."""
     # We need to verify that any listeners referencing this pool are also
     # mutable
     pool = self.repositories.pool.get(session, id=hm.pool_id)
     load_balancer_id = pool.load_balancer_id
     if not self.repositories.test_and_set_lb_and_listeners_prov_status(
             session, load_balancer_id,
             constants.PENDING_UPDATE, constants.PENDING_UPDATE,
             listener_ids=self._get_affected_listener_ids(session, hm),
             pool_id=hm.pool_id):
         LOG.info("Health Monitor cannot be created or modified because "
                  "the Load Balancer is in an immutable state")
         raise exceptions.ImmutableObject(resource='Load Balancer',
                                          id=load_balancer_id)
示例#19
0
    def put(self, health_monitor):
        """Updates a health monitor.

        Updates a health monitor on a pool if it exists.  Only one health
        monitor is allowed per pool so there is no need for a health monitor
        id.
        """
        session = db_api.get_session()
        db_hm = self.repositories.health_monitor.get(session,
                                                     pool_id=self.pool_id)
        if not db_hm:
            LOG.info(_LI("Health Monitor for Pool %s was not found"),
                     self.pool_id)
            raise exceptions.NotFound(
                resource=data_models.HealthMonitor._name(), id=id)
        # 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.
        if not self.repositories.test_and_set_lb_and_listener_prov_status(
                session, self.load_balancer_id, self.listener_id,
                constants.PENDING_UPDATE, constants.PENDING_UPDATE):
            LOG.info(
                _LI("Health Monitor for Pool %s cannot be updated "
                    "because the Load Balancer is immutable."), self.pool_id)
            lb_repo = self.repositories.load_balancer
            db_lb = lb_repo.get(session, id=self.load_balancer_id)
            raise exceptions.ImmutableObject(resource=db_lb._name(),
                                             id=self.load_balancer_id)
        try:
            LOG.info(
                _LI("Sending Update of Health Monitor for Pool %s to "
                    "handler"), self.pool_id)
            self.handler.update(db_hm, health_monitor)
        except Exception:
            with excutils.save_and_reraise_exception(reraise=False):
                self.repositories.listener.update(
                    session,
                    self.listener_id,
                    operating_status=constants.ERROR)
        db_hm = self.repositories.health_monitor.get(session,
                                                     pool_id=self.pool_id)
        return self._convert_db_to_type(db_hm, hm_types.HealthMonitorResponse)