@@ -56,7 +56,7 @@ def get_ansible_inventory(self) -> Path:
5656 f"ansible_port={ self .vag .port ()} "
5757 f"ansible_user={ self .vag .user ()} "
5858 f"ansible_ssh_private_key_file={ self .vag .keyfile ()} "
59- f"ansible_ssh_common_args='-o StrictHostKeyChecking=no'" )
59+ f"ansible_ssh_common_args='-o StrictHostKeyChecking=no -oHostKeyAlgorithms=+ssh-rsa '" )
6060 f .write (data )
6161 return inventory
6262
@@ -70,7 +70,7 @@ def _update_netplan_config(self, netcfg: dict, netcfg_dest: str):
7070 self .ssh .run_command ("sudo netplan apply" )
7171 self .network_interface_initialized = True
7272
73- def set_network_interface_ip (self , router : VM | None = None ):
73+ def set_network_interface_ip_netplan (self , router : VM | None = None ):
7474 if self .network_interface_initialized :
7575 return
7676 yamls = self .ssh .run_command ("ls /etc/netplan" )
@@ -114,6 +114,33 @@ def set_routing(self, router: VM):
114114 self .ssh .run_command ("sudo sysctl net.ipv4.conf.all.accept_redirects=0" )
115115 self .ssh .run_command ("sudo sysctl net.ipv4.conf.default.accept_redirects=0" )
116116
117+ def set_network_interface_ip_ifupdown (self , router : VM | None = None ):
118+ # Download existing config
119+ netcfg_local = tempfile .NamedTemporaryFile ()
120+ self .ssh .download_file (netcfg_local .name , "/etc/network/interfaces" )
121+
122+ with open (netcfg_local .name , "r" ) as f :
123+ netcfg = f .read ()
124+
125+ netcfg = re .sub ('(iface eth1[^\r ]*address[ ]*)([0-9.]*)' ,
126+ f'\\ g<1>{ self .ip } ' , netcfg , flags = re .MULTILINE )
127+
128+ with open (netcfg_local .name , "w" ) as f :
129+ f .write (netcfg )
130+ self .ssh .upload_file (netcfg_local .name , "/tmp/interfaces" )
131+ self .ssh .run_command ("sudo mv /tmp/interfaces /etc/network/interfaces" )
132+ self .ssh .run_command ("sudo ifdown eth1; sudo ifup eth1" )
133+
134+
135+ def set_network_interface_ip (self , router : VM | None = None ):
136+ if self .net_backend is None or self .net_backend == 'netplan' :
137+ self .set_network_interface_ip_netplan (router )
138+ elif self .net_backend == 'ifupdown' :
139+ self .set_network_interface_ip_ifupdown (router )
140+ else :
141+ self .log .critical ("Unknown net backend %s" , self .net_backend )
142+ sys .exit (1 )
143+
117144 def start_api_tracing (self ):
118145 if not self .trace :
119146 return
0 commit comments