vagrant_utm 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3fb5b4444402858a94f7d14c05bcc536749f405e5fa7c4ea8c84656a9f2dbee
4
- data.tar.gz: 8e2c1b654f105d996504cc8c5f03276c421389fe414ff3c81c020bd0e4525179
3
+ metadata.gz: c22d83ed499aea91dd64bc9cdfa9f161a690e510e1e8c28fa9d912a2a0478606
4
+ data.tar.gz: c4f0be1c3eefa6d8412e60d7f193e00426462a34b90e34016539a75b34195da1
5
5
  SHA512:
6
- metadata.gz: 30371d09843505b8a0bf16f1e2c454470e9459b454b0dcd94b52a525a64a95f1d0bb61fb3ec7434c4cf9e37e3889b15542ba7aaa2d2ac6cc6b26a95ab4c4f8fe
7
- data.tar.gz: b6c93091338e29b4a41ad83c2e112e3c554384da447243ed3a4a45849e4779d7de9281cfd5b5a5b75958821db6c570ddb705c0c0162e98766100029bbc86ec9f
6
+ metadata.gz: 4539bf98ad765bb41946fc1b825e24161ad05e1e56b0b63416521c17c60ec182a78b6a5b6115fc8eea75879ba863c04468fe9881bd7996e928902fe7150198f1
7
+ data.tar.gz: 430329351ee74c943093194d6d64ce3e230bc8677153337e0f342a3f5c448f4b76bb390d51c6fe817f7cd09d1197185421bd7a97027b9f2869efff04cdada695
data/README.md CHANGED
@@ -15,9 +15,7 @@ vagrant plugin install vagrant_utm
15
15
 
16
16
  ```ruby
17
17
  Vagrant.configure("2") do |config|
18
- config.vm.provider :utm do |utm|
19
- utm.utm_file_url = "https://github.com/naveenrajm7/utm-box/releases/download/debian-11/debian_vagrant_utm.zip"
20
- end
18
+ config.vm.box = "utm/debian11"
21
19
  end
22
20
  ```
23
21
 
data/docs/_config.yml CHANGED
@@ -2,12 +2,11 @@ title: Vagrant UTM
2
2
  description: >-
3
3
  vagrant_utm is a Vagrant plugin which adds UTM provider to Vagrant,
4
4
  allowing Vagrant to control and provision machines via UTM's API
5
- baseurl: "/docs" # the subpath of your site, e.g. /blog
6
- # theme: just-the-docs
7
-
8
- url: "https://naveenrajm7.github.io/vagrant_utm"
5
+ baseurl: "/vagrant_utm" # the subpath of your site, e.g. /blog
6
+ url: "https://naveenrajm7.github.io" # the base hostname & protocol for your site, e.g. http://example.com
7
+ repository: naveenrajm7/vagrant_utm # for github-metadata
9
8
  github_username: naveenrajm7
10
- repository: naveenrajm7/vagrant_utm
9
+
11
10
 
12
11
  # Build settings
13
12
  remote_theme: just-the-docs/just-the-docs@v0.8.2
@@ -73,4 +72,4 @@ back_to_top: true
73
72
  back_to_top_text: "Back to top"
74
73
 
75
74
  # Footer
76
- footer_content: "Copyright &copy; 2024 Naveenraj Muthuraj. Distributed by an <a href=\"https://github.com/naveenrajm7/vagrant_utm/tree/main/LICENSE.txt\">MIT license.</a>"
75
+ footer_content: "Copyright &copy; 2024 Naveenraj Muthuraj. Distributed by an <a href=\"https://github.com/naveenrajm7/vagrant_utm/tree/main/LICENSE.txt\">MIT license.</a>"
@@ -8,15 +8,6 @@ nav_order: 2
8
8
 
9
9
  As with [every Vagrant Provider](https://developer.hashicorp.com/vagrant/docs/providers/basic_usage), the Vagrant UTM provider has a custom box format that is required to work with Vagrant and the UTM plugin.
10
10
 
11
- {: .important }
12
- The UTM bundle (.utm file) is the box format for Vagrant UTM provider.
13
- Because the current UTM API does not support importing utm file, we do not use vagrant box format (.box file).
14
- We currently use `utm://downloadVM?url=` to import VM to UTM.
15
-
16
-
17
- {: .note }
18
- However, once UTM supports import, we should be able to package UTM files into box format and use the benefits of Vagrant boxes . For example, downloading the box once to spin up multiple VMs and using vagrant cloud to publish custom UTM boxes.
19
-
20
11
 
21
12
  {: .warning }
22
13
  This is a reasonably advanced topic that a beginning user of Vagrant does not need to understand. If you are just getting started with Vagrant, skip this and use an [available box](/utm_box_gallery.md). If you are an experienced user of Vagrant and want to create your own custom boxes, this is for you.
@@ -46,25 +37,37 @@ Check the [UTM Guide on Guest Support](https://docs.getutm.app/guest-support/gue
46
37
  By satisfying the [general guidance on creating vagrant boxes](https://developer.hashicorp.com/vagrant/docs/boxes/base) and the above [Virtual Machine](#virtual-machine) requirements you can use your VM with Vagrant UTM plugin.
47
38
 
48
39
  Apart from manually building the boxes, you can also use the semi-automated way of building these boxes using [packer plugin for UTM](https://github.com/naveenrajm7/packer-plugin-utm).
49
- The packer plugin has a builder and a post processor, which uses an existing UTM file, adds Vagrant specific stuff and packs the UTM file as a zip so it can be used by UTM Vagrant plugin.
40
+ The packer plugin has the following components:
41
+ 1. Builder
42
+ 1. UTM - Use existing utm file
43
+ 2. ISO - Start from scratch using ISO files
44
+ 2. Post-processor
45
+ 1. ZIP - Package UTM VM into zip file
46
+ 2. Vagrant - Package UTM VM into vagrant box.
47
+
50
48
 
51
49
  Checkout [UTM Box Guide](https://github.com/naveenrajm7/utm-box/blob/main/HowToBuild/DebianUTM.md) to know how to build Box using packer.
52
50
 
53
- ## Using your own UTM boxes
51
+ ## Using your own UTM VMs
54
52
 
55
- Due to the limitation of UTM API, the plugin can only take a url pointing to the zip file.
56
- So, you can use a local python server to host your UTM bundle in zip file
53
+ Do you have your own UTM VM that you would like to use with Vagrant
57
54
 
55
+ 1. Convert your utm file to box format
56
+
57
+ a. Make a directory
58
+ b. Put utm vm file in it
59
+ c. Tar the folder with .box extension
60
+
61
+ 2. Import the vagrant box
58
62
  ```bash
59
- python3 -m http.server
60
- Serving HTTP on :: port 8000 (http://[::]:8000/) ...
63
+ vagrant box add --name custom/debian debian.box
61
64
  ```
62
65
 
63
- Use in Vagrantfile
66
+ 3. Use in Vagrantfile
64
67
  ```ruby
65
68
  Vagrant.configure("2") do |config|
66
- config.vm.provider :utm do |utm|
67
- utm.utm_file_url = "http://localhost:8000/debian_vagrant_utm.zip"
68
- end
69
+ config.vm.box = "custom/debian11"
69
70
  end
70
- ```
71
+ ```
72
+
73
+ You can also use [packer plugin for UTM](https://github.com/naveenrajm7/packer-plugin-utm) to build, package and publish your UTM VMs to HCP Vagrant registry and share it your teams or with the world.
@@ -1,117 +1,41 @@
1
1
  ---
2
- title: UTM box gallery
2
+ title: UTM Vagrant box gallery
3
3
  # layout: default
4
4
  parent: UTM Box
5
5
  nav_order: 1
6
6
  ---
7
7
 
8
- # UTM Box Gallery
8
+ # UTM Vagrant Box Gallery
9
9
 
10
10
  To work with Vagrant, a base VM (box) must have
11
- [certain features](https://developer.hashicorp.com/vagrant/docs/boxes/base), like a ssh user for vagrant to connect.
11
+ [certain features](https://developer.hashicorp.com/vagrant/docs/boxes/base), like an ssh user for vagrant to connect.
12
12
 
13
- To help you get started with Vagrant UTM provider, couple of pre-built VMs from the [UTM Gallery](https://mac.getutm.app/gallery/) are modified to work with Vagrant and are made available to use.
13
+ To help you get started with Vagrant UTM provider, a couple of pre-built VMs that work with Vagrant and are published in [HCP Vagrant registry](https://portal.cloud.hashicorp.com/vagrant/discover/utm).
14
14
 
15
+ {: .important}
16
+ All the VMs provided are built from [UTM Gallery VMs](https://mac.getutm.app/gallery/) or ISO in an (semi) automated way using [packer plugin for UTM][packer plugin for UTM]. Please see the [UTM Box Guide][UTM Box Guide] on how these UTM Vagrant boxes were built using packer.
15
17
 
16
18
  * Debian 11 (Xfce):
17
19
  ```ruby
18
- u.utm_file_url = https://github.com/naveenrajm7/utm-box/releases/download/debian-11/debian_vagrant_utm.zip
20
+ config.vm.box = "utm/debian11"
19
21
  ```
20
22
 
23
+ * Ubuntu 24.04 :
24
+ ```ruby
25
+ config.vm.box = "utm/ubuntu-24.04"
26
+ ```
27
+
28
+ * Help build more boxes using [packer plugin for UTM][packer plugin for UTM]
21
29
  <!-- * ArchLinux ARM -->
22
30
 
23
31
 
24
32
  {: .new}
25
- To enable building reproducible and easily sharable UTM VM bundle a [packer plugin for UTM](https://github.com/naveenrajm7/packer-plugin-utm) has been developed.
26
- Please see the [UTM Box Guide](https://github.com/naveenrajm7/utm-box/blob/main/HowToBuild/DebianUTM.md) on how these UTM Vagrant boxes were built using packer.
27
-
28
-
29
- Check out [Creating UTM Box](/boxes/creating_utm_box.md) to build your own Vagrant compatible UTM box.
30
-
31
- ## Corresponding VMs from UTM Gallery
32
-
33
- <div class="content">
34
- <section class="gallery">
35
- <!-- <div class="gallery-item">
36
- <a href="{{ vm.url }}">
37
- <h3>ArchLinux ARM</h3>
38
- <h4><i class="fas fa-microchip"></i> ARM64 </h4>
39
- <img src="{{ site.baseurl }}/assets/images/screens/archlinux-logo.png" alt="Screenshot" class="screenshot" />
40
- </a>
41
- </div> -->
42
- <div class="gallery-item">
43
- <a href="">
44
- <h3>Debian 11 (Xfce)</h3>
45
- <h4><i class="fas fa-microchip"></i> ARM64 </h4>
46
- <img src="{{ site.baseurl }}/assets/images/screens/debian-11-xfce-arm64.png" alt="Screenshot" class="screenshot" />
47
- </a>
48
- </div>
49
- </section>
50
- </div>
51
-
52
- <style>
53
- .gallery {
54
- display: flex;
55
- flex-flow: row wrap;
56
- justify-content: center;
57
- align-items: center;
58
- }
59
-
60
- .gallery .gallery-item {
61
- padding: 5px;
62
- width: 20em;
63
- }
64
-
65
- .gallery-item a {
66
- text-decoration: none;
67
- color: black;
68
- }
69
-
70
- .gallery h3, .gallery h4 {
71
- text-align: center;
72
- overflow: hidden;
73
- text-overflow: ellipsis;
74
- white-space: nowrap;
75
- }
76
-
77
- .gallery h3 {
78
- font-size: 1.2em;
79
- }
80
-
81
- .gallery h4 {
82
- margin: 10px 0 10px 0;
83
- font-size: 0.8em;
84
- font-weight: normal;
85
- }
33
+ To enable building reproducible and easily sharable UTM VM bundle a [packer plugin for UTM][packer plugin for UTM] has been developed and open-sourced.
86
34
 
87
- .gallery .image {
88
- width: 20em;
89
- }
90
35
 
91
- .gallery .screenshot {
92
- max-width: 100%;
93
- height: auto;
94
- display: block;
95
- box-shadow: 0 1px 0 #ccc, 0 1px 0 1px #eee;
96
- border-radius: 2px;
97
- margin-left: auto;
98
- margin-right: auto;
99
- background: #DDD url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2244%22%20height%3D%2212%22%20viewBox%3D%220%200%2044%2012%22%3E%3Ccircle%20cx%3D%226%22%20cy%3D%226%22%20r%3D%224%22%20fill%3D%22%23eee%22%20%2F%3E%3Ccircle%20cx%3D%2222%22%20cy%3D%226%22%20r%3D%224%22%20fill%3D%22%23eee%22%20%2F%3E%3Ccircle%20cx%3D%2238%22%20cy%3D%226%22%20r%3D%224%22%20fill%3D%22%23eee%22%20%2F%3E%3C%2Fsvg%3E') 4px 4px no-repeat;
100
- padding: 20px 0 0 0;
101
- position: relative;
102
- }
103
36
 
104
- .gallery .placeholder {
105
- padding-top: 75%;
106
- }
37
+ Check out [Creating UTM Box](/creating_utm_box.md) to build your own compatible UTM Vagrant box.
107
38
 
108
- .gallery li {
109
- padding: 5px 0 5px 0;
110
- }
111
39
 
112
- .gallery .button {
113
- padding-bottom: 5px;
114
- margin: 20px 0 20px 0;
115
- font-size: 1.5em;
116
- }
117
- </style>
40
+ [packer plugin for UTM]: https://github.com/naveenrajm7/packer-plugin-utm
41
+ [UTM Box Guide]: https://github.com/naveenrajm7/utm-box/blob/main/HowToBuild/DebianUTM.md
data/docs/commands.md CHANGED
@@ -9,7 +9,7 @@ nav_order: 2
9
9
 
10
10
  This page lists all the supported Vagrant commands which depend on the UTM provider. Eg. `up`, `suspend`, `resume`, `halt`.
11
11
 
12
- Adds note to the command which are not yet available. Eg. `package`.
12
+ Adds note to the command which are have some limitations. Eg. `snapshot`.
13
13
 
14
14
  The Vagrant commands that do not depend on provider are not listed and will continue to work. Eg. `global-status`
15
15
 
@@ -26,9 +26,7 @@ The Vagrant commands that do not depend on provider are not listed and will cont
26
26
 
27
27
  **Command: `vagrant box`**
28
28
 
29
- UTM provider uses .utm file as VM bundle .
30
-
31
- Box support is not yet available.
29
+ UTM provider uses .utm file as VM bundle and supports box operations.
32
30
 
33
31
  ## **Destroy**
34
32
 
@@ -46,9 +44,7 @@ Box support is not yet available.
46
44
 
47
45
  **Command: `vagrant package [name|id]`**
48
46
 
49
- Currently prompts to manually export (Share) the VM
50
-
51
-
47
+ UTM 'Share' / export
52
48
 
53
49
  ## **Port**
54
50
 
@@ -70,7 +66,7 @@ Runs any configured [provisioners](https://developer.hashicorp.com/vagrant/docs
70
66
 
71
67
  **Command: `vagrant reload [name|id]`**
72
68
 
73
- The equivalent of running a [halt](https://developer.hashicorp.com/vagrant/docs/cli/halt) followed by an[up](https://developer.hashicorp.com/vagrant/docs/cli/up).
69
+ The equivalent of running a [halt](https://developer.hashicorp.com/vagrant/docs/cli/halt) followed by an [up](https://developer.hashicorp.com/vagrant/docs/cli/up).
74
70
 
75
71
 
76
72
 
@@ -17,10 +17,22 @@ config.vm.provider "utm" do |u|
17
17
  end
18
18
  ```
19
19
 
20
+ ## Checking for Guest Additions
21
+
22
+ By default UTM plugin will check for the `qemu-guest-agent` when starting a machine, and will output a warning if the guest additions are not detected. You can skip the guest additions check by setting the check_guest_additions option:
23
+
24
+ ```ruby
25
+ config.vm.provider "utm" do |u|
26
+ u.check_guest_additions = false
27
+ end
28
+ ```
29
+
20
30
  ## Other customization
21
31
 
22
32
  ```ruby
23
33
  Vagrant.configure("2") do |config|
34
+ # Vagrant box
35
+ config.vm.box = "utm/debian11"
24
36
  # Hostname inside the VM
25
37
  config.vm.hostname = "debian"
26
38
  # Ports to forward
@@ -29,13 +41,11 @@ Vagrant.configure("2") do |config|
29
41
  config.vm.provider "utm" do |u|
30
42
  # Name in UTM UI
31
43
  u.name = "debian"
32
- # UTM VM file to import
33
- u.utm_file_url = "http://localhost:8000/debian_vagrant_utm.zip"
34
44
  # CPU in cores
35
45
  u.cpus = 1
36
46
  # Memory in MB
37
47
  u.memory = 1024
38
- # Notes for UTM VM (Appears in UI)
48
+ # Notes for UTM VM (Appears in UTM UI)
39
49
  u.notes = "Vagrant: For testing plugin development"
40
50
  # QEMU Directoy Share mode for the VM.
41
51
  # Takes none, webDAV or virtFS
@@ -13,8 +13,8 @@ After which the the host directory can be selected from UTM UI, and the guest di
13
13
 
14
14
  ```ruby
15
15
  Vagrant.configure("2") do |config|
16
+ config.vm.box = "utm/debian11"
16
17
  config.vm.provider :utm do |u|
17
- u.utm_file_url = "http://localhost:8000/vm_utm.zip"
18
18
  # QEMU Directoy Share mode for the VM.
19
19
  # Takes none, webDAV or virtFS
20
20
  u.directory_share_mode = "webDAV"
data/docs/index.md CHANGED
@@ -18,10 +18,16 @@ allowing Vagrant to control and provision machines via UTM's API.
18
18
 
19
19
  ---
20
20
 
21
- [UTM] is a free, full featured system emulator and virtual machine host for iOS and macOS.
22
- The UTM provider currently supports UTM versions 4.5.x (except 4.5.0).
21
+ {: .new}
22
+ > UTM Vagrant plugin now supports [Vagrant boxes](https://developer.hashicorp.com/vagrant/docs/boxes)!
23
+ > Find UTM boxes at [HCP Vagrant registry](https://portal.cloud.hashicorp.com/vagrant/discover/utm).
23
24
 
24
- [Vagrant] enables the creation and configuration of lightweight, reproducible, and portable development environments using Vagrantfile. The UTM provider plugin works with Vagrant version 2.4.1 .
25
+ [UTM] is a free, full-featured system emulator and virtual machine host for iOS and macOS.
26
+ The UTM provider currently supports UTM versions
27
+ * 4.6.x
28
+ * 4.5.x (Obsolete, use plugin version 0.0.1)
29
+
30
+ [Vagrant] enables the creation and configuration of lightweight, reproducible, and portable development environments using Vagrantfile. The UTM provider plugin works with Vagrant version 2.4.1.
25
31
 
26
32
 
27
33
  Both UTM and Vagrant must be installed prior to using this plugin.
@@ -33,11 +39,11 @@ Browse the docs to learn more about how to use this plugin.
33
39
 
34
40
  ## Getting started
35
41
 
36
- Get started with Vagrant UTM plugin in 3 simple steps.
42
+ Get started with Vagrant UTM plugin in 2 simple steps.
37
43
  Make sure both [Vagrant] and [UTM] are installed before your proceed.
38
44
 
39
- {: .warning}
40
- UTM Vagrant plugin is built around the existing UTM API. Some steps like Import, Snapshot are not straightforward. Please check [Known Issues](/known_issues.md) before using this plugin.
45
+ {: .note}
46
+ UTM Vagrant plugin is built around the existing UTM API. Some action like Snapshot are not straightforward. Please check [Known Issues](/known_issues.md) before using this plugin.
41
47
 
42
48
 
43
49
  ### Install
@@ -49,26 +55,34 @@ vagrant plugin install vagrant_utm
49
55
 
50
56
  ### Use
51
57
 
52
- Save the below config in your Vagrantfile.
58
+ #### Step 1
59
+ Option 1: Create a Vagrantfile and initiate the box (OR)
60
+
61
+ ```
62
+ vagrant init utm/debian11
63
+ ```
64
+
65
+ Option 2: Open the Vagrantfile and replace the contents with the following
66
+
53
67
  ```ruby
54
68
  Vagrant.configure("2") do |config|
55
- config.vm.provider :utm do |u|
56
- u.utm_file_url = "https://github.com/naveenrajm7/utm-box/releases/download/debian-11/debian_vagrant_utm.zip"
57
- end
69
+ config.vm.box = "utm/debian11"
58
70
  end
59
71
  ```
60
72
 
61
- ### Run
73
+ #### Step 2
74
+ Bring up your virtual machine
62
75
 
63
- Bring up vagrant environment.
64
- ```bash
76
+ ```
65
77
  vagrant up
66
78
  ```
67
79
 
80
+ Now start using your machine!
68
81
 
82
+ `vagrant ssh` to log into machine or forward ports to check your website or share folders and start developing.
69
83
 
70
84
  Check [Commands](commands.md) for all supported Vagrant commands.
71
- Check [Configuration](configuration.md) for more provider config options.
85
+ Check [Configuration](configuration.md) for more UTM provider config options.
72
86
 
73
87
 
74
88
  ## About the project
@@ -27,5 +27,4 @@ But, if we need to exchange complex data like json from UTM to plugin we use Jav
27
27
  All interactions with UTM should be possible with `utmctl` or `osascript`. But, due to the unavailablity of certain commands or features, we work around the issue by using direct shell command.
28
28
  For Example:
29
29
 
30
- * Import `open -g utm://downloadVM?url=...`
31
30
  * Snapshot `qemu-img snapshot ...`
data/docs/known_issues.md CHANGED
@@ -8,14 +8,14 @@ nav_order: 7
8
8
  This plugin was built built around the existing UTM API.
9
9
  Hence there are things which are not ideal.
10
10
 
11
- 1. vagrant up : Loads new VM by downloading zip file every time, and manually asks the user to confirm the download completion.
12
- Draw back - UTM does not support import API.
11
+ 1. ~~vagrant up : Loads new VM by downloading zip file every time, and manually asks the user to confirm the download completion.~~
12
+ ~~Draw back - UTM does not support import API.~~
13
13
 
14
- 2. UUID : After importing VM , considers last VM in the list as the VM that was imported . So, if the intended VM is not last in the list , the plugin might customize other VM according to the Vagrantfile.
15
- Draw back - UTM import API should return UUID when imported.
14
+ 2. ~~UUID : After importing VM , considers last VM in the list as the VM that was imported . So, if the intended VM is not last in the list , the plugin might customize other VM according to the Vagrantfile.~~
15
+ ~~Draw back - UTM import API should return UUID when imported.~~
16
16
 
17
- 3. vagrant package: plugin just prints message to manually export the VM.
18
- Draw back - UTM does not expose export API. (UTM already has 'Share')
17
+ 3. ~~vagrant package: plugin just prints message to manually export the VM.
18
+ Draw back - UTM does not expose export API. (UTM already has 'Share')~~
19
19
 
20
20
  4. Hide: Any plugin action will bring up the main UTM window. However, a properly built UTM box with no display will run headless.
21
21
 
@@ -3,19 +3,40 @@
3
3
  module VagrantPlugins
4
4
  module Utm
5
5
  module Action
6
- # This action destroys the running machine.
6
+ # This action exports the virtual machine.
7
7
  class Export
8
8
  def initialize(app, _env)
9
9
  @app = app
10
10
  end
11
11
 
12
12
  def call(env)
13
- # UTM 'Share' feature in UI will Export the virtual machine and all its data.
14
- # Till 'Share' is exposed via API, show a message to manually export.
15
- env[:ui].info I18n.t("vagrant_utm.actions.vm.export.manual_exporting",
16
- name: env[:machine].provider_config.name)
13
+ @env = env
14
+
15
+ raise Vagrant::Errors::VMPowerOffToPackage if \
16
+ @env[:machine].state.id != :stopped
17
+
18
+ export
19
+
17
20
  @app.call(env)
18
21
  end
22
+
23
+ def export
24
+ @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting")
25
+ @env[:machine].provider.driver.export(utm_path) do |progress|
26
+ @env[:ui].rewriting do |ui|
27
+ ui.clear_line
28
+ ui.report_progress(progress.percent, 100, false)
29
+ end
30
+ end
31
+
32
+ # Clear the line a final time so the next data can appear
33
+ # alone on the line.
34
+ @env[:ui].clear_line
35
+ end
36
+
37
+ def utm_path
38
+ File.join(@env["export.temp_dir"], "box.utm")
39
+ end
19
40
  end
20
41
  end
21
42
  end
@@ -13,25 +13,35 @@ module VagrantPlugins
13
13
  import(env)
14
14
  end
15
15
 
16
- def import(env)
17
- machine = env[:machine]
18
- config = machine.provider_config
19
- driver = machine.provider.driver
20
- utm_file_url = config.utm_file_url
16
+ def import(env) # rubocop:disable Metrics/AbcSize
17
+ env[:ui].info I18n.t("vagrant.actions.vm.import.importing",
18
+ name: env[:machine].box.name)
21
19
 
22
- env[:ui].info I18n.t("vagrant_utm.messages.importing_utm_file", name: utm_file_url)
20
+ # Import the virtual machine
21
+ utm_file = env[:machine].box.directory.join("box.utm").to_s
22
+ id = env[:machine].provider.driver.import(utm_file) do |progress|
23
+ env[:ui].rewriting do |ui|
24
+ ui.clear_line
25
+ ui.report_progress(progress, 100, false)
26
+ end
27
+ end
23
28
 
24
- # Import the UTM VM file
25
- driver.import(utm_file_url)
29
+ # Set the machine ID
30
+ env[:machine_id] = id
31
+ env[:machine].id = id unless env[:skip_machine]
26
32
 
27
- # Set the UID of Vagrant machine to the UUID of the VM in UTM.
28
- # UTM maintains UUID as primary key for VMs, but even the name works for all commands
29
- # However, name is not unique.
33
+ # Clear the line one last time since the progress meter doesn't disappear
34
+ # immediately.
35
+ env[:ui].clear_line
30
36
 
31
- # So we set the machine.id to UUID in next step after import.
32
- # TODO: Set the machine.id to UUID after import returns the UUID (yet to be supported by UTM).
33
- # machine.id = return value of import
37
+ # If we got interrupted, then the import could have been
38
+ # interrupted and its not a big deal. Just return out.
39
+ return if env[:interrupted]
34
40
 
41
+ # Flag as erroneous and return if import failed
42
+ raise Vagrant::Errors::VMImportFailure unless id
43
+
44
+ # Import completed successfully. Continue the chain
35
45
  @app.call(env)
36
46
  end
37
47
 
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ require "vagrant/action/general/package"
7
+
8
+ module VagrantPlugins
9
+ module Utm
10
+ module Action
11
+ # This action packages the virtual machine into a box
12
+ class Package < Vagrant::Action::General::Package
13
+ # Doing this so that we can test that the parent is properly
14
+ # called in the unit tests.
15
+ alias general_call call
16
+ def call(env)
17
+ general_call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ require "vagrant/action/general/package_setup_files"
7
+
8
+ module VagrantPlugins
9
+ module Utm
10
+ module Action
11
+ # This action sets up the files that are used in the package process.
12
+ class PackageSetupFiles < Vagrant::Action::General::PackageSetupFiles
13
+ # Doing this so that we can test that the parent is properly
14
+ # called in the unit tests.
15
+ alias general_call call
16
+ def call(env)
17
+ general_call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ require "fileutils"
7
+
8
+ require "vagrant/action/general/package_setup_folders"
9
+
10
+ module VagrantPlugins
11
+ module Utm
12
+ module Action
13
+ # This action sets up the folders that are used in the package process.
14
+ class PackageSetupFolders < Vagrant::Action::General::PackageSetupFolders
15
+ # Doing this so that we can test that the parent is properly
16
+ # called in the unit tests.
17
+ alias general_call call
18
+ def call(env)
19
+ general_call(env)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ require "vagrant/util/template_renderer"
7
+
8
+ module VagrantPlugins
9
+ module Utm
10
+ module Action
11
+ # This middleware class sets up the Vagrantfile that will be placed
12
+ # into the root of the exported box.
13
+ class PackageVagrantfile
14
+ # For TemplateRenderer
15
+ include Vagrant::Util
16
+
17
+ def initialize(app, _env)
18
+ @app = app
19
+ end
20
+
21
+ def call(env)
22
+ @env = env
23
+ create_vagrantfile
24
+ @app.call(env)
25
+ end
26
+
27
+ # This method creates the auto-generated Vagrantfile at the root of the
28
+ # box. This Vagrantfile can contain anything that might be essential for user.
29
+ # Ex: Mac Address (for VirtualBox), etc.
30
+ # Currently nothing is added to the Vagrantfile.
31
+ def create_vagrantfile
32
+ File.open(File.join(@env["export.temp_dir"], "Vagrantfile"), "w") do |f|
33
+ f.write(TemplateRenderer.render("package_Vagrantfile"))
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -3,7 +3,7 @@
3
3
  module VagrantPlugins
4
4
  module Utm
5
5
  module Action
6
- # This action destroys the running machine.
6
+ # This action sets the machine id to the UUID of the VM in UTM.
7
7
  class SetId
8
8
  def initialize(app, _env)
9
9
  @app = app
@@ -21,7 +21,6 @@ module VagrantPlugins
21
21
  autoload :Created, action_root.join("created")
22
22
  autoload :Customize, action_root.join("customize")
23
23
  autoload :Destroy, action_root.join("destroy")
24
- autoload :DownloadConfirm, action_root.join("download_confirm")
25
24
  autoload :Export, action_root.join("export")
26
25
  autoload :ForcedHalt, action_root.join("forced_halt")
27
26
  autoload :ForwardPorts, action_root.join("forward_ports")
@@ -35,6 +34,10 @@ module VagrantPlugins
35
34
  autoload :MessageNotStopped, action_root.join("message_not_stopped")
36
35
  autoload :MessageWillNotCreate, action_root.join("message_will_not_create")
37
36
  autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
37
+ autoload :Package, action_root.join("package")
38
+ autoload :PackageSetupFiles, action_root.join("package_setup_files")
39
+ autoload :PackageSetupFolders, action_root.join("package_setup_folders")
40
+ autoload :PackageVagrantfile, action_root.join("package_vagrantfile")
38
41
  autoload :PrepareForwardedPortCollisionParams, action_root.join("prepare_forwarded_port_collision_params")
39
42
  autoload :Resume, action_root.join("resume")
40
43
  autoload :SetId, action_root.join("set_id")
@@ -146,10 +149,15 @@ module VagrantPlugins
146
149
  b2.use MessageNotCreated
147
150
  next
148
151
  end
152
+
153
+ b2.use PackageSetupFolders
154
+ b2.use PackageSetupFiles
149
155
  b2.use CheckAccessible
150
156
  b2.use action_halt
151
157
  b2.use ClearForwardedPorts
158
+ b2.use Package
152
159
  b2.use Export
160
+ b2.use PackageVagrantfile
153
161
  end
154
162
  end
155
163
  end
@@ -321,6 +329,7 @@ module VagrantPlugins
321
329
  Vagrant::Action::Builder.new.tap do |b|
322
330
  b.use CheckUtm
323
331
  b.use ConfigValidate
332
+ b.use BoxCheckOutdated
324
333
  b.use Call, IsRunning do |env, b2|
325
334
  # If the VM is running, run the necessary provisioners
326
335
  if env[:result]
@@ -376,35 +385,30 @@ module VagrantPlugins
376
385
  end
377
386
 
378
387
  # This action brings the machine up from nothing, including importing
379
- # the UTM file, configuring metadata, and booting.
380
- def self.action_up # rubocop:disable Metrics/AbcSize
388
+ # the box, configuring metadata, and booting.
389
+ def self.action_up
381
390
  Vagrant::Action::Builder.new.tap do |b|
382
391
  b.use CheckUtm
392
+
393
+ # Handle box_url downloading early so that if the Vagrantfile
394
+ # references any files in the box or something it all just
395
+ # works fine.
396
+ b.use Call, Created do |env, b2|
397
+ b2.use HandleBox unless env[:result]
398
+ end
399
+
383
400
  b.use ConfigValidate
384
401
  b.use Call, Created do |env, b2|
385
402
  # If the VM is NOT created yet, then do the setup steps
386
403
  unless env[:result]
387
404
  b2.use CheckAccessible
388
405
  b2.use Customize, "pre-import"
389
- # load UTM file to UTM app, through 'utm://downloadVM?url='
390
- b2.use Import
391
406
 
392
- b2.use Call, DownloadConfirm do |env1, b3|
393
- if env1[:result]
394
- # SetID
395
- b3.use SetId
396
- b3.use SetName
397
- # Customize
398
- b3.use Customize, "pre-boot"
399
- else
400
- b3.use MessageWillNotCreate
401
- raise Errors::UtmImportFailed
402
- end
403
- end
407
+ b2.use Import
404
408
  end
405
409
  end
406
410
 
407
- # Start the VM
411
+ b.use EnvSet, cloud_init: true
408
412
  b.use action_start
409
413
  end
410
414
  end
@@ -12,11 +12,6 @@ module VagrantPlugins
12
12
  # @return [String]
13
13
  attr_accessor :name
14
14
 
15
- # The path to the UTM VM file.
16
- #
17
- # @return [String]
18
- attr_accessor :utm_file_url
19
-
20
15
  # If true, will check if guest additions are installed and up to
21
16
  # date. By default, this is true.
22
17
  #
@@ -39,7 +34,6 @@ module VagrantPlugins
39
34
  @check_guest_additions = UNSET_VALUE
40
35
  @customizations = []
41
36
  @name = UNSET_VALUE
42
- @utm_file_url = UNSET_VALUE
43
37
  @wait_time = UNSET_VALUE
44
38
  end
45
39
 
@@ -112,16 +106,13 @@ module VagrantPlugins
112
106
  # The default name is just nothing, and we default it
113
107
  @name = nil if @name == UNSET_VALUE
114
108
 
115
- @utm_file_url = nil if @utm_file_url == UNSET_VALUE
116
-
117
109
  @wait_time = 20 if @wait_time == UNSET_VALUE
118
110
  end
119
111
 
120
112
  def validate(_machine)
121
113
  errors = _detected_errors
122
114
 
123
- # Checks for the UTM file URL
124
- errors << I18n.t("vagrant_utm.config.utm_file_url_required") if @utm_file_url.nil? || @utm_file_url.empty?
115
+ # Add errors if config is invalid Ex: required fields are not set
125
116
 
126
117
  valid_events = %w[pre-import pre-boot post-boot post-comm]
127
118
  @customizations.each do |event, _| # rubocop:disable Style/HashEachMethods
@@ -100,11 +100,10 @@ module VagrantPlugins
100
100
  # @return [ListResult] The list of machines.
101
101
  def list; end
102
102
 
103
- # Execute the 'utm://downloadVM?url='
104
- # See https://docs.getutm.app/advanced/remote-control/
105
- # @param utm_file_url [String] The url to the UTM file.
103
+ # Import a virtual machine from a UTM file.
104
+ # @param utm_file [String] The url to the UTM file.
106
105
  # @return [uuid] The UUID of the imported machine.
107
- def import(utm_file_url); end
106
+ def import(utm_file); end
108
107
 
109
108
  # Sets the name of the virtual machine.
110
109
  # @param name [String] The new name of the machine.
@@ -55,7 +55,8 @@ module VagrantPlugins
55
55
  # Instantiate the proper version driver for UTM
56
56
  @logger.debug("Finding driver for UTM version: #{@version}")
57
57
  driver_map = {
58
- "4.5" => Version_4_5
58
+ "4.5" => Version_4_5,
59
+ "4.6" => Version_4_6
59
60
  }
60
61
 
61
62
  # UTM 4.5.0 just doesn't work with Vagrant (https://github.com/utmapp/UTM/issues/5963),
@@ -92,6 +93,7 @@ module VagrantPlugins
92
93
  :delete,
93
94
  :delete_snapshot,
94
95
  :execute_osa_script,
96
+ :export,
95
97
  :forward_ports,
96
98
  :halt,
97
99
  :import,
@@ -14,7 +14,7 @@ module VagrantPlugins
14
14
  def initialize(uuid)
15
15
  super()
16
16
 
17
- @logger = Log4r::Logger.new("vagrant::provider::utm_4_5")
17
+ @logger = Log4r::Logger.new("vagrant::provider::utm::version_4_5")
18
18
  @uuid = uuid
19
19
  end
20
20
 
@@ -52,6 +52,11 @@ module VagrantPlugins
52
52
  execute_shell("qemu-img", "snapshot", "-d", snapshot_name, machine_file)
53
53
  end
54
54
 
55
+ def export(_path)
56
+ @logger.info("This version of UTM does not support exporting VMs
57
+ Please upgrade to the latest version of UTM or UTM 'Share' feature in UI to export the virtual machine")
58
+ end
59
+
55
60
  def list_snapshots(machine_id) # rubocop:disable Metrics/AbcSize
56
61
  list_result = list
57
62
  machine_name = list_result.find(uuid: machine_id).name
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("version_4_5", __dir__)
4
+
5
+ module VagrantPlugins
6
+ module Utm
7
+ module Driver
8
+ # Driver for UTM 4.6.x
9
+ class Version_4_6 < Version_4_5 # rubocop:disable Naming/ClassAndModuleCamelCase
10
+ def initialize(uuid)
11
+ super
12
+
13
+ @logger = Log4r::Logger.new("vagrant::provider::utm::version_4_6")
14
+ end
15
+
16
+ def import(utm)
17
+ utm = Vagrant::Util::Platform.windows_path(utm)
18
+
19
+ vm_id = nil
20
+
21
+ command = ["import_vm.applescript", utm]
22
+ output = execute_osa_script(command)
23
+
24
+ @logger.debug("Import output: #{output}")
25
+
26
+ # Check if we got the VM ID
27
+ if output =~ /virtual machine id ([A-F0-9-]+)/
28
+ vm_id = ::Regexp.last_match(1) # Capture the VM ID
29
+ end
30
+
31
+ vm_id
32
+ end
33
+
34
+ def export(path)
35
+ @logger.debug("Exporting UTM file to: #{path}")
36
+ command = ["export_vm.applescript", @uuid, path]
37
+ execute_osa_script(command)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,13 @@
1
+ # Usage: osascript export_vm.applescript <vmUUID> <filePath>
2
+ # vmID is the uuid of the virtual machine
3
+ # filePath is the path where the exported file will be saved
4
+ on run argv
5
+ set vmID to item 1 of argv
6
+ set exportPath to item 2 of argv
7
+ set exportFile to POSIX file exportPath
8
+
9
+ tell application "UTM"
10
+ set vm to virtual machine id vmID
11
+ export vm to exportFile
12
+ end tell
13
+ end run
@@ -0,0 +1,14 @@
1
+ # Usage: osascript import_vm.applescript <filePath>
2
+ # filePath is the path of the file to import
3
+ # Returns the imported virtual machine
4
+ on run argv
5
+ set importFile to item 1 of argv
6
+ -- Convert the file path to a POSIX file
7
+ -- This should be done outside the tell block
8
+ set vmFile to POSIX file importFile
9
+
10
+ tell application "UTM"
11
+ set vm to import new virtual machine from vmFile
12
+ return vm
13
+ end tell
14
+ end run
@@ -1,4 +1,4 @@
1
- # Usage: osascript read_port_forwards.applescript <vmID>
1
+ # Usage: osascript read_forwarded_ports.applescript <vmID>
2
2
  # vmID is the id of the virtual machine
3
3
  # This script reads the port forwards of the 'emulated' network interface
4
4
  # 'Forwarding(nicIndex)(ruleIndex)="protocol,guestAddress,guestPort,hostAddress,hostPort"'
@@ -4,6 +4,6 @@ module VagrantPlugins
4
4
  # Top level module for the Utm provider plugin.
5
5
  module Utm
6
6
  # Current version of the Utm provider plugin.
7
- VERSION = "0.0.1"
7
+ VERSION = "0.1.0"
8
8
  end
9
9
  end
data/lib/vagrant_utm.rb CHANGED
@@ -16,6 +16,7 @@ module VagrantPlugins
16
16
  lib_path = Pathname.new(File.expand_path("vagrant_utm/driver", __dir__))
17
17
  autoload :Meta, lib_path.join("meta")
18
18
  autoload :Version_4_5, lib_path.join("version_4_5") # rubocop:disable Naming/VariableNumber
19
+ autoload :Version_4_6, lib_path.join("version_4_6") # rubocop:disable Naming/VariableNumber
19
20
  end
20
21
 
21
22
  # Drop some autoloads for the model classes
data/locales/en.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  en:
2
2
  vagrant_utm:
3
3
  config:
4
+ # Deprecated Configuration field
4
5
  utm_file_url_required: |-
5
6
  Configuration must specify utm.file_url.
6
7
  UTM file URL is required to import the UTM virtual machine.
data/notes/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # Notes
2
+
3
+ This directory will hold documentation about the project.
4
+
5
+
6
+ # Development
7
+
8
+ To invoke vagrant with the plugin in development
9
+ ```bash
10
+ bundle exec vagrant <command> --debug
11
+ ```
12
+
13
+ To locally launch docs site
14
+ ```bash
15
+ cd docs
16
+ bundle exec jekyll serve
17
+ ```
18
+
19
+ To release
20
+
21
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`
22
+ GitHub action upon tag push with "v*" will publish gem to GHR and rubygems
@@ -4,18 +4,19 @@
4
4
  # vi: set ft=ruby :
5
5
 
6
6
  Vagrant.configure("2") do |config|
7
+ config.vm.box = "utm/debian11"
8
+ config.vm.box_version = "0.0.1"
7
9
  # hostname inside the VM
8
10
  config.vm.hostname = "utm"
9
11
  config.vm.network "forwarded_port", guest: 80, host: 8989
10
12
  config.vm.provider :utm do |utm|
11
13
  # Name in UTM UI
12
14
  # utm.name = "debian"
13
- # UTM VM file
14
- utm.utm_file_url = "http://localhost:8000/debian_vagrant_utm.zip"
15
15
  utm.memory = 512
16
16
  utm.cpus = 1
17
17
  utm.notes = "Vagrant: For testing plugin development"
18
18
  # Wait time in secs for VM to be running after 'started'
19
+ # Currently, not used and we rely on the built-in wait for communicator(ssh) to be ready
19
20
  utm.wait_time = 22
20
21
  # QEMU Directoy Share mode for the VM
21
22
  utm.directory_share_mode = "webDAV"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant_utm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naveenraj M
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-09 00:00:00.000000000 Z
11
+ date: 2024-11-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Vagrant UTM provider that allows you to manage UTM virtual machines.
14
14
  email:
@@ -35,6 +35,7 @@ files:
35
35
  - docs/assets/images/favicon.ico
36
36
  - docs/assets/images/logo.png
37
37
  - docs/assets/images/screens/archlinux-logo.png
38
+ - docs/assets/images/screens/debian-10.4-i3-arm64.png
38
39
  - docs/assets/images/screens/debian-11-xfce-arm64.png
39
40
  - docs/boxes/creating_utm_box.md
40
41
  - docs/boxes/index.md
@@ -63,7 +64,6 @@ files:
63
64
  - lib/vagrant_utm/action/created.rb
64
65
  - lib/vagrant_utm/action/customize.rb
65
66
  - lib/vagrant_utm/action/destroy.rb
66
- - lib/vagrant_utm/action/download_confirm.rb
67
67
  - lib/vagrant_utm/action/export.rb
68
68
  - lib/vagrant_utm/action/forced_halt.rb
69
69
  - lib/vagrant_utm/action/forward_ports.rb
@@ -77,6 +77,10 @@ files:
77
77
  - lib/vagrant_utm/action/message_not_stopped.rb
78
78
  - lib/vagrant_utm/action/message_will_not_create.rb
79
79
  - lib/vagrant_utm/action/message_will_not_destroy.rb
80
+ - lib/vagrant_utm/action/package.rb
81
+ - lib/vagrant_utm/action/package_setup_files.rb
82
+ - lib/vagrant_utm/action/package_setup_folders.rb
83
+ - lib/vagrant_utm/action/package_vagrantfile.rb
80
84
  - lib/vagrant_utm/action/prepare_forwarded_port_collision_params.rb
81
85
  - lib/vagrant_utm/action/resume.rb
82
86
  - lib/vagrant_utm/action/set_id.rb
@@ -92,6 +96,7 @@ files:
92
96
  - lib/vagrant_utm/driver/base.rb
93
97
  - lib/vagrant_utm/driver/meta.rb
94
98
  - lib/vagrant_utm/driver/version_4_5.rb
99
+ - lib/vagrant_utm/driver/version_4_6.rb
95
100
  - lib/vagrant_utm/errors.rb
96
101
  - lib/vagrant_utm/model/forwarded_port.rb
97
102
  - lib/vagrant_utm/model/list_result.rb
@@ -101,6 +106,8 @@ files:
101
106
  - lib/vagrant_utm/scripts/clear_port_forwards.applescript
102
107
  - lib/vagrant_utm/scripts/customize_vm.applescript
103
108
  - lib/vagrant_utm/scripts/downloadVM.sh
109
+ - lib/vagrant_utm/scripts/export_vm.applescript
110
+ - lib/vagrant_utm/scripts/import_vm.applescript
104
111
  - lib/vagrant_utm/scripts/list_vm.js
105
112
  - lib/vagrant_utm/scripts/open_with_utm.js
106
113
  - lib/vagrant_utm/scripts/read_forwarded_ports.applescript
@@ -109,6 +116,7 @@ files:
109
116
  - lib/vagrant_utm/util/compile_forwarded_ports.rb
110
117
  - lib/vagrant_utm/version.rb
111
118
  - locales/en.yml
119
+ - notes/README.md
112
120
  - sig/vagrant_utm.rbs
113
121
  - vagrantfile_examples/Vagrantfile
114
122
  homepage: https://naveenrajm7.github.io/vagrant_utm/
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "vagrant/action/builtin/confirm"
4
-
5
- module VagrantPlugins
6
- module Utm
7
- module Action
8
- # Action to confirm download of UTM.
9
- class DownloadConfirm < Vagrant::Action::Builtin::Confirm
10
- def initialize(app, env)
11
- force_key = nil # No force key, user must confirm the download
12
- message = I18n.t("vagrant_utm.messages.download_confirmation",
13
- name: env[:machine].provider_config.utm_file_url)
14
- super(app, env, message, force_key, allowed: %w[y n Y N])
15
- end
16
- end
17
- end
18
- end
19
- end