@@ -267,46 +267,39 @@ def ipv4_ssh_hostname(self) -> str:
267267 @property
268268 def ipv6_ssh_hostname (self ) -> str :
269269 """
270- The hostname to use when connecting to the Pi over SSH using IPv6
270+ The hostname to use when connecting to the Pi using SSH over IPv6
271271 """
272272 return self .hostname
273273
274274 @property
275275 def ipv4_ssh_command (self ) -> str :
276276 """
277- The SSH command required to connect to the Pi over SSH using IPv4
277+ The default SSH command required to connect to the Pi using SSH over IPv4
278278 """
279- return f"ssh -p { self .ipv4_ssh_port } root@ { self . ipv4_ssh_hostname } "
279+ return self .get_ipv4_ssh_command ()
280280
281281 @property
282282 def ipv6_ssh_command (self ) -> str :
283283 """
284- The SSH command required to connect to the Pi over SSH using IPv6
284+ The default SSH command required to connect to the Pi using SSH over IPv6
285285 """
286- return f"ssh root@ { self .ipv6_ssh_hostname } "
286+ return self .get_ipv6_ssh_command ()
287287
288288 @property
289289 def ipv4_ssh_config (self ) -> str :
290290 """
291- A string containing the IPv4 SSH config for the Pi. The contents could be added to an SSH
292- config file for easy access to the Pi.
291+ A string containing the default IPv4 SSH config for the Pi. The contents could be added to
292+ an SSH config file for easy access to the Pi.
293293 """
294- return f"""Host { self .name }
295- user root
296- port { self .ipv4_ssh_port }
297- hostname { self .ipv4_ssh_hostname }
298- """ .strip ()
294+ return self .get_ipv4_ssh_config ()
299295
300296 @property
301297 def ipv6_ssh_config (self ) -> str :
302298 """
303- A string containing the IPv6 SSH config for the Pi. The contents could be added to an SSH
304- config file for easy access to the Pi.
299+ A string containing the default IPv6 SSH config for the Pi. The contents could be added to
300+ an SSH config file for easy access to the Pi.
305301 """
306- return f"""Host { self .name }
307- user root
308- hostname { self .ipv6_ssh_hostname }
309- """ .strip ()
302+ return self .get_ipv6_ssh_config ()
310303
311304 @property
312305 def url (self ) -> str :
@@ -504,6 +497,48 @@ def cancel(self):
504497
505498 self ._cancelled = True
506499
500+ def get_ipv4_ssh_command (self , user : str = "root" ) -> str :
501+ """
502+ Construct an SSH command required to connect to the Pi using SSH over IPv4
503+ """
504+ return f"ssh -p { self .ipv4_ssh_port } { user } @{ self .ipv4_ssh_hostname } "
505+
506+ def get_ipv6_ssh_command (self , * , user : str = "root" , numeric : bool = False ) -> str :
507+ """
508+ Construct an SSH command required to connect to the Pi using SSH over IPv6
509+ """
510+ if numeric :
511+ return f"ssh { user } @[{ self .ipv6_address .compressed } ]"
512+ else :
513+ return f"ssh { user } @{ self .ipv6_ssh_hostname } "
514+
515+ def get_ipv4_ssh_config (self , user : str = "root" ) -> str :
516+ """
517+ Construct a string containing the IPv4 SSH config for the Pi. The contents could be added to
518+ an SSH config file for easy access to the Pi.
519+ """
520+ return f"""Host { self .name }
521+ user { user }
522+ port { self .ipv4_ssh_port }
523+ hostname { self .ipv4_ssh_hostname }
524+ """ .strip ()
525+
526+ def get_ipv6_ssh_config (
527+ self ,
528+ * ,
529+ user : str = "root" ,
530+ numeric : bool = False ,
531+ ) -> str :
532+ """
533+ Construct a string containing the SSH config for the Pi. The contents could be added to an
534+ SSH config file for easy access to the Pi.
535+ """
536+ hostname = self .ipv6_address .compressed if numeric else self .ipv6_ssh_hostname
537+ return f"""Host { self .name }
538+ user { user }
539+ hostname { hostname }
540+ """ .strip ()
541+
507542 def add_ssh_keys (self , ssh_keys : SSHKeySources ) -> set [str ]:
508543 """
509544 Add SSH keys to the Pi from the specified sources.
0 commit comments