Skip to content

Commit 33e1dde

Browse files
committed
Show IPv6 address in the full table
1 parent 84d2773 commit 33e1dde

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

hostedpi/cli/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Option("--launchpad", "--lp", help="Launchpad usernames to source SSH keys from"),
2424
]
2525
ipv6 = Annotated[bool, Option(help="Use the IPv6 connection method")]
26+
numeric = Annotated[bool, Option("-n", help="Use numeric IPv6 address in SSH command")]
2627
yes = Annotated[bool, Option("--yes", "-y", help="Proceed without confirmation")]
2728
number = Annotated[Union[int, None], Option(help="Number of Raspberry Pi servers to create", min=1)]
2829
full_table = Annotated[bool, Option(help="Show full table of Raspberry Pi server info")]

hostedpi/cli/ssh.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212

1313
@ssh_app.command("command")
14-
def do_command(name: arguments.server_name, ipv6: options.ipv6 = False):
14+
def do_command(
15+
name: arguments.server_name, ipv6: options.ipv6 = False, numeric: options.numeric = False
16+
):
1517
"""
1618
Get the SSH command to connect to a Raspberry Pi server
1719
"""
@@ -21,7 +23,10 @@ def do_command(name: arguments.server_name, ipv6: options.ipv6 = False):
2123
raise Exit(1)
2224
try:
2325
if ipv6:
24-
print(pi.ipv6_ssh_command)
26+
if numeric:
27+
print(pi.ipv6_ssh_command_numeric)
28+
else:
29+
print(pi.ipv6_ssh_command)
2530
else:
2631
print(pi.ipv4_ssh_command)
2732
except HostedPiException as exc:
@@ -34,6 +39,7 @@ def do_config(
3439
names: arguments.server_names = None,
3540
filter: options.filter_pattern_pi = None,
3641
ipv6: options.ipv6 = False,
42+
numeric: options.numeric = False,
3743
):
3844
"""
3945
Get the SSH config to connect to one or more Raspberry Pi servers
@@ -42,7 +48,10 @@ def do_config(
4248
for pi in pis:
4349
try:
4450
if ipv6:
45-
print(pi.ipv6_ssh_config)
51+
if numeric:
52+
print(pi.ipv6_ssh_config_numeric)
53+
else:
54+
print(pi.ipv6_ssh_config)
4655
else:
4756
print(pi.ipv4_ssh_config)
4857
except HostedPiException as exc:

hostedpi/cli/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def full_pis_table(pis: list[Pi]):
8989
"Status",
9090
"Initialised keys",
9191
"IPv4 SSH port",
92+
"IPv6 Address",
9293
]
9394
table = Table(*headers)
9495

@@ -104,6 +105,7 @@ def full_pis_table(pis: list[Pi]):
104105
pi.status,
105106
format.boolean(pi.initialised_keys),
106107
str(pi.ipv4_ssh_port),
108+
pi.ipv6_address.compressed,
107109
)
108110

109111

hostedpi/pi.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,24 +267,32 @@ 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 SSH command required to connect to the Pi using SSH over IPv4
278278
"""
279279
return f"ssh -p {self.ipv4_ssh_port} root@{self.ipv4_ssh_hostname}"
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 SSH command required to connect to the Pi using SSH over IPv6
285285
"""
286286
return f"ssh root@{self.ipv6_ssh_hostname}"
287287

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}]"
295+
288296
@property
289297
def ipv4_ssh_config(self) -> str:
290298
"""

0 commit comments

Comments
 (0)