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

scripting : add vm registry suite #6977

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

naveenrajm7
Copy link
Contributor

Fixes #6899

The registry suite is used to read and update vm registry.
All configs saved to disk is exposed by Configuration suite, similarly those that are not saved to disk are stored in RegistryEntry of a VM, they will now be exposed by Registry suite.

Users will now be able to give UTM→QEMU access to their custom path by updating registry, which can then be used in qemu additional args.

Added

  • UTMScriptingRegistryEntryImpl will control what will be exposed from RegistryEntry to scripting bridge, currently only shared directory is exposed in the form of [URL].

    Since we have a separate suite for handling registry , this suite can grow on what will be exposed. Eg: externalDrives (Not everything in RegistryEntry is suitable to be exposed)

  • Added file urls to qemu addtional args, QEMU launcher looks at file urls of args to collect required resources. These files urls are not stored to the disk, meaning they will be lost .

    However, they exists only for QEMU to figure out permission for these resources. Since the permission should actually come from registry, it is okay to lose these entries in qemu args.

Usage: Registry Suite

registry_add.applescript

on run argv
  set vmName to item 1 of argv
  -- Define the directory path
  set dir1Path to POSIX file "/Users/utm/Dir1"
  set dir2Path to POSIX file "/Users/utm/Dir2"

  tell application "UTM"
      set vm to virtual machine named vmName
      
      -- get current registry
      set reg to registry of vm
      -- add new entries
      set newEntry to {dir1Path,dir2Path}
      set reg to reg & newEntry
      -- update registry  ( No need for the VM to be stopped )
      update registry of vm with reg -- QEMU now has access to Dir1, Dir2
  end tell
end run

osascript registry_add.applescript testVM

Example use-case for registry: directory share

on run argv
    set vmName to item 1 of argv
     -- share id to support multiple shares and avoid conflict with UTM's default share (id=0)
    set dirId to "1" 
    set dirPath to "/Users/utm/Dir1"
    set dirURL to POSIX file dirPath
    
    -- Prepare the QEMU argument strings
    set fsdevArgStr to "-fsdev local,id=virtfs" & dirId & ",path=" & dirPath & ",security_model=mapped-xattr"
    set deviceArgStr to "-device virtio-9p-pci,fsdev=virtfs" & dirId & ",mount_tag=share" & dirId

    tell application "UTM"
        -- Get the VM and its configuration
        set vm to virtual machine named vmName
        set config to configuration of vm

        -- Get the current QEMU additional arguments
        set qemuAddArgs to qemu additional arguments of config

        -- Add the new arguments to the existing ones
        set end of qemuAddArgs to {argument string:fsdevArgStr, file urls:{dirURL}}
        set end of qemuAddArgs to {argument string:deviceArgStr}

        -- Update the configuration with the new arguments list
        set qemu additional arguments of config to qemuAddArgs
        update configuration of vm with config
				
	-- Give UTM access to the shared directory by updating registry
        -- Get the current directory shares in registry
        set reg to registry of vm
        -- Add new directory shares to the registry
        set reg to reg & {dirURL}
        -- Update registry of vm with new directory shares
        update registry of vm with reg
	
    end tell
end run

Mount inside VM

sudo mkdir -p /mnt/share1
sudo mount -t 9p -o trans=virtio,version=9p2000.L share1 /mnt/share1

* file urls is a list of file
* file urls are not saved to the disk (config.plist)
* QEMU launcher looks at file urls of args to collect required resources
* QEMU uses file URLs to access its corresponding bookmark
* The permissions of these urls is not handled as part of config update (ConfigImpl) , they should be handled at VM level(VMImpl) to update registryEntry of each VM
The registry suite is used to read and update vm registry.
All configs saved to disk is exposed by Configuration suite,
similarly those that are not saved to disk are stored in RegistryEntry
 will now be exposed by Registry suite.
  - UTMScriptingRegistryEntryImpl will control what will be exposed from RegistryEntry to scripting bridge, currently only shared directory is exposed in the form of [URL]
  - expose UTMQemuVirtualMachine.system as public to be used in Scripting
  - Add UTMRegistryEntry.appendSharedDirectory to support multiple directory shares.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scripting: add sandbox permission to custom path through applescript
1 participant