Skip to content

Commit

Permalink
Expose VM virt shells for consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 committed Jan 16, 2025
1 parent 257f060 commit 5846dd3
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/middlewared/middlewared/apps/webshell_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ def get_command(self, username, as_root, options):
command = ["/usr/bin/sudo", "-H", "-u", username] + command
return command, not as_root
elif options.get("virt_instance_id"):
command = [
"/usr/bin/incus",
"exec",
options["virt_instance_id"],
options["command"],
]
command = ["/usr/bin/incus"]
if options["instance_type"] == "VM":
command += ["console", options["virt_instance_id"]]
else:
command += ["exec", options["virt_instance_id"], 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 +276,18 @@ 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.")
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 5846dd3

Please sign in to comment.