Skip to content

Commit

Permalink
Expose VM virt shells for consumption (#15398)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 authored Jan 16, 2025
1 parent e641739 commit e6b7bc4
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/middlewared/middlewared/apps/webshell_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ def get_command(self, username, as_root, options):
elif options.get("virt_instance_id"):
command = [
"/usr/bin/incus",
"exec",
options["virt_instance_id"],
options["command"],
"console" if options.get("use_console") else "exec",
options["virt_instance_id"]
]
if options.get("command"):
command.append(options["command"])
if not as_root:
command = ["/usr/bin/sudo", "-H", "-u", username] + command
return command, not as_root
Expand Down Expand Up @@ -277,17 +278,23 @@ async def run(self, ws, origin, conndata):
)
if options.get("virt_instance_id"):
try:
await self.middleware.call(
virt_instance = await self.middleware.call(
"virt.instance.get_instance", options["virt_instance_id"]
)
if not options.get("command"):
options["command"] = (
await self.middleware.call(
"virt.instance.get_shell",
options["virt_instance_id"],
)
or "/bin/sh"
)
options["instance_type"] = virt_instance["type"]
if virt_instance["type"] == "VM":
if virt_instance["status"] != "RUNNING":
raise CallError("Virt instance must be running.")
options.setdefault("use_console", True)
if options["use_console"]:
options["command"] = None
else:
options["command"] = options.get("command") or "/bin/sh"
elif not options.get("command"):
command = await self.middleware.call("virt.instance.get_shell", options["virt_instance_id"])
if not command:
command = "/bin/sh"
options["command"] = command
except InstanceNotFound:
raise CallError("Provided instance id is not valid")
if options.get("app_name"):
Expand Down

0 comments on commit e6b7bc4

Please sign in to comment.