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 15, 2025
1 parent 28b1247 commit d83ffa0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/middlewared/middlewared/apps/webshell_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,10 @@ async def run(self, ws, origin, conndata):
"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"
)
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
7 changes: 4 additions & 3 deletions src/middlewared/middlewared/plugins/virt/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,11 @@ def get_shell(self, id):

self.middleware.call_sync('virt.global.check_initialized')
instance = self.middleware.call_sync('virt.instance.get_instance', id)
if instance['type'] != 'CONTAINER':
raise CallError('Only available for containers.')
if instance['status'] != 'RUNNING':
raise CallError('Container must be running.')
raise CallError('Virt instance must be running.')
if instance['type'] != 'CONTAINER':
return None

config = self.middleware.call_sync('virt.global.config')
mount_info = self.middleware.call_sync(
'filesystem.mount_info', [['mount_source', '=', f'{config["dataset"]}/containers/{id}']]
Expand Down

0 comments on commit d83ffa0

Please sign in to comment.