Esempio n. 1
0
    def sync_qos(self, context, host):
        try:
            l3_agent = self._core_plugin._get_agent_by_type_and_host(
                context, n_constants.AGENT_TYPE_L3, host)
            if not l3_agent.is_active:
                # L3 agent is dead, return nothing for routers
                raise ext_agent.AgentNotFoundByTypeHost(
                    agent_type=n_constants.AGENT_TYPE_L3, host=host)
            binding_query = context.session.query(
                l3_agent_db.RouterL3AgentBinding.router_id).filter(
                    l3_agent_db.RouterL3AgentBinding.l3_agent_id ==
                    l3_agent.id)
            routers_bound_to_host = set(binding.router_id
                                        for binding in binding_query)
            router_query = context.session.query(l3_db.Router).filter(
                l3_db.Router.id.in_(routers_bound_to_host)).filter(
                    l3_db.Router.admin_state_up == true())
            routers_on_host = set(router.id for router in router_query)
        except ext_agent.AgentNotFoundByTypeHost:
            routers_on_host = set()

        port_query = context.session.query(ml2_models.PortBinding)
        port_query = port_query.filter(ml2_models.PortBinding.host == host)
        ports_on_host = set(binding.port_id for binding in port_query)

        query = context.session.query(Qos)
        query = query.filter(
            or_(
                and_(Qos.router_id.isnot(None),
                     Qos.router_id.in_(routers_on_host)),
                and_(Qos.port_id.isnot(None), Qos.port_id.in_(ports_on_host))))

        qoss_on_host = {}
        for qos in query.all():
            namespace = None
            if qos.router_id:
                namespace = 'qrouter-' + qos.router_id
            elif qos.port_id:
                if self._is_owner_floatingip(qos.port.device_owner):
                    try:
                        fip = self._l3_plugin.get_floatingip(
                            context, qos.port.device_id)
                    except ext_l3.FloatingIPNotFound:
                        continue
                    if fip['router_id'] is None:
                        continue
                    namespace = 'qrouter-' + fip['router_id']
                else:
                    namespace = '_root'

            if namespace:
                qos_for_agent = self._get_qos_for_agent(context, qos)
                if qos_for_agent:
                    if namespace not in qoss_on_host:
                        qoss_on_host[namespace] = []
                    qoss_on_host[namespace].append(qos_for_agent)

        return qoss_on_host
Esempio n. 2
0
 def _get_agent_by_type_and_host(self, context, agent_type, host):
     agent_objs = agent_obj.Agent.get_objects(context,
                                              agent_type=agent_type,
                                              host=host)
     if not agent_objs:
         raise ext_agent.AgentNotFoundByTypeHost(agent_type=agent_type,
                                                 host=host)
     if len(agent_objs) > 1:
         raise ext_agent.MultipleAgentFoundByTypeHost(agent_type=agent_type,
                                                      host=host)
     return agent_objs[0]
Esempio n. 3
0
 def _get_agent_by_type_and_host(self, context, agent_type, host):
     query = model_query.query_with_hooks(context, agent_model.Agent)
     try:
         agent_db = query.filter(agent_model.Agent.agent_type == agent_type,
                                 agent_model.Agent.host == host).one()
         return agent_db
     except exc.NoResultFound:
         raise ext_agent.AgentNotFoundByTypeHost(agent_type=agent_type,
                                                 host=host)
     except exc.MultipleResultsFound:
         raise ext_agent.MultipleAgentFoundByTypeHost(agent_type=agent_type,
                                                      host=host)
Esempio n. 4
0
 def _get_agent_by_type_and_host(self, context, agent_type, host):
     query = context.session.query(H3CAgent)
     try:
         agent_db = query.filter_by(agent_type=agent_type,
                                    host=host).one()
         return agent_db
     except exc.NoResultFound:
         raise ext_a.AgentNotFoundByTypeHost(agent_type=agent_type,
                                             host=host)
     except exc.MultipleResultsFound:
         raise ext_a.MultipleAgentFoundByTypeHost(agent_type=agent_type,
                                                  host=host)