<s> """<STR_LIT>""" <EOL> import sys <EOL> from exabgp . logger import Logger <EOL> from exabgp . configuration . core import Error <EOL> from exabgp . configuration . core import Scope <EOL> from exabgp . configuration . core import Tokeniser <EOL> from exabgp . configuration . core import Section <EOL> from exabgp . configuration . process import ParseProcess <EOL> from exabgp . configuration . template import ParseTemplate <EOL> from exabgp . configuration . neighbor import ParseNeighbor <EOL> from exabgp . configuration . neighbor . api import ParseAPI <EOL> from exabgp . configuration . neighbor . api import ParseSend <EOL> from exabgp . configuration . neighbor . api import ParseReceive <EOL> from exabgp . configuration . family import ParseFamily <EOL> from exabgp . configuration . capability import ParseCapability <EOL> from exabgp . configuration . static import ParseStatic <EOL> from exabgp . configuration . static import ParseStaticRoute <EOL> from exabgp . configuration . flow import ParseFlow <EOL> from exabgp . configuration . flow import ParseFlowRoute <EOL> from exabgp . configuration . flow import ParseFlowThen <EOL> from exabgp . configuration . flow import ParseFlowMatch <EOL> from exabgp . configuration . l2vpn import ParseL2VPN <EOL> from exabgp . configuration . l2vpn import ParseVPLS <EOL> from exabgp . configuration . operational import ParseOperational <EOL> from exabgp . configuration . environment import environment <EOL> class _Configuration ( object ) : <EOL> def __init__ ( self ) : <EOL> self . processes = { } <EOL> self . neighbors = { } <EOL> self . logger = Logger ( ) <EOL> def inject_change ( self , peers , change ) : <EOL> result = True <EOL> for neighbor in self . neighbors : <EOL> if neighbor in peers : <EOL> if change . nlri . family ( ) in self . neighbors [ neighbor ] . families ( ) : <EOL> self . neighbors [ neighbor ] . rib . outgoing . insert_announced ( change ) <EOL> else : <EOL> self . logger . configuration ( '<STR_LIT>' , '<STR_LIT:error>' ) <EOL> result = False <EOL> return result <EOL> def inject_eor ( self , peers , family ) : <EOL> result = False <EOL> for neighbor in self . neighbors : <EOL> if neighbor in peers : <EOL> result = True <EOL> self . neighbors [ neighbor ] . eor . append ( family ) <EOL> return result <EOL> def inject_operational ( self , peers , operational ) : <EOL> result = True <EOL> for neighbor in self . neighbors : <EOL> if neighbor in peers : <EOL> if operational . family ( ) in self . neighbors [ neighbor ] . families ( ) : <EOL> if operational . name == '<STR_LIT>' : <EOL> self . neighbors [ neighbor ] . asm [ operational . family ( ) ] = operational <EOL> self . neighbors [ neighbor ] . messages . append ( operational ) <EOL> else : <EOL> self . logger . configuration ( '<STR_LIT>' , '<STR_LIT:error>' ) <EOL> result = False <EOL> return result <EOL> def inject_refresh ( self , peers , refresh ) : <EOL> result = True <EOL> for neighbor in self . neighbors : <EOL> if neighbor in peers : <EOL> family = ( refresh . afi , refresh . safi ) <EOL> if family in self . neighbors [ neighbor ] . families ( ) : <EOL> self . neighbors [ neighbor ] . refresh . append ( refresh . __class__ ( refresh . afi , refresh . safi ) ) <EOL> else : <EOL> result = False <EOL> return result <EOL> class Configuration ( _Configuration ) : <EOL> def __init__ ( self , configurations ) : <EOL> _Configuration . __init__ ( self ) <EOL> self . api_encoder = environment . settings ( ) . api . encoder <EOL> self . _configurations = configurations <EOL> self . error = Error ( ) <EOL> self . scope = Scope ( ) <EOL> self . tokeniser = Tokeniser ( self . scope , self . error , self . logger ) <EOL> generic = Section ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . process = ParseProcess ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . template = ParseTemplate ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . neighbor = ParseNeighbor ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . family = ParseFamily ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . capability = ParseCapability ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . api = ParseAPI ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . api_send = ParseSend ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . api_receive = ParseReceive ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . static = ParseStatic ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . static_route = ParseStaticRoute ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . flow = ParseFlow ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . flow_route = ParseFlowRoute ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . flow_match = ParseFlowMatch ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . flow_then = ParseFlowThen ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . l2vpn = ParseL2VPN ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . vpls = ParseVPLS ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . operational = ParseOperational ( self . tokeniser , self . scope , self . error , self . logger ) <EOL> self . _structure = { <EOL> '<STR_LIT:root>' : { <EOL> '<STR_LIT:class>' : generic , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . process . name , <EOL> '<STR_LIT>' : self . neighbor . name , <EOL> '<STR_LIT>' : self . template . name , <EOL> } , <EOL> } , <EOL> self . process . name : { <EOL> '<STR_LIT:class>' : self . process , <EOL> '<STR_LIT>' : self . process . known . keys ( ) , <EOL> '<STR_LIT>' : { } , <EOL> } , <EOL> self . template . name : { <EOL> '<STR_LIT:class>' : self . template , <EOL> '<STR_LIT>' : self . template . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . family . name , <EOL> '<STR_LIT>' : self . capability . name , <EOL> '<STR_LIT>' : self . api . name , <EOL> '<STR_LIT>' : self . static . name , <EOL> '<STR_LIT>' : self . flow . name , <EOL> '<STR_LIT>' : self . l2vpn . name , <EOL> '<STR_LIT>' : self . operational . name , <EOL> } , <EOL> } , <EOL> self . neighbor . name : { <EOL> '<STR_LIT:class>' : self . neighbor , <EOL> '<STR_LIT>' : self . neighbor . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . family . name , <EOL> '<STR_LIT>' : self . capability . name , <EOL> '<STR_LIT>' : self . api . name , <EOL> '<STR_LIT>' : self . static . name , <EOL> '<STR_LIT>' : self . flow . name , <EOL> '<STR_LIT>' : self . l2vpn . name , <EOL> '<STR_LIT>' : self . operational . name , <EOL> } , <EOL> } , <EOL> self . family . name : { <EOL> '<STR_LIT:class>' : self . family , <EOL> '<STR_LIT>' : self . family . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } , <EOL> self . capability . name : { <EOL> '<STR_LIT:class>' : self . capability , <EOL> '<STR_LIT>' : self . capability . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } , <EOL> self . api . name : { <EOL> '<STR_LIT:class>' : self . api , <EOL> '<STR_LIT>' : self . api . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . api_send . name , <EOL> '<STR_LIT>' : self . api_receive . name , <EOL> } , <EOL> } , <EOL> self . api_send . name : { <EOL> '<STR_LIT:class>' : self . api_send , <EOL> '<STR_LIT>' : self . api_send . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } , <EOL> self . api_receive . name : { <EOL> '<STR_LIT:class>' : self . api_receive , <EOL> '<STR_LIT>' : self . api_receive . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } , <EOL> self . static . name : { <EOL> '<STR_LIT:class>' : self . static , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . static_route . name , <EOL> } , <EOL> } , <EOL> self . static_route . name : { <EOL> '<STR_LIT:class>' : self . static_route , <EOL> '<STR_LIT>' : self . static_route . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } , <EOL> self . flow . name : { <EOL> '<STR_LIT:class>' : self . flow , <EOL> '<STR_LIT>' : self . flow . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . flow_route . name , <EOL> } , <EOL> } , <EOL> self . flow_route . name : { <EOL> '<STR_LIT:class>' : self . flow_route , <EOL> '<STR_LIT>' : self . flow_route . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . flow_match . name , <EOL> '<STR_LIT>' : self . flow_then . name , <EOL> } , <EOL> } , <EOL> self . flow_match . name : { <EOL> '<STR_LIT:class>' : self . flow_match , <EOL> '<STR_LIT>' : self . flow_match . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } , <EOL> self . flow_then . name : { <EOL> '<STR_LIT:class>' : self . flow_then , <EOL> '<STR_LIT>' : self . flow_then . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } , <EOL> self . l2vpn . name : { <EOL> '<STR_LIT:class>' : self . l2vpn , <EOL> '<STR_LIT>' : self . l2vpn . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . vpls . name , <EOL> } , <EOL> } , <EOL> self . vpls . name : { <EOL> '<STR_LIT:class>' : self . vpls , <EOL> '<STR_LIT>' : self . l2vpn . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } , <EOL> self . operational . name : { <EOL> '<STR_LIT:class>' : self . operational , <EOL> '<STR_LIT>' : self . operational . known . keys ( ) , <EOL> '<STR_LIT>' : { <EOL> } <EOL> } , <EOL> } <EOL> self . _neighbors = { } <EOL> self . _previous_neighbors = { } <EOL> def _clear ( self ) : <EOL> self . processes = { } <EOL> self . neighbors = { } <EOL> self . _neighbors = { } <EOL> self . _previous_neighbors = { } <EOL> def _cleanup ( self ) : <EOL> self . error . clear ( ) <EOL> self . tokeniser . clear ( ) <EOL> self . scope . clear ( ) <EOL> self . process . clear ( ) <EOL> self . template . clear ( ) <EOL> self . neighbor . clear ( ) <EOL> self . family . clear ( ) <EOL> self . capability . clear ( ) <EOL> self . api . clear ( ) <EOL> self . api_send . clear ( ) <EOL> self . api_receive . clear ( ) <EOL> self . static . clear ( ) <EOL> self . static_route . clear ( ) <EOL> self . flow . clear ( ) <EOL> self . flow_route . clear ( ) <EOL> self . flow_match . clear ( ) <EOL> self . flow_then . clear ( ) <EOL> self . l2vpn . clear ( ) <EOL> self . vpls . clear ( ) <EOL> self . operational . clear ( ) <EOL> def _rollback_reload ( self ) : <EOL> self . neighbors = self . _previous_neighbors <EOL> self . _neighbors = { } <EOL> self . _previous_neighbors = { } <EOL> def _commit_reload ( self ) : <EOL> self . neighbors = self . neighbor . neighbors <EOL> self . processes = self . process . processes <EOL> self . _neighbors = { } <EOL> for neighbor in self . neighbors : <EOL> if neighbor in self . _previous_neighbors : <EOL> self . neighbors [ neighbor ] . changes = self . _previous_neighbors [ neighbor ] . changes <EOL> self . _previous_neighbors = { } <EOL> self . _cleanup ( ) <EOL> def reload ( self ) : <EOL> try : <EOL> return self . _reload ( ) <EOL> except KeyboardInterrupt : <EOL> return self . error . set ( '<STR_LIT>' ) <EOL> except Error , exc : <EOL> if environment . settings ( ) . debug . configuration : <EOL> raise <EOL> return self . error . set ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( self . tokeniser . index_line , exc ) <EOL> ) <EOL> except StandardError , exc : <EOL> if environment . settings ( ) . debug . configuration : <EOL> raise <EOL> return self . error . set ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( self . tokeniser . index_line , exc ) <EOL> ) <EOL> def _reload ( self ) : <EOL> fname = self . _configurations . pop ( <NUM_LIT:0> ) <EOL> self . _configurations . append ( fname ) <EOL> self . _clear ( ) <EOL> if not self . tokeniser . set_file ( fname ) : <EOL> return False <EOL> if self . section ( '<STR_LIT:root>' ) is not True : <EOL> self . _rollback_reload ( ) <EOL> return self . error . set ( <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( <EOL> self . scope . location ( ) , <EOL> self . tokeniser . number , <EOL> '<STR_LIT:U+0020>' . join ( self . tokeniser . line ) , <EOL> str ( self . error ) <EOL> ) <EOL> ) <EOL> self . _commit_reload ( ) <EOL> self . _link ( ) <EOL> self . debug_check_route ( ) <EOL> self . debug_self_check ( ) <EOL> return True <EOL> def _link ( self ) : <EOL> for neighbor in self . neighbors . itervalues ( ) : <EOL> api = neighbor . api <EOL> for process in api . get ( '<STR_LIT>' , [ ] ) : <EOL> self . processes . setdefault ( process , { } ) [ '<STR_LIT>' ] = api [ '<STR_LIT>' ] <EOL> for way in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> key = "<STR_LIT>" % ( way , name ) <EOL> if api [ key ] : <EOL> self . processes [ process ] . setdefault ( key , [ ] ) . append ( neighbor . router_id ) <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> key = "<STR_LIT>" % ( way , name ) <EOL> if api [ key ] : <EOL> self . processes [ process ] . setdefault ( key , [ ] ) . append ( neighbor . router_id ) <EOL> def partial ( self , section , text ) : <EOL> self . _cleanup ( ) <EOL> self . _clear ( ) <EOL> self . tokeniser . set_api ( text if text . endswith ( '<STR_LIT:;>' ) or text . endswith ( '<STR_LIT:}>' ) else text + '<STR_LIT>' ) <EOL> if self . section ( section ) is not True : <EOL> self . _rollback_reload ( ) <EOL> self . logger . configuration ( <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( <EOL> self . scope . location ( ) , <EOL> self . tokeniser . number , <EOL> '<STR_LIT:U+0020>' . join ( self . tokeniser . line ) , <EOL> str ( self . error ) <EOL> ) <EOL> ) <EOL> return False <EOL> return True <EOL> def _enter ( self , name ) : <EOL> location = self . tokeniser . iterate ( ) <EOL> self . logger . configuration ( "<STR_LIT>" % ( location , self . tokeniser . params ( ) ) ) <EOL> if location not in self . _structure [ name ] [ '<STR_LIT>' ] : <EOL> return self . error . set ( '<STR_LIT>' % ( location , name , self . scope . location ( ) ) ) <EOL> self . scope . enter ( location ) <EOL> if not self . section ( self . _structure [ name ] [ '<STR_LIT>' ] [ location ] ) : <EOL> return False <EOL> return True <EOL> def _leave ( self ) : <EOL> left = self . scope . leave ( ) <EOL> self . logger . configuration ( "<STR_LIT>" % ( left , self . tokeniser . params ( ) ) ) <EOL> if not left : <EOL> return self . error . set ( '<STR_LIT>' ) <EOL> return True <EOL> def _run ( self , name ) : <EOL> command = self . tokeniser . iterate ( ) <EOL> self . logger . configuration ( "<STR_LIT>" % ( command , self . tokeniser . params ( ) ) ) <EOL> if not self . run ( name , command ) : <EOL> return False <EOL> return True <EOL> def dispatch ( self , name ) : <EOL> while True : <EOL> self . tokeniser ( ) <EOL> if self . tokeniser . end == '<STR_LIT:;>' : <EOL> if self . _run ( name ) : <EOL> continue <EOL> return False <EOL> if self . tokeniser . end == '<STR_LIT:{>' : <EOL> if self . _enter ( name ) : <EOL> continue <EOL> return False <EOL> if self . tokeniser . end == '<STR_LIT:}>' : <EOL> return self . _leave ( ) <EOL> if not self . tokeniser . end : <EOL> return True <EOL> return self . error . set ( '<STR_LIT>' % self . tokeniser . index_line ) <EOL> return False <EOL> def section ( self , name ) : <EOL> if name not in self . _structure : <EOL> return self . error . set ( '<STR_LIT>' % name ) <EOL> instance = self . _structure [ name ] . get ( '<STR_LIT:class>' , None ) <EOL> if not instance : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> return instance . pre ( ) and self . dispatch ( name ) and instance . post ( ) <EOL> def run ( self , name , command ) : <EOL> if command not in self . _structure [ name ] [ '<STR_LIT>' ] : <EOL> return self . error . set ( '<STR_LIT>' % command ) <EOL> return self . _structure [ name ] [ '<STR_LIT:class>' ] . parse ( name , command ) <EOL> def debug_check_route ( self ) : <EOL> if environment . settings ( ) . debug . route : <EOL> from exabgp . configuration . check import check_message <EOL> if check_message ( self . neighbors , environment . settings ( ) . debug . route ) : <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def debug_self_check ( self ) : <EOL> if environment . settings ( ) . debug . selfcheck : <EOL> from exabgp . configuration . check import check_neighbor <EOL> if check_neighbor ( self . neighbors ) : <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> sys . exit ( <NUM_LIT:1> ) </s>
