Ejemplo n.º 1
0
    def create_pool_health_monitor(self, context, health_monitor, pool_id):
        monitor_id = health_monitor['health_monitor']['id']
        with context.session.begin(subtransactions=True):
            monitor_qry = context.session.query(HealthMonitor)
            try:
                monitor = monitor_qry.filter_by(id=monitor_id).one()
                monitor.update({'pool_id': pool_id})
            except exc.NoResultFound:
                raise loadbalancer.HealthMonitorNotFound(monitor_id=monitor_id)
            try:
                qry = context.session.query(Pool)
                pool = qry.filter_by(id=pool_id).one()
            except exc.NoResultFound:
                raise loadbalancer.PoolNotFound(pool_id=pool_id)

            assoc = PoolMonitorAssociation(pool_id=pool_id,
                                           monitor_id=monitor_id)
            assoc.monitor = monitor
            pool.monitors.append(assoc)

        monitors = []
        try:
            qry = context.session.query(Pool)
            pool = qry.filter_by(id=pool_id).one()
            for monitor in pool['monitors']:
                monitors.append(monitor['monitor_id'])
        except exc.NoResultFound:
            pass

        res = {"health_monitor": monitors}
        return res
Ejemplo n.º 2
0
 def delete_pool_health_monitor(self, context, id, pool_id):
     with context.session.begin(subtransactions=True):
         pool = self._get_resource(context, Pool, pool_id)
         try:
             monitor_qry = context.session.query(PoolMonitorAssociation)
             monitor = monitor_qry.filter_by(monitor_id=id,
                                             pool_id=pool_id).one()
             pool.monitors.remove(monitor)
         except exc.NoResultFound:
             raise loadbalancer.HealthMonitorNotFound(monitor_id=id)
Ejemplo n.º 3
0
 def _get_resource(self, context, model, id):
     try:
         r = self._get_by_id(context, model, id)
     except exc.NoResultFound:
         if issubclass(model, Vip):
             raise loadbalancer.VipNotFound(vip_id=id)
         elif issubclass(model, Pool):
             raise loadbalancer.PoolNotFound(pool_id=id)
         elif issubclass(model, Member):
             raise loadbalancer.MemberNotFound(member_id=id)
         elif issubclass(model, HealthMonitor):
             raise loadbalancer.HealthMonitorNotFound(monitor_id=id)
         else:
             raise
     return r