Skip to content

Commit 3587441

Browse files
SSH login by domain (#723)
1 parent 7d7ddcf commit 3587441

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

linodecli/plugins/ssh.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ def call(args, context): # pylint: disable=too-many-branches
5050
action="store_true",
5151
help="If given, uses the Linode's SLAAC address for SSH.",
5252
)
53+
parser.add_argument(
54+
"-d",
55+
action="store_true",
56+
help="If given, uses the Lindoe's domain name for SSH",
57+
)
5358

5459
parsed, args = parser.parse_known_args(args)
5560

@@ -147,4 +152,7 @@ def parse_target_address(
147152
if ip.startswith("192.168"):
148153
continue
149154

155+
if getattr(parsed, "d"):
156+
ip = ip.replace(".", "-") + ".ip.linodeusercontent.com"
157+
150158
return ip

tests/unit/test_plugin_ssh.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,17 @@ def test_parse_target_address():
187187
"ipv6": "c001:d00d::1337/128",
188188
}
189189

190-
test_namespace = argparse.Namespace(**{"6": False})
190+
test_namespace = argparse.Namespace(**{"6": False, "d": False})
191191

192192
address = plugin.parse_target_address(test_namespace, test_target)
193193
assert address == "123.123.123.123"
194194

195+
# Hack to work around invalid key
196+
setattr(test_namespace, "d", True)
197+
198+
address = plugin.parse_target_address(test_namespace, test_target)
199+
assert address == "123-123-123-123.ip.linodeusercontent.com"
200+
195201
# Hack to work around invalid key
196202
setattr(test_namespace, "6", True)
197203

0 commit comments

Comments
 (0)