def add_router_to_l3_agent(self, context, id, router_id): """Add a l3 agent to host a router.""" router = self.get_router(context, router_id) with context.session.begin(subtransactions=True): agent_db = self._get_agent(context, id) if (agent_db['agent_type'] != constants.AGENT_TYPE_L3 or not agent_db['admin_state_up'] or not self.get_l3_agent_candidates(router, [agent_db])): raise l3agentscheduler.InvalidL3Agent(id=id) query = context.session.query(RouterL3AgentBinding) try: binding = query.filter( RouterL3AgentBinding.l3_agent_id == agent_db.id, RouterL3AgentBinding.router_id == router_id).one() if binding: raise l3agentscheduler.RouterHostedByL3Agent( router_id=router_id, agent_id=id) except exc.NoResultFound: pass result = self.auto_schedule_routers(context, agent_db.host, [router_id]) if not result: raise l3agentscheduler.RouterSchedulingFailed( router_id=router_id, agent_id=id) l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3) if l3_notifier: l3_notifier.router_added_to_agent( context, [router_id], agent_db.host)
def create_router_to_agent_binding(self, context, agent, router): """Create router to agent binding.""" router_id = router['id'] agent_id = agent['id'] if self.router_scheduler: try: self.router_scheduler.bind_router(context, router_id, agent) except db_exc.DBError: raise l3agentscheduler.RouterSchedulingFailed( router_id=router_id, agent_id=agent_id)
def create_router_to_agent_binding(self, context, agent, router): """Create router to agent binding.""" router_id = router['id'] agent_id = agent['id'] if router['external_gateway_info'] and self.router_scheduler and ( router.get('distributed')): try: self.bind_snat_router(context, router_id, agent) self.bind_dvr_router_servicenode(context, router_id, agent) except db_exc.DBError: raise l3agentscheduler.RouterSchedulingFailed( router_id=router_id, agent_id=agent_id) else: super(L3_DVRsch_db_mixin, self).create_router_to_agent_binding(context, agent, router)
def add_router_to_l3_agent(self, context, agent_id, router_id): """Add a l3 agent to host a router.""" router = self.get_router(context, router_id) distributed = router.get('distributed') with context.session.begin(subtransactions=True): agent_db = self._get_agent(context, agent_id) agent_conf = self.get_configuration_dict(agent_db) agent_mode = agent_conf.get('agent_mode', 'legacy') if (not distributed and agent_mode == 'dvr' or distributed and agent_mode == 'legacy'): router_type = ('distributed' if distributed else 'centralized') raise l3agentscheduler.RouterL3AgentMismatch( router_type=router_type, router_id=router_id, agent_mode=agent_mode, agent_id=agent_id) if (agent_db['agent_type'] != constants.AGENT_TYPE_L3 or not agent_db['admin_state_up'] or not self.get_l3_agent_candidates( context, router, [agent_db])): raise l3agentscheduler.InvalidL3Agent(id=agent_id) query = context.session.query(RouterL3AgentBinding) if distributed: binding = query.filter_by(router_id=router_id, l3_agent_id=agent_id).first() if binding: raise l3agentscheduler.RouterHostedByL3Agent( router_id=router_id, agent_id=binding.l3_agent_id) else: try: binding = query.filter_by(router_id=router_id).one() raise l3agentscheduler.RouterHostedByL3Agent( router_id=router_id, agent_id=binding.l3_agent_id) except exc.NoResultFound: pass result = self.auto_schedule_routers(context, agent_db.host, [router_id]) if not result: raise l3agentscheduler.RouterSchedulingFailed( router_id=router_id, agent_id=agent_id) l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3) if l3_notifier: l3_notifier.router_added_to_agent(context, [router_id], agent_db.host)
def create_router_to_agent_binding(self, context, agent, router): """Create router to agent binding.""" router_id = router['id'] agent_id = agent['id'] if self.router_scheduler: try: if router.get('ha'): plugin = manager.NeutronManager.get_service_plugins().get( service_constants.L3_ROUTER_NAT) self.router_scheduler.create_ha_port_and_bind( plugin, context, router['id'], router['tenant_id'], agent) else: self.router_scheduler.bind_router(context, router_id, agent) except db_exc.DBError: raise l3agentscheduler.RouterSchedulingFailed( router_id=router_id, agent_id=agent_id)
def create_router_to_agent_binding(self, context, agent, router): """Create router to agent binding.""" router_id = router['id'] agent_id = agent['id'] if self.router_scheduler: plugin = directory.get_plugin(constants.L3) try: if router.get('ha'): self.router_scheduler.create_ha_port_and_bind( plugin, context, router['id'], router['tenant_id'], agent, is_manual_scheduling=True) else: self.router_scheduler.bind_router( plugin, context, router_id, agent.id) except db_exc.DBError: raise l3agentscheduler.RouterSchedulingFailed( router_id=router_id, agent_id=agent_id)