#NEWLINE# def post( self ) : #NEWLINE# #INDENT# local = self . scope . pop_context ( self . name ) #NEWLINE# neighbor = Neighbor ( ) #NEWLINE# neighbor . router_id = local . get ( 'router-id' , None ) #NEWLINE# neighbor . peer_address = local . get ( 'peer-address' , None ) #NEWLINE# neighbor . local_address = local . get ( 'local-address' , None ) #NEWLINE# neighbor . local_as = local . get ( 'local-as' , None ) #NEWLINE# neighbor . peer_as = local . get ( 'peer-as' , None ) #NEWLINE# neighbor . passive = local . get ( 'passive' , False ) #NEWLINE# neighbor . listen = local . get ( 'listen' , 0 ) #NEWLINE# neighbor . connect = local . get ( 'connect' , 0 ) #NEWLINE# neighbor . hold_time = local . get ( 'hold-time' , HoldTime ( 180 ) ) #NEWLINE# neighbor . host_name = local . get ( 'host-name' , _hostname ( ) ) #NEWLINE# neighbor . domain_name = local . get ( 'domain-name' , _domainname ( ) ) #NEWLINE# neighbor . md5_password = local . get ( 'md5-password' , None ) #NEWLINE# neighbor . md5_ip = local . get ( 'md5-ip' , neighbor . local_address ) #NEWLINE# neighbor . description = local . get ( 'description' , '' ) #NEWLINE# neighbor . flush = local . get ( 'auto-flush' , True ) #NEWLINE# neighbor . adjribout = local . get ( 'adj-rib-out' , True ) #NEWLINE# neighbor . aigp = local . get ( 'aigp' , None ) #NEWLINE# neighbor . ttl_out = local . get ( 'outgoing-ttl' , None ) #NEWLINE# neighbor . ttl_in = local . get ( 'incoming-ttl' , None ) #NEWLINE# neighbor . group_updates = local . get ( 'group-updates' , True ) #NEWLINE# neighbor . manual_eor = local . get ( 'manual-eor' , False ) #NEWLINE# neighbor . api = ParseAPI . extract ( ) #NEWLINE# capability = local . get ( 'capability' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# neighbor . add_path = capability . get ( 'add-path' , 0 ) #NEWLINE# neighbor . asn4 = capability . get ( 'asn4' , True ) #NEWLINE# neighbor . multisession = capability . get ( 'multi-session' , False ) #NEWLINE# neighbor . operational = capability . get ( 'operational' , False ) #NEWLINE# neighbor . route_refresh = capability . get ( 'route-refresh' , 0 ) #NEWLINE# if ( capability . get ( 'graceful-restart' , False ) is not False ) : #NEWLINE# #INDENT# neighbor . graceful_restart = ( capability . get ( 'graceful-restart' , 0 ) or int ( neighbor . hold_time ) ) #NEWLINE# #UNINDENT# families = [ ] #NEWLINE# for family in ParseFamily . convert . keys ( ) : #NEWLINE# #INDENT# for pair in local . get ( 'family' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( family , [ ] ) : #NEWLINE# #INDENT# families . append ( pair ) #NEWLINE# #UNINDENT# #UNINDENT# families = ( families or NLRI . known_families ( ) ) #NEWLINE# if ( ( AFI . ipv4 , SAFI . unicast ) not in families ) : #NEWLINE# #INDENT# families . append ( ( AFI ( AFI . ipv4 ) , SAFI ( SAFI . unicast ) ) ) #NEWLINE# #UNINDENT# for family in families : #NEWLINE# #INDENT# neighbor . add_family ( family ) #NEWLINE# #UNINDENT# neighbor . changes = [ ] #NEWLINE# for section in ( 'static' , 'l2vpn' , 'flow' ) : #NEWLINE# #INDENT# routes = local . get ( section , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( 'routes' , [ ] ) #NEWLINE# for route in routes : #NEWLINE# #INDENT# route . nlri . action = OUT . ANNOUNCE #NEWLINE# #UNINDENT# neighbor . changes . extend ( routes ) #NEWLINE# #UNINDENT# messages = local . get ( 'operational' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( 'routes' , [ ] ) #NEWLINE# if ( not neighbor . router_id ) : #NEWLINE# #INDENT# neighbor . router_id = neighbor . local_address #NEWLINE# #UNINDENT# if neighbor . route_refresh : #NEWLINE# #INDENT# if neighbor . adjribout : #NEWLINE# #INDENT# self . logger . configuration ( 'route-refresh requested, enabling adj-rib-out' ) #NEWLINE# #UNINDENT# #UNINDENT# missing = neighbor . missing ( ) #NEWLINE# if missing : #NEWLINE# #INDENT# return self . error . set ( ( 'incomplete neighbor, missing %s' % missing ) ) #NEWLINE# #UNINDENT# if ( neighbor . local_address . afi != neighbor . peer_address . afi ) : #NEWLINE# #INDENT# return self . error . set ( 'local-address and peer-address must be of the same family' ) #NEWLINE# #UNINDENT# if ( neighbor . peer_address . top ( ) in self . _neighbors ) : #NEWLINE# #INDENT# return self . error . set ( ( 'duplicate peer definition %s' % neighbor . peer_address . top ( ) ) ) #NEWLINE# #UNINDENT# self . _neighbors . append ( neighbor . peer_address . top ( ) ) #NEWLINE# for change in neighbor . changes : #NEWLINE# #INDENT# family = change . nlri . family ( ) #NEWLINE# if ( ( family not in families ) and ( family != ( AFI . ipv4 , SAFI . unicast ) ) ) : #NEWLINE# #INDENT# return self . error . set ( ( 'Trying to announce a route of type %s,%s when we are not announcing the family to our peer' % change . nlri . family ( ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# def _init_neighbor( neighbor ) : #NEWLINE# #INDENT# families = neighbor . families ( ) #NEWLINE# for change in neighbor . changes : #NEWLINE# #INDENT# if ( change . nlri . family ( ) in families ) : #NEWLINE# #INDENT# neighbor . rib . outgoing . insert_announced_watchdog ( change ) #NEWLINE# #UNINDENT# #UNINDENT# for message in messages : #NEWLINE# #INDENT# if ( message . family ( ) in families ) : #NEWLINE# #INDENT# if ( message . name == 'ASM' ) : #NEWLINE# #INDENT# neighbor . asm [ message . family ( ) ] = message #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# neighbor . messages . append ( message ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . neighbors [ neighbor . name ( ) ] = neighbor #NEWLINE# #UNINDENT# if ( neighbor . multisession and ( len ( neighbor . families ( ) ) > 1 ) ) : #NEWLINE# #INDENT# for family in neighbor . families ( ) : #NEWLINE# #INDENT# m_neighbor = deepcopy ( neighbor ) #NEWLINE# m_neighbor . make_rib ( ) #NEWLINE# m_neighbor . rib . outgoing . families = [ family ] #NEWLINE# _init_neighbor ( m_neighbor ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# neighbor . make_rib ( ) #NEWLINE# _init_neighbor ( neighbor ) #NEWLINE# #UNINDENT# return True