#NEWLINE# @ utils . synchronized ( 'lock_gateway' , external = True ) #NEWLINE# def initialize_gateway_device( dev , network_ref ) : #NEWLINE# #INDENT# if ( not network_ref ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# _enable_ipv4_forwarding ( ) #NEWLINE# try : #NEWLINE# #INDENT# prefix = network_ref . cidr . prefixlen #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# prefix = network_ref [ 'cidr' ] . rpartition ( '/' ) [ 2 ] #NEWLINE# #UNINDENT# full_ip = ( '%s/%s' % ( network_ref [ 'dhcp_server' ] , prefix ) ) #NEWLINE# new_ip_params = [ [ full_ip , 'brd' , network_ref [ 'broadcast' ] ] ] #NEWLINE# old_ip_params = [ ] #NEWLINE# ( out , err ) = _execute ( 'ip' , 'addr' , 'show' , 'dev' , dev , 'scope' , 'global' ) #NEWLINE# for line in out . split ( '\n' ) : #NEWLINE# #INDENT# fields = line . split ( ) #NEWLINE# if ( fields and ( fields [ 0 ] == 'inet' ) ) : #NEWLINE# #INDENT# if ( fields [ ( - 2 ) ] in ( 'secondary' , 'dynamic' ) ) : #NEWLINE# #INDENT# ip_params = fields [ 1 : ( - 2 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ip_params = fields [ 1 : ( - 1 ) ] #NEWLINE# #UNINDENT# old_ip_params . append ( ip_params ) #NEWLINE# if ( ip_params [ 0 ] != full_ip ) : #NEWLINE# #INDENT# new_ip_params . append ( ip_params ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( ( not old_ip_params ) or ( old_ip_params [ 0 ] [ 0 ] != full_ip ) ) : #NEWLINE# #INDENT# old_routes = [ ] #NEWLINE# result = _execute ( 'ip' , 'route' , 'show' , 'dev' , dev ) #NEWLINE# if result : #NEWLINE# #INDENT# ( out , err ) = result #NEWLINE# for line in out . split ( '\n' ) : #NEWLINE# #INDENT# fields = line . split ( ) #NEWLINE# if ( fields and ( 'via' in fields ) ) : #NEWLINE# #INDENT# old_routes . append ( fields ) #NEWLINE# _execute ( 'ip' , 'route' , 'del' , fields [ 0 ] , 'dev' , dev , run_as_root = True ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for ip_params in old_ip_params : #NEWLINE# #INDENT# _execute ( * _ip_bridge_cmd ( 'del' , ip_params , dev ) , run_as_root = True , check_exit_code = [ 0 , 2 , 254 ] ) #NEWLINE# #UNINDENT# for ip_params in new_ip_params : #NEWLINE# #INDENT# _execute ( * _ip_bridge_cmd ( 'add' , ip_params , dev ) , run_as_root = True , check_exit_code = [ 0 , 2 , 254 ] ) #NEWLINE# #UNINDENT# for fields in old_routes : #NEWLINE# #INDENT# _execute ( 'ip' , 'route' , 'add' , * fields , run_as_root = True ) #NEWLINE# #UNINDENT# if ( CONF . send_arp_for_ha and ( CONF . send_arp_for_ha_count > 0 ) ) : #NEWLINE# #INDENT# send_arp_for_ip ( network_ref [ 'dhcp_server' ] , dev , CONF . send_arp_for_ha_count ) #NEWLINE# #UNINDENT# #UNINDENT# if CONF . use_ipv6 : #NEWLINE# #INDENT# _execute ( 'ip' , '-f' , 'inet6' , 'addr' , 'change' , network_ref [ 'cidr_v6' ] , 'dev' , dev , run_as_root = True )