def schedule_unscheduled_bgp_speakers(self, context, host): if self.bgp_drscheduler: return self.bgp_drscheduler.schedule_unscheduled_bgp_speakers( context, host) else: LOG.warning(_LW("Cannot schedule BgpSpeaker to DrAgent. " "Reason: No scheduler registered."))
def _report_state(self): LOG.debug("Report state task started") try: self.agent_state.get('configurations').update( self.cache.get_state()) ctx = context.get_admin_context_without_session() agent_status = self.state_rpc.report_state(ctx, self.agent_state, True) if agent_status == agent_consts.AGENT_REVIVED: LOG.info(_LI("Agent has just been revived. " "Scheduling full sync")) self.schedule_full_resync( reason=_("Agent has just been revived")) except AttributeError: # This means the server does not support report_state LOG.warning(_LW("Neutron server does not support state report. " "State report for this agent will be disabled.")) self.heartbeat.stop() self.run() return except Exception: LOG.exception(_LE("Failed reporting state!")) return if self.agent_state.pop('start_flag', None): self.run()
def safe_configure_dragent_for_bgp_speaker(self, bgp_speaker): try: self.add_bgp_speaker_on_dragent(bgp_speaker) except (bgp_ext.BgpSpeakerNotFound, RuntimeError): LOG.warning(_LW('BGP speaker %s may have been deleted and its ' 'resources may have already been disposed.'), bgp_speaker['id'])
def schedule_unscheduled_bgp_speakers(self, context, host): """Schedule unscheduled BgpSpeaker to a BgpDrAgent. """ LOG.debug('Started auto-scheduling on host %s', host) with context.session.begin(subtransactions=True): bgp_dragent = obj_reg.load_class('Agent').get_object( context, agent_type=bgp_consts.AGENT_TYPE_BGP_ROUTING, host=host, admin_state_up=True) if not bgp_dragent: LOG.debug('No enabled BgpDrAgent on host %s', host) return False if utils.is_agent_down(bgp_dragent.heartbeat_timestamp): LOG.warning(_LW('BgpDrAgent %s is down'), bgp_dragent.id) return False if self._is_bgp_speaker_hosted(context, bgp_dragent['id']): # One BgpDrAgent can only host one BGP speaker LOG.debug( 'BgpDrAgent already hosting a speaker on host %s. ' 'Cannot schedule an another one', host) return False unscheduled_speakers = self._get_unscheduled_bgp_speakers(context) if not unscheduled_speakers: LOG.debug('Nothing to auto-schedule on host %s', host) return False self.bind(context, [bgp_dragent], unscheduled_speakers[0]) return True
def add_vrf_speaker_assoc(self, context, vrf_id, speaker_association): speaker_id = speaker_association['speaker_id'] LOG.info( _LI("Add speaker association %(speaker_id)s " "for BGPVRF %(vrf_id)s"), { 'speaker_id': speaker_id, 'vrf_id': vrf_id }) try: with context.session.begin(subtransactions=True): speaker_assoc_db = BgpSpeakerVrfBinding( id=uuidutils.generate_uuid(), vrf_id=vrf_id, speaker_id=speaker_id) context.session.add(speaker_assoc_db) return self._make_speaker_assoc_dict(speaker_assoc_db) except db_exc.DBDuplicateEntry: LOG.warning( _LW("Speaker %(speaker_id)s is already associated to " "BGPVRF %(vrf_id)s"), { 'speaker_id': speaker_id, 'vrf_id': vrf_id }) raise vrf_ext.BGPVRFSpeakerAssocAlreadyExists( vrf_id=vrf_id, speaker_id=speaker_id)
def schedule_unscheduled_bgp_speakers(self, context, host): if self.bgp_drscheduler: return self.bgp_drscheduler.schedule_unscheduled_bgp_speakers( context, host) else: LOG.warning(_LW("Cannot schedule BgpSpeaker to DrAgent. " "Reason: No scheduler registered."))
def schedule_unscheduled_bgp_speakers(self, context, host): """Schedule unscheduled BgpSpeaker to a BgpDrAgent. """ LOG.debug('Started auto-scheduling on host %s', host) with context.session.begin(subtransactions=True): bgp_dragent = obj_reg.load_class('Agent').get_object( context, agent_type=bgp_consts.AGENT_TYPE_BGP_ROUTING, host=host, admin_state_up=True) if not bgp_dragent: LOG.debug('No enabled BgpDrAgent on host %s', host) return False if utils.is_agent_down( bgp_dragent.heartbeat_timestamp): LOG.warning(_LW('BgpDrAgent %s is down'), bgp_dragent.id) return False if self._is_bgp_speaker_hosted(context, bgp_dragent['id']): # One BgpDrAgent can only host one BGP speaker LOG.debug('BgpDrAgent already hosting a speaker on host %s. ' 'Cannot schedule an another one', host) return False unscheduled_speakers = self._get_unscheduled_bgp_speakers(context) if not unscheduled_speakers: LOG.debug('Nothing to auto-schedule on host %s', host) return False self.bind(context, [bgp_dragent], unscheduled_speakers[0]) return True
def safe_configure_dragent_for_bgp_speaker(self, bgp_speaker): try: self.add_bgp_speaker_on_dragent(bgp_speaker) except (bgp_ext.BgpSpeakerNotFound, RuntimeError): LOG.warning(_LW('BGP speaker %s may have been deleted and its ' 'resources may have already been disposed.'), bgp_speaker['id'])
def _report_state(self): LOG.debug("Report state task started") try: self.agent_state.get('configurations').update( self.cache.get_state()) ctx = context.get_admin_context_without_session() agent_status = self.state_rpc.report_state(ctx, self.agent_state, True) if agent_status == agent_consts.AGENT_REVIVED: LOG.info(_LI("Agent has just been revived. " "Scheduling full sync")) self.schedule_full_resync( reason=_("Agent has just been revived")) except AttributeError: # This means the server does not support report_state LOG.warning(_LW("Neutron server does not support state report. " "State report for this agent will be disabled.")) self.heartbeat.stop() self.run() return except Exception: LOG.exception(_LE("Failed reporting state!")) return if self.agent_state.pop('start_flag', None): self.run()
def schedule_unscheduled_bgp_speakers(self, context, host): """Schedule unscheduled BgpSpeaker to a BgpDrAgent. """ LOG.debug('Started auto-scheduling on host %s', host) with context.session.begin(subtransactions=True): query = context.session.query(agents_db.Agent) query = query.filter_by( agent_type=bgp_consts.AGENT_TYPE_BGP_ROUTING, host=host, admin_state_up=sql.true()) try: bgp_dragent = query.one() except (exc.NoResultFound): LOG.debug('No enabled BgpDrAgent on host %s', host) return False if agents_db.AgentDbMixin.is_agent_down( bgp_dragent.heartbeat_timestamp): LOG.warning(_LW('BgpDrAgent %s is down'), bgp_dragent.id) return False if self._is_bgp_speaker_hosted(context, bgp_dragent['id']): # One BgpDrAgent can only host one BGP speaker LOG.debug('BgpDrAgent already hosting a speaker on host %s. ' 'Cannot schedule an another one', host) return False unscheduled_speakers = self._get_unscheduled_bgp_speakers(context) if not unscheduled_speakers: LOG.debug('Nothing to auto-schedule on host %s', host) return False self.bind(context, [bgp_dragent], unscheduled_speakers[0]) return True
def schedule_all_unscheduled_bgp_speakers(self): context = ncontext.get_admin_context() if self.bgp_drscheduler: return self.bgp_drscheduler.schedule_all_unscheduled_bgp_speakers( context) else: LOG.warning(_LW("Cannot schedule BgpSpeaker to DrAgent. " "Reason: No scheduler registered."))
def add_periodic_dragent_status_check(self): if self.bgp_drscheduler: self.add_agent_status_check_worker( self.remove_bgp_speaker_from_down_dragents) self.add_agent_status_check_worker( self.schedule_all_unscheduled_bgp_speakers) else: LOG.warning(_LW("Cannot schedule BgpSpeaker to DrAgent. " "Reason: No scheduler registered."))
def schedule_all_unscheduled_bgp_speakers(self): context = ncontext.get_admin_context() if self.bgp_drscheduler: return self.bgp_drscheduler.schedule_all_unscheduled_bgp_speakers( context) else: LOG.warning( _LW("Cannot schedule BgpSpeaker to DrAgent. " "Reason: No scheduler registered."))
def add_periodic_dragent_status_check(self): if self.bgp_drscheduler: self.add_agent_status_check_worker( self.remove_bgp_speaker_from_down_dragents) self.add_agent_status_check_worker( self.schedule_all_unscheduled_bgp_speakers) else: LOG.warning( _LW("Cannot schedule BgpSpeaker to DrAgent. " "Reason: No scheduler registered."))
def schedule_bgp_speaker(self, context, created_bgp_speaker): if self.bgp_drscheduler: agents = self.bgp_drscheduler.schedule(context, created_bgp_speaker) for agent in agents: self._bgp_rpc.bgp_speaker_created(context, created_bgp_speaker['id'], agent.host) else: LOG.warning(_LW("Cannot schedule BgpSpeaker to DrAgent. " "Reason: No scheduler registered."))
def schedule_bgp_speaker(self, context, created_bgp_speaker): if self.bgp_drscheduler: agents = self.bgp_drscheduler.schedule(context, created_bgp_speaker) for agent in agents: self._bgp_rpc.bgp_speaker_created(context, created_bgp_speaker['id'], agent.host) else: LOG.warning(_LW("Cannot schedule BgpSpeaker to DrAgent. " "Reason: No scheduler registered."))
def safe_get_bgp_peer_info(self, bgp_speaker_id, bgp_peer_id): try: bgp_peer = self.plugin_rpc.get_bgp_peer_info(self.context, bgp_peer_id) if not bgp_peer: LOG.warning(_LW('BGP Peer %s has been deleted.'), bgp_peer) return bgp_peer except Exception as e: self.schedule_resync(speaker_id=bgp_speaker_id, reason=e) LOG.error(_LE('BGP peer %(bgp_peer)s info call ' 'failed with reason=%(e)s.'), {'bgp_peer': bgp_peer_id, 'e': e})
def safe_get_bgp_peer_info(self, bgp_speaker_id, bgp_peer_id): try: bgp_peer = self.plugin_rpc.get_bgp_peer_info(self.context, bgp_peer_id) if not bgp_peer: LOG.warning(_LW('BGP Peer %s has been deleted.'), bgp_peer) return bgp_peer except Exception as e: self.schedule_resync(speaker_id=bgp_speaker_id, reason=e) LOG.error(_LE('BGP peer %(bgp_peer)s info call ' 'failed with reason=%(e)s.'), {'bgp_peer': bgp_peer_id, 'e': e})
def add_vrf_router_assoc(self, context, vrf_id, router_association): LOG.debug("vrf id %s, association %s", vrf_id, router_association) router_id = router_association['router_id'] try: with context.session.begin(subtransactions=True): router_assoc_db = BGPVRFRouterAssociation( id=uuidutils.generate_uuid(), vrf_id=vrf_id, router_id=router_id) context.session.add(router_assoc_db) return self._make_router_assoc_dict(router_assoc_db) except db_exc.DBDuplicateEntry: LOG.warning( _LW("router %(router_id)s is already associated to " "BGPVRF %(vrf_id)s"), { 'router_id': router_id, 'vrf_id': vrf_id }) raise vrf_ext.BGPVRFRouterAssocAlreadyExists(vrf_id=vrf_id, router_id=router_id)
def schedule_unscheduled_bgp_speakers(self, context, host): """Schedule unscheduled BgpSpeaker to a BgpDrAgent. """ LOG.debug('Started auto-scheduling on host %s', host) with context.session.begin(subtransactions=True): query = context.session.query(agent_model.Agent) query = query.filter_by( agent_type=bgp_consts.AGENT_TYPE_BGP_ROUTING, host=host, admin_state_up=sql.true()) try: bgp_dragent = query.one() except (exc.NoResultFound): LOG.debug('No enabled BgpDrAgent on host %s', host) return False if agents_db.AgentDbMixin.is_agent_down( bgp_dragent.heartbeat_timestamp): LOG.warning(_LW('BgpDrAgent %s is down'), bgp_dragent.id) return False if self._is_bgp_speaker_hosted(context, bgp_dragent['id']): # One BgpDrAgent can only host one BGP speaker LOG.debug( 'BgpDrAgent already hosting a speaker on host %s. ' 'Cannot schedule an another one', host) return False unscheduled_speakers = self._get_unscheduled_bgp_speakers(context) if not unscheduled_speakers: LOG.debug('Nothing to auto-schedule on host %s', host) return False self.bind(context, [bgp_dragent], unscheduled_speakers[0]) return True