#NEWLINE# def _TermletToStr( self , filter_name , action , proto , saddr , sport , daddr , dport , icmp_type , option ) : #NEWLINE# #INDENT# "Take the various compenents and turn them into a cisco acl line.\n\n    Args:\n      action: str, action\n      proto: str, protocl\n      saddr: str or ipaddr, source address\n      sport: str list or none, the source port\n      daddr: str or ipaddr, the destination address\n      dport: str list or none, the destination port\n      icmp_type: icmp-type numeric specification (if any)\n      option: list or none, optional, eg. 'logging' tokens.\n\n    Returns:\n      string of the cisco acl line, suitable for printing.\n    " #NEWLINE# if ( ( type ( saddr ) is nacaddr . IPv4 ) or ( type ( saddr ) is ipaddr . IPv4Network ) ) : #NEWLINE# #INDENT# if ( saddr . numhosts > 1 ) : #NEWLINE# #INDENT# saddr = ( '%s %s' % ( saddr . ip , saddr . netmask ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# saddr = ( 'host %s' % saddr . ip ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( type ( daddr ) is nacaddr . IPv4 ) or ( type ( daddr ) is ipaddr . IPv4Network ) ) : #NEWLINE# #INDENT# if ( daddr . numhosts > 1 ) : #NEWLINE# #INDENT# daddr = ( '%s %s' % ( daddr . ip , daddr . netmask ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# daddr = ( 'host %s' % daddr . ip ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( type ( saddr ) is nacaddr . IPv6 ) or ( type ( saddr ) is ipaddr . IPv6Network ) ) : #NEWLINE# #INDENT# if ( saddr . numhosts > 1 ) : #NEWLINE# #INDENT# saddr = ( '%s/%s' % ( saddr . ip , saddr . prefixlen ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# saddr = ( 'host %s' % saddr . ip ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( type ( daddr ) is nacaddr . IPv6 ) or ( type ( daddr ) is ipaddr . IPv6Network ) ) : #NEWLINE# #INDENT# if ( daddr . numhosts > 1 ) : #NEWLINE# #INDENT# daddr = ( '%s/%s' % ( daddr . ip , daddr . prefixlen ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# daddr = ( 'host %s' % daddr . ip ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not sport ) : #NEWLINE# #INDENT# sport = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( sport [ 0 ] != sport [ 1 ] ) : #NEWLINE# #INDENT# sport = ( ' range %s %s' % ( self . _TermPortToProtocol ( sport [ 0 ] , proto ) , self . _TermPortToProtocol ( sport [ 1 ] , proto ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sport = ( ' eq %s' % self . _TermPortToProtocol ( sport [ 0 ] , proto ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not dport ) : #NEWLINE# #INDENT# dport = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dport [ 0 ] != dport [ 1 ] ) : #NEWLINE# #INDENT# dport = ( ' range %s %s' % ( self . _TermPortToProtocol ( dport [ 0 ] , proto ) , self . _TermPortToProtocol ( dport [ 1 ] , proto ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# dport = ( ' eq %s' % self . _TermPortToProtocol ( dport [ 0 ] , proto ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not option ) : #NEWLINE# #INDENT# option = [ '' ] #NEWLINE# #UNINDENT# sane_options = list ( option ) #NEWLINE# if ( ( proto == 'udp' ) and ( 'established' in sane_options ) ) : #NEWLINE# #INDENT# sane_options . remove ( 'established' ) #NEWLINE# #UNINDENT# ret_lines = [ ] #NEWLINE# icmp_type = str ( self . _TermPortToProtocol ( icmp_type , 'icmp' ) ) #NEWLINE# ret_lines . append ( ( 'access-list %s extended  %s %s %s %s %s %s %s %s' % ( filter_name , action , proto , saddr , sport , daddr , dport , icmp_type , ' ' . join ( sane_options ) ) ) ) #NEWLINE# stripped_ret_lines = [ re . sub ( '\\s+' , ' ' , x ) . rstrip ( ) for x in ret_lines ] #NEWLINE# return stripped_ret_lines