Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-133483 / 25.04 / Expose VM virt shells for consumption #15398

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading