@@ -274,58 +274,32 @@ def ipv6_ssh_hostname(self) -> str:
274274 @property
275275 def ipv4_ssh_command (self ) -> str :
276276 """
277- The SSH command required to connect to the Pi using SSH over 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 using SSH over 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 } "
287-
288- @property
289- def ipv6_ssh_command_numeric (self ) -> str :
290- """
291- The SSH command required to connect to the Pi using SSH over IPv6 (using the IPv6 address
292- rather than hostname)
293- """
294- return f"ssh root@[{ self .ipv6_address .compressed } ]"
286+ return self .get_ipv6_ssh_command ()
295287
296288 @property
297289 def ipv4_ssh_config (self ) -> str :
298290 """
299- A string containing the IPv4 SSH config for the Pi. The contents could be added to an SSH
300- 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.
301293 """
302- return f"""Host { self .name }
303- user root
304- port { self .ipv4_ssh_port }
305- hostname { self .ipv4_ssh_hostname }
306- """ .strip ()
294+ return self .get_ipv4_ssh_config ()
307295
308296 @property
309297 def ipv6_ssh_config (self ) -> str :
310298 """
311- A string containing the IPv6 SSH config for the Pi. The contents could be added to an SSH
312- 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.
313301 """
314- return f"""Host { self .name }
315- user root
316- hostname { self .ipv6_ssh_hostname }
317- """ .strip ()
318-
319- @property
320- def ipv6_ssh_config_numeric (self ) -> str :
321- """
322- A string containing the IPv6 SSH config for the Pi. The contents could be added to an SSH
323- config file for easy access to the Pi.
324- """
325- return f"""Host { self .name }
326- user root
327- hostname { self .ipv6_address .compressed }
328- """ .strip ()
302+ return self .get_ipv6_ssh_config ()
329303
330304 @property
331305 def url (self ) -> str :
@@ -523,6 +497,48 @@ def cancel(self):
523497
524498 self ._cancelled = True
525499
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+
526542 def add_ssh_keys (self , ssh_keys : SSHKeySources ) -> set [str ]:
527543 """
528544 Add SSH keys to the Pi from the specified sources.
0 commit comments