<s> from oslo_log import log as logging <EOL> import oslo_messaging <EOL> from neutron . common import constants <EOL> from neutron . common import rpc as n_rpc <EOL> from neutron . common import topics <EOL> from neutron . common import utils <EOL> from neutron import manager <EOL> from networking_cisco . plugins . cisco . common import cisco_constants <EOL> from networking_cisco . plugins . cisco . extensions import ciscocfgagentscheduler <EOL> LOG = logging . getLogger ( __name__ ) <EOL> L3AGENT_SCHED = constants . L3_AGENT_SCHEDULER_EXT_ALIAS <EOL> CFGAGENT_SCHED = ciscocfgagentscheduler . CFG_AGENT_SCHEDULER_ALIAS <EOL> CFG_AGENT_L3_ROUTING = cisco_constants . CFG_AGENT_L3_ROUTING <EOL> class L3RouterCfgAgentNotifyAPI ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , l3plugin , topic = CFG_AGENT_L3_ROUTING ) : <EOL> self . _l3plugin = l3plugin <EOL> target = oslo_messaging . Target ( topic = topic , version = '<STR_LIT:1.0>' ) <EOL> self . client = n_rpc . get_client ( target ) <EOL> def _agent_notification_bulk ( self , context , method , routers , <EOL> hosting_device , operation ) : <EOL> """<STR_LIT>""" <EOL> admin_context = context . is_admin and context or context . elevated ( ) <EOL> dmplugin = manager . NeutronManager . get_service_plugins ( ) . get ( <EOL> cisco_constants . DEVICE_MANAGER ) <EOL> if ( hosting_device is not None and utils . is_extension_supported ( <EOL> dmplugin , CFGAGENT_SCHED ) ) : <EOL> agents = dmplugin . get_cfg_agents_for_hosting_devices ( <EOL> admin_context , [ hosting_device [ '<STR_LIT:id>' ] ] , admin_state_up = True , <EOL> schedule = True ) <EOL> if agents : <EOL> agent = agents [ <NUM_LIT:0> ] <EOL> LOG . debug ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : agent . agent_type , <EOL> '<STR_LIT>' : CFG_AGENT_L3_ROUTING , <EOL> '<STR_LIT:host>' : agent . host , <EOL> '<STR_LIT>' : method } ) <EOL> cctxt = self . client . prepare ( server = agent . host , <EOL> version = '<STR_LIT>' ) <EOL> cctxt . cast ( context , method , routers = routers ) <EOL> def _agent_notification ( self , context , method , routers , operation , <EOL> shuffle_agents ) : <EOL> """<STR_LIT>""" <EOL> admin_context = context . is_admin and context or context . elevated ( ) <EOL> dmplugin = manager . NeutronManager . get_service_plugins ( ) . get ( <EOL> cisco_constants . DEVICE_MANAGER ) <EOL> for router in routers : <EOL> if ( router [ '<STR_LIT>' ] is not None and <EOL> utils . is_extension_supported ( dmplugin , CFGAGENT_SCHED ) ) : <EOL> agents = dmplugin . get_cfg_agents_for_hosting_devices ( <EOL> admin_context , [ router [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] ] , <EOL> admin_state_up = True , schedule = True ) <EOL> else : <EOL> continue <EOL> for agent in agents : <EOL> LOG . debug ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : agent . agent_type , <EOL> '<STR_LIT>' : CFG_AGENT_L3_ROUTING , <EOL> '<STR_LIT:host>' : agent . host , <EOL> '<STR_LIT>' : method } ) <EOL> cctxt = self . client . prepare ( server = agent . host ) <EOL> cctxt . cast ( context , method , routers = [ router [ '<STR_LIT:id>' ] ] ) <EOL> def _notification ( self , context , method , routers , operation , <EOL> shuffle_agents ) : <EOL> """<STR_LIT>""" <EOL> if utils . is_extension_supported ( self . _l3plugin , L3AGENT_SCHED ) : <EOL> adm_context = ( context . is_admin and context or context . elevated ( ) ) <EOL> self . _l3plugin . schedule_routers ( adm_context , routers ) <EOL> self . _agent_notification ( <EOL> context , method , routers , operation , shuffle_agents ) <EOL> else : <EOL> cctxt = self . client . prepare ( topics = topics . L3_AGENT , fanout = True ) <EOL> cctxt . cast ( context , method , routers = [ r [ '<STR_LIT:id>' ] for r in routers ] ) <EOL> def router_deleted ( self , context , router ) : <EOL> """<STR_LIT>""" <EOL> self . _agent_notification ( context , '<STR_LIT>' , [ router ] , None , <EOL> False ) <EOL> def routers_updated ( self , context , routers , operation = None , data = None , <EOL> shuffle_agents = False ) : <EOL> """<STR_LIT>""" <EOL> if routers : <EOL> self . _notification ( context , '<STR_LIT>' , routers , operation , <EOL> shuffle_agents ) <EOL> def router_removed_from_hosting_device ( self , context , router ) : <EOL> """<STR_LIT>""" <EOL> self . _notification ( context , '<STR_LIT>' , <EOL> [ router ] , operation = None , shuffle_agents = False ) <EOL> def router_added_to_hosting_device ( self , context , router ) : <EOL> """<STR_LIT>""" <EOL> self . _notification ( context , '<STR_LIT>' , <EOL> [ router ] , operation = None , shuffle_agents = False ) <EOL> def routers_removed_from_hosting_device ( self , context , router_ids , <EOL> hosting_device ) : <EOL> """<STR_LIT>""" <EOL> self . _agent_notification_bulk ( <EOL> context , '<STR_LIT>' , router_ids , <EOL> hosting_device , operation = None ) </s>
