Skip to content

Commit bf096ec

Browse files
committed
virtme-ng: introduce --console and --ssh shortcuts
Simplify the remote console and ssh options for the vng front-end: - to start a console or ssh server: $ vng --console [PORT] $ vng --ssh [PORT] - to start a console or ssh client session: $ vng --console-client [PORT] $ vng --ssh-client [PORT] Signed-off-by: Andrea Righi <arighi@nvidia.com>
1 parent 4b0c48d commit bf096ec

File tree

2 files changed

+74
-36
lines changed

2 files changed

+74
-36
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ Requirements
129129
* Optionally, you may need virtiofsd 1.7.0 (or higher) for better filesystem
130130
performance inside the virtme-ng guests.
131131

132-
* Optionally, you may need `socat` for the `--server` and `--client` options,
133-
and the host's kernel should support VSOCK (`CONFIG_VHOST_VSOCK`).
132+
* Optionally, you may need `socat` for the `--console` and
133+
`--console-client` options, and the host's kernel should support VSOCK
134+
(`CONFIG_VHOST_VSOCK`).
135+
136+
* Optionally, you may need `sshd` installed for the `--ssh` and
137+
`--ssh-client` options.
134138

135139
Examples
136140
========
@@ -382,26 +386,26 @@ Examples
382386
- Connect to a simple remote shell (`socat` is required, VSOCK will be used):
383387
```
384388
# Start the vng instance with server support:
385-
$ vng --server
389+
$ vng --console
386390
387391
# In a separate terminal run the following command to connect to a remote shell:
388-
$ vng --client
392+
$ vng --console-client
389393
```
390394

391395
- Enable ssh in the vng guest:
392396
```
393397
# Start the vng instance with ssh server support:
394-
$ vng --server ssh
398+
$ vng --ssh
395399
396400
# Connect to the vng guest from the host via ssh:
397-
$ vng --client ssh
401+
$ vng --ssh-client
398402
```
399403

400404
- Generate some results inside the vng guest and copy them back to the
401405
host using scp:
402406
```
403407
# Start the vng instance with SSH server support:
404-
arighi@host~> vng --server ssh
408+
arighi@host~> vng --ssh
405409
...
406410
arighi@virtme-ng~> ./run.sh > result.txt
407411

virtme_ng/run.py

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -487,32 +487,46 @@ def make_parser():
487487
)
488488

489489
g_remote = parser.add_argument_group(title="Remote Console")
490-
cli_srv_choices = ["console", "ssh"]
491490

492491
g_remote.add_argument(
493-
"--server",
492+
"--console",
494493
action="store",
495-
const=cli_srv_choices[0],
496494
nargs="?",
497-
choices=cli_srv_choices,
498-
help="Enable a server to communicate later from the host to the device using '--client'. "
495+
type=int,
496+
const=2222,
497+
metavar="PORT",
498+
help="Enable a server to communicate later from the host using '--console-client'. "
499499
+ "By default, a simple console will be offered using a VSOCK connection, and 'socat' for the proxy."
500500
)
501501

502502
g_remote.add_argument(
503-
"--client",
503+
"--console-client",
504504
action="store",
505-
const=cli_srv_choices[0],
506505
nargs="?",
507-
choices=cli_srv_choices,
508-
help="Connect to a VM launched with the '--server' option for a remote control.",
506+
type=int,
507+
const=2222,
508+
metavar="PORT",
509+
help="Connect to a VM launched with the '--console' option for a remote control.",
509510
)
510511

511512
g_remote.add_argument(
512-
"--port",
513+
"--ssh",
513514
action="store",
515+
nargs="?",
514516
type=int,
515-
help="Unique port to communicate with a VM.",
517+
const=2222,
518+
metavar="PORT",
519+
help="Enable SSH server to communicate later from the host to using '--ssh-client'."
520+
)
521+
522+
g_remote.add_argument(
523+
"--ssh-client",
524+
action="store",
525+
nargs="?",
526+
type=int,
527+
const=2222,
528+
metavar="PORT",
529+
help="Connect to a VM launched with the '--ssh' option for a remote control.",
516530
)
517531

518532
g_remote.add_argument(
@@ -992,23 +1006,41 @@ def _get_virtme_net_mac_address(self, args):
9921006
else:
9931007
self.virtme_param["net_mac_address"] = ""
9941008

995-
def _get_virtme_server(self, args):
996-
if args.server is not None:
997-
self.virtme_param["server"] = "--server " + args.server
1009+
def _get_virtme_console(self, args):
1010+
if args.console is not None:
1011+
self.virtme_param["console"] = f"--server console --port {args.console}"
9981012
else:
999-
self.virtme_param["server"] = ""
1013+
self.virtme_param["console"] = ""
10001014

1001-
def _get_virtme_client(self, args):
1002-
if args.client is not None:
1003-
self.virtme_param["client"] = "--client " + args.client
1015+
def _get_virtme_console_client(self, args):
1016+
if args.console_client is not None:
1017+
self.virtme_param["console_client"] = f"--client console --port {args.console_client}"
10041018
else:
1005-
self.virtme_param["client"] = ""
1019+
self.virtme_param["console_client"] = ""
1020+
1021+
def _get_virtme_ssh(self, args):
1022+
if args.console is not None and args.ssh is not None:
1023+
arg_fail('--console cannot be used with --ssh', show_usage=False)
1024+
1025+
if args.ssh is not None and args.root is not None:
1026+
arg_fail('--ssh is not currently compatible with --root', show_usage=False)
1027+
1028+
if args.ssh is not None and args.rw:
1029+
arg_fail('--ssh is not currently compatible with --rw', show_usage=False)
1030+
1031+
if args.ssh is not None:
1032+
self.virtme_param["ssh"] = f"--server ssh --port {args.ssh}"
1033+
else:
1034+
self.virtme_param["ssh"] = ""
1035+
1036+
def _get_virtme_ssh_client(self, args):
1037+
if args.console_client is not None and args.ssh_client is not None:
1038+
arg_fail('--console-client cannot be used with --ssh-client', show_usage=False)
10061039

1007-
def _get_virtme_port(self, args):
1008-
if args.port is not None:
1009-
self.virtme_param["port"] = "--port " + str(args.port)
1040+
if args.ssh_client is not None:
1041+
self.virtme_param["ssh_client"] = f"--client ssh --port {args.ssh_client}"
10101042
else:
1011-
self.virtme_param["port"] = ""
1043+
self.virtme_param["ssh_client"] = ""
10121044

10131045
def _get_virtme_remote_cmd(self, args):
10141046
if args.remote_cmd is not None:
@@ -1190,9 +1222,10 @@ def run(self, args):
11901222
self._get_virtme_mods(args)
11911223
self._get_virtme_network(args)
11921224
self._get_virtme_net_mac_address(args)
1193-
self._get_virtme_server(args)
1194-
self._get_virtme_client(args)
1195-
self._get_virtme_port(args)
1225+
self._get_virtme_console(args)
1226+
self._get_virtme_console_client(args)
1227+
self._get_virtme_ssh(args)
1228+
self._get_virtme_ssh_client(args)
11961229
self._get_virtme_remote_cmd(args)
11971230
self._get_virtme_disk(args)
11981231
self._get_virtme_sound(args)
@@ -1234,9 +1267,10 @@ def run(self, args):
12341267
+ f'{self.virtme_param["mods"]} '
12351268
+ f'{self.virtme_param["network"]} '
12361269
+ f'{self.virtme_param["net_mac_address"]} '
1237-
+ f'{self.virtme_param["server"]} '
1238-
+ f'{self.virtme_param["client"]} '
1239-
+ f'{self.virtme_param["port"]} '
1270+
+ f'{self.virtme_param["console"]} '
1271+
+ f'{self.virtme_param["console_client"]} '
1272+
+ f'{self.virtme_param["ssh"]} '
1273+
+ f'{self.virtme_param["ssh_client"]} '
12401274
+ f'{self.virtme_param["remote_cmd"]} '
12411275
+ f'{self.virtme_param["disk"]} '
12421276
+ f'{self.virtme_param["sound"]} '

0 commit comments

Comments
 (0)