vagrant_utm 0.0.1

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.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +11 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +132 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +59 -0
  8. data/Rakefile +12 -0
  9. data/docs/.gitignore +15 -0
  10. data/docs/Gemfile +10 -0
  11. data/docs/Gemfile.lock +276 -0
  12. data/docs/README.md +174 -0
  13. data/docs/_config.yml +76 -0
  14. data/docs/_includes/footer_custom.html +3 -0
  15. data/docs/_sass/gallery.scss +64 -0
  16. data/docs/_virtual_machines/archlinux-arm.md +13 -0
  17. data/docs/assets/images/favicon.ico +0 -0
  18. data/docs/assets/images/logo.png +0 -0
  19. data/docs/assets/images/screens/archlinux-logo.png +0 -0
  20. data/docs/assets/images/screens/debian-11-xfce-arm64.png +0 -0
  21. data/docs/boxes/creating_utm_box.md +70 -0
  22. data/docs/boxes/index.md +6 -0
  23. data/docs/boxes/utm_box_gallery.md +117 -0
  24. data/docs/commands.md +156 -0
  25. data/docs/configuration.md +51 -0
  26. data/docs/features/index.md +5 -0
  27. data/docs/features/synced_folders.md +28 -0
  28. data/docs/index.md +103 -0
  29. data/docs/internals/actions.md +20 -0
  30. data/docs/internals/index.md +5 -0
  31. data/docs/internals/status.md +25 -0
  32. data/docs/internals/utm_api.md +31 -0
  33. data/docs/known_issues.md +24 -0
  34. data/lib/vagrant_utm/action/boot.rb +22 -0
  35. data/lib/vagrant_utm/action/boot_disposable.rb +22 -0
  36. data/lib/vagrant_utm/action/check_accessible.rb +33 -0
  37. data/lib/vagrant_utm/action/check_created.rb +24 -0
  38. data/lib/vagrant_utm/action/check_guest_additions.rb +37 -0
  39. data/lib/vagrant_utm/action/check_qemu_img.rb +21 -0
  40. data/lib/vagrant_utm/action/check_running.rb +25 -0
  41. data/lib/vagrant_utm/action/check_utm.rb +30 -0
  42. data/lib/vagrant_utm/action/clear_forwarded_ports.rb +26 -0
  43. data/lib/vagrant_utm/action/created.rb +26 -0
  44. data/lib/vagrant_utm/action/customize.rb +50 -0
  45. data/lib/vagrant_utm/action/destroy.rb +25 -0
  46. data/lib/vagrant_utm/action/download_confirm.rb +19 -0
  47. data/lib/vagrant_utm/action/export.rb +22 -0
  48. data/lib/vagrant_utm/action/forced_halt.rb +28 -0
  49. data/lib/vagrant_utm/action/forward_ports.rb +90 -0
  50. data/lib/vagrant_utm/action/import.rb +63 -0
  51. data/lib/vagrant_utm/action/is_paused.rb +26 -0
  52. data/lib/vagrant_utm/action/is_running.rb +26 -0
  53. data/lib/vagrant_utm/action/is_stopped.rb +26 -0
  54. data/lib/vagrant_utm/action/message_already_running.rb +22 -0
  55. data/lib/vagrant_utm/action/message_not_created.rb +22 -0
  56. data/lib/vagrant_utm/action/message_not_running.rb +22 -0
  57. data/lib/vagrant_utm/action/message_not_stopped.rb +22 -0
  58. data/lib/vagrant_utm/action/message_will_not_create.rb +23 -0
  59. data/lib/vagrant_utm/action/message_will_not_destroy.rb +23 -0
  60. data/lib/vagrant_utm/action/prepare_forwarded_port_collision_params.rb +43 -0
  61. data/lib/vagrant_utm/action/resume.rb +24 -0
  62. data/lib/vagrant_utm/action/set_id.rb +20 -0
  63. data/lib/vagrant_utm/action/set_name.rb +62 -0
  64. data/lib/vagrant_utm/action/snapshot_delete.rb +34 -0
  65. data/lib/vagrant_utm/action/snapshot_restore.rb +28 -0
  66. data/lib/vagrant_utm/action/snapshot_save.rb +34 -0
  67. data/lib/vagrant_utm/action/suspend.rb +23 -0
  68. data/lib/vagrant_utm/action/wait_for_running.rb +28 -0
  69. data/lib/vagrant_utm/action.rb +413 -0
  70. data/lib/vagrant_utm/cap.rb +40 -0
  71. data/lib/vagrant_utm/config.rb +141 -0
  72. data/lib/vagrant_utm/disposable.rb +16 -0
  73. data/lib/vagrant_utm/driver/base.rb +358 -0
  74. data/lib/vagrant_utm/driver/meta.rb +132 -0
  75. data/lib/vagrant_utm/driver/version_4_5.rb +307 -0
  76. data/lib/vagrant_utm/errors.rb +77 -0
  77. data/lib/vagrant_utm/model/forwarded_port.rb +75 -0
  78. data/lib/vagrant_utm/model/list_result.rb +77 -0
  79. data/lib/vagrant_utm/plugin.rb +65 -0
  80. data/lib/vagrant_utm/provider.rb +139 -0
  81. data/lib/vagrant_utm/scripts/add_port_forwards.applescript +72 -0
  82. data/lib/vagrant_utm/scripts/clear_port_forwards.applescript +56 -0
  83. data/lib/vagrant_utm/scripts/customize_vm.applescript +59 -0
  84. data/lib/vagrant_utm/scripts/downloadVM.sh +1 -0
  85. data/lib/vagrant_utm/scripts/list_vm.js +32 -0
  86. data/lib/vagrant_utm/scripts/open_with_utm.js +30 -0
  87. data/lib/vagrant_utm/scripts/read_forwarded_ports.applescript +27 -0
  88. data/lib/vagrant_utm/scripts/read_guest_ip.applescript +9 -0
  89. data/lib/vagrant_utm/scripts/read_network_interfaces.applescript +12 -0
  90. data/lib/vagrant_utm/util/compile_forwarded_ports.rb +43 -0
  91. data/lib/vagrant_utm/version.rb +9 -0
  92. data/lib/vagrant_utm.rb +40 -0
  93. data/locales/en.yml +154 -0
  94. data/sig/vagrant_utm.rbs +4 -0
  95. data/vagrantfile_examples/Vagrantfile +27 -0
  96. metadata +140 -0
@@ -0,0 +1,51 @@
1
+ ---
2
+ title: Configuration
3
+ nav_order: 3
4
+ ---
5
+
6
+ # Configuration
7
+
8
+ The UTM provider exposes some additional configuration options that allow you to more finely control your UTM-powered Vagrant environments.
9
+
10
+ ## Virtual Machine Name
11
+
12
+ You can customize the name that appears in the UTM GUI by setting the name property. By default, Vagrant sets it to the containing folder of the Vagrantfile plus a timestamp of when the machine was created. By setting another name, your VM can be more easily identified.
13
+
14
+ ```ruby
15
+ config.vm.provider "utm" do |u|
16
+ u.name = "my_vm"
17
+ end
18
+ ```
19
+
20
+ ## Other customization
21
+
22
+ ```ruby
23
+ Vagrant.configure("2") do |config|
24
+ # Hostname inside the VM
25
+ config.vm.hostname = "debian"
26
+ # Ports to forward
27
+ config.vm.network "forwarded_port", guest: 80, host: 8989
28
+ # Provider specific configs
29
+ config.vm.provider "utm" do |u|
30
+ # Name in UTM UI
31
+ u.name = "debian"
32
+ # UTM VM file to import
33
+ u.utm_file_url = "http://localhost:8000/debian_vagrant_utm.zip"
34
+ # CPU in cores
35
+ u.cpus = 1
36
+ # Memory in MB
37
+ u.memory = 1024
38
+ # Notes for UTM VM (Appears in UI)
39
+ u.notes = "Vagrant: For testing plugin development"
40
+ # QEMU Directoy Share mode for the VM.
41
+ # Takes none, webDAV or virtFS
42
+ u.directory_share_mode = "webDAV"
43
+ end
44
+ # Provisioner config, supports all built provisioners
45
+ # shell, ansible
46
+ config.vm.provision "shell", inline: <<-SHELL
47
+ apt-get update
48
+ apt-get install -y apache2
49
+ SHELL
50
+ end
51
+ ```
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Features
3
+ nav_order: 4
4
+ has_children: true
5
+ ---
@@ -0,0 +1,28 @@
1
+ ---
2
+ layout: default
3
+ title: Synced Folders
4
+ parent: Features
5
+ nav_order: 1
6
+ ---
7
+
8
+ # Synced Folders
9
+
10
+ UTM Vagrant plugin currently gives rudimentary support for syncing folders between host and guest machine.
11
+ The plugin provides option to configure the Qemu directory share mode.
12
+ After which the the host directory can be selected from UTM UI, and the guest directory can be mounted in guest OS. Both of these steps are now manual until UTM exposes API to configure Host/Guest directory.
13
+
14
+ ```ruby
15
+ Vagrant.configure("2") do |config|
16
+ config.vm.provider :utm do |u|
17
+ u.utm_file_url = "http://localhost:8000/vm_utm.zip"
18
+ # QEMU Directoy Share mode for the VM.
19
+ # Takes none, webDAV or virtFS
20
+ u.directory_share_mode = "webDAV"
21
+ end
22
+ end
23
+ ```
24
+
25
+ ## Other Vagrant options
26
+
27
+ {: .important}
28
+ Apart from the provider specific Sync options, Vagrant has components to provide sync folders feature using NFS and RSync. These features are not yet supported in UTM plugin.
data/docs/index.md ADDED
@@ -0,0 +1,103 @@
1
+ ---
2
+ title: Home
3
+ layout: home
4
+ nav_order: 1
5
+ description: "Vagrant UTM plugin enables you to manage UTM VMs using Vagrant"
6
+ permalink: /
7
+ ---
8
+
9
+ # Automate your VM setup on Mac
10
+ {: .fs-7 }
11
+
12
+ vagrant_utm is a [Vagrant][Vagrant] plugin which adds [UTM][UTM] provider to Vagrant,
13
+ allowing Vagrant to control and provision machines via UTM's API.
14
+
15
+
16
+ [Get started now](#getting-started){: .btn .btn-primary .fs-5 .mb-4 .mb-md-0 .mr-2 }
17
+ [View it on GitHub][Vagrant UTM repo]{: .btn .fs-5 .mb-4 .mb-md-0 }
18
+
19
+ ---
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).
23
+
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
+
26
+
27
+ Both UTM and Vagrant must be installed prior to using this plugin.
28
+ * [Download UTM for Mac](https://mac.getutm.app)
29
+ * [Install Vagrant ](https://developer.hashicorp.com/vagrant/install?product_intent=vagrant)
30
+
31
+ Browse the docs to learn more about how to use this plugin.
32
+
33
+
34
+ ## Getting started
35
+
36
+ Get started with Vagrant UTM plugin in 3 simple steps.
37
+ Make sure both [Vagrant] and [UTM] are installed before your proceed.
38
+
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.
41
+
42
+
43
+ ### Install
44
+
45
+ Install vagrant_utm plugin.
46
+ ```bash
47
+ vagrant plugin install vagrant_utm
48
+ ```
49
+
50
+ ### Use
51
+
52
+ Save the below config in your Vagrantfile.
53
+ ```ruby
54
+ 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
58
+ end
59
+ ```
60
+
61
+ ### Run
62
+
63
+ Bring up vagrant environment.
64
+ ```bash
65
+ vagrant up
66
+ ```
67
+
68
+
69
+
70
+ Check [Commands](commands.md) for all supported Vagrant commands.
71
+ Check [Configuration](configuration.md) for more provider config options.
72
+
73
+
74
+ ## About the project
75
+
76
+ Vagrant UTM is &copy; {{ "now" | date: "%Y" }} by [Naveenraj Muthuraj](https://naveenrajm7.github.io).
77
+
78
+ ### License
79
+
80
+ The Vagrant UTM plugin is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). However, it uses vagrant library and parts of the code from virtualbox plugin both of which are BSL.
81
+ Please be aware of this if you intend on redistributing this plugin.
82
+
83
+ ### Contributing
84
+
85
+ Bug reports and pull requests are welcome on GitHub at [Vagrant UTM repo]. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/naveenrajm7/vagrant_utm/blob/main/CODE_OF_CONDUCT.md).
86
+
87
+ #### Thank you to the contributors of Vagrant UTM Plugin!
88
+
89
+ <ul class="list-style-none">
90
+ {% for contributor in site.github.contributors %}
91
+ <li class="d-inline-block mr-1">
92
+ <a href="{{ contributor.html_url }}"><img src="{{ contributor.avatar_url }}" width="32" height="32" alt="{{ contributor.login }}"></a>
93
+ </li>
94
+ {% endfor %}
95
+ </ul>
96
+
97
+ ### Code of Conduct
98
+
99
+ Everyone interacting in the Vagrant UTM project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/naveenrajm7/vagrant_utm/blob/main/CODE_OF_CONDUCT.md).
100
+
101
+ [Vagrant UTM repo]: https://github.com/naveenrajm7/vagrant_utm
102
+ [UTM]: https://mac.getutm.app
103
+ [Vagrant]: https://www.vagrantup.com
@@ -0,0 +1,20 @@
1
+ ---
2
+ layout: default
3
+ title: Actions
4
+ parent: Internals
5
+ nav_order: 1
6
+ ---
7
+
8
+ The Table below maps the vagrant commands to the corresponding UTM commands that are executed.
9
+
10
+ | Vagrant | utmctl / AppleScript |
11
+ | --- | ------------------ |
12
+ | `vagrant up` | `utmctl start` |
13
+ | `vagrant halt` | `utmctl stop` |
14
+ | `vagrant suspend` | `utmctl suspend` |
15
+ | `vagrant resume` | `utmctl start` |
16
+ | `vagrant reload` | update configuration of vm with config |
17
+ | `vagrant destroy` | `utmctl delete` |
18
+ | `vagrant status` | `utmctl status` |
19
+ | `vagrant disposable` | `utmctl start --disposable` |
20
+ | `vagrant snapshot` | `qemu-img snapshot` |
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Internals
3
+ nav_order: 5
4
+ has_children: true
5
+ ---
@@ -0,0 +1,25 @@
1
+ ---
2
+ layout: default
3
+ title: Status
4
+ parent: Internals
5
+ nav_order: 2
6
+ ---
7
+
8
+ The Table below maps the vagrant (virtualbox) status to UTM status.
9
+
10
+
11
+
12
+ | Vagrant/VirtualBox | UTM |
13
+ | --- | --- |
14
+ | poweroff | stopped |
15
+ | | starting |
16
+ | running | started |
17
+ | | pausing |
18
+ | paused/saved | paused |
19
+ | | resuming |
20
+ | stopping | stopping |
21
+ | | unknown |
22
+
23
+ {: .warning }
24
+ UTM does not report the state `running`, which usally means the VM is ready to accept commands.
25
+ Hence, wherever the state `running` is required by Vagrant, we cautiously use the state `started`.
@@ -0,0 +1,31 @@
1
+ ---
2
+ layout: default
3
+ title: UTM API
4
+ parent: Internals
5
+ nav_order: 3
6
+ ---
7
+
8
+ The plugin invokes UTM API inorder to implement Vagrant required actions.
9
+ As there are several ways to control UTM, we use the following order
10
+
11
+ 1. UTM Command Line (`utmctl`)
12
+ 2. Apple Scripting Bridge (`osascript`)
13
+ 2.a Applescript
14
+ 2.b JavaScript
15
+ 3. Shell command
16
+
17
+
18
+ **1. UTM Command Line** : Just like virtualbox plugin uses VBoxManage, the goal of this plugin is to use UTM command line tool `utmctl` as single point of control.
19
+
20
+ **2. Apple Scripting Bridge** :
21
+ However, not all capabilities are currently exposed via `utmctl`.
22
+ So we rely on Apple Scripting Bridge scripts which can be executed using `osascript` binary.
23
+ When it comes to writing the OSA scripts, our first choice is applescript language due to its simplicity and support.
24
+ But, if we need to exchange complex data like json from UTM to plugin we use Javascript (Note: Some APIs are difficult to get it working in JS, hence our first choice is applescript).
25
+
26
+ **3. Shell command** :
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
+ For Example:
29
+
30
+ * Import `open -g utm://downloadVM?url=...`
31
+ * Snapshot `qemu-img snapshot ...`
@@ -0,0 +1,24 @@
1
+ ---
2
+ title: Known Issues
3
+ nav_order: 7
4
+ ---
5
+
6
+ # Known Issues
7
+
8
+ This plugin was built built around the existing UTM API.
9
+ Hence there are things which are not ideal.
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.
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.
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')
19
+
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
+
22
+ 5. vagrant snapshot: Even though UTM does not have snapshot feature, this plugin has a experimental support for offline VM snapshots using qemu-img.
23
+ The VM must be stopped, for any snapshot commands to work.
24
+ The snapshot only works for **single** qcow2 based VM images
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Utm
5
+ module Action
6
+ # Action to start the virtual machine.
7
+ class Boot
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ # Start up the VM and wait for it to boot.
14
+ env[:ui].info I18n.t("vagrant.actions.vm.boot.booting")
15
+ env[:machine].provider.driver.start
16
+
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Utm
5
+ module Action
6
+ # Action to start the virtual machine in disposable mode.
7
+ class BootDisposable
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ # Start up the VM in disposable mode.
14
+ env[:ui].warn I18n.t("vagrant_utm.actions.vm.boot.disposable")
15
+ env[:machine].provider.driver.start_disposable
16
+
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ module VagrantPlugins
7
+ module Utm
8
+ module Action
9
+ # This middleware checks that the VM is accessible, and raises an exception
10
+ # TODO: Define what is inaccessible in UTM and set the state accordingly
11
+ # Currently, UTM does not report inaccessible state,
12
+ # So this plugin will set the state to inaccessible
13
+ # Hence, this action will never raise an exception
14
+ class CheckAccessible
15
+ def initialize(app, _env)
16
+ @app = app
17
+ end
18
+
19
+ def call(env)
20
+ if env[:machine].state.id == :inaccessible
21
+ # The VM we are attempting to manipulate is inaccessible. This
22
+ # is a very bad situation and can only be fixed by the user. It
23
+ # also prohibits us from actually doing anything with the virtual
24
+ # machine, so we raise an error.
25
+ raise Vagrant::Errors::VMInaccessible
26
+ end
27
+
28
+ @app.call(env)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ 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
+ module VagrantPlugins
7
+ module Utm
8
+ module Action
9
+ # This middleware checks that the VM is created, and raises an exception
10
+ # if it is not, notifying the user that creation is required.
11
+ class CheckCreated
12
+ def initialize(app, _env)
13
+ @app = app
14
+ end
15
+
16
+ def call(env)
17
+ raise Vagrant::Errors::VMNotCreatedError if env[:machine].state.id == :not_created
18
+
19
+ @app.call(env)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "log4r"
4
+
5
+ module VagrantPlugins
6
+ module Utm
7
+ module Action
8
+ # This action checks if the guest additions are installed.
9
+ # Currently only check's if qemu-guest-agent is installed and running.
10
+ # TODO: Add other checks, Drivers(eg Virt), SPICE Agent, SPICE WebDAV, VirtFS
11
+ class CheckGuestAdditions
12
+ def initialize(app, _env)
13
+ @app = app
14
+ @logger = Log4r::Logger.new("vagrant_utm::action::check_guest_additions")
15
+ end
16
+
17
+ def call(env) # rubocop:disable Metrics/AbcSize
18
+ unless env[:machine].provider_config.check_guest_additions
19
+ @logger.info("Not checking guest additions because configuration")
20
+ return @app.call(env)
21
+ end
22
+
23
+ env[:ui].output(I18n.t("vagrant_utm.utm.checking_guest_additions"))
24
+
25
+ if env[:machine].provider.driver.check_qemu_guest_agent
26
+ env[:ui].detail(I18n.t("vagrant_utm.actions.vm.check_guest_additions.detected"))
27
+ else
28
+ env[:ui].detail(I18n.t("vagrant_utm.actions.vm.check_guest_additions.not_detected"))
29
+ end
30
+
31
+ # Continue
32
+ @app.call(env)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Utm
5
+ module Action
6
+ # This action checks if qemu-img is installed.
7
+ class CheckQemuImg
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ qemu_img_present = Vagrant::Util::Which.which("qemu-img")
14
+ raise Errors::QemuImgRequired unless qemu_img_present
15
+
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ module VagrantPlugins
7
+ module Utm
8
+ module Action
9
+ # This middleware checks that the VM is running, and raises an exception
10
+ # if it is not, notifying the user that the VM must be running.
11
+ # UTM equivalent status is "started"
12
+ class CheckRunning
13
+ def initialize(app, _env)
14
+ @app = app
15
+ end
16
+
17
+ def call(env)
18
+ raise Vagrant::Errors::VMNotRunningError if env[:machine].state.id != :started
19
+
20
+ @app.call(env)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ require "vagrant/util/platform"
7
+
8
+ module VagrantPlugins
9
+ module Utm
10
+ module Action
11
+ # Checks that UTM is installed and ready to be used.
12
+ class CheckUtm
13
+ def initialize(app, _env)
14
+ @app = app
15
+ @logger = Log4r::Logger.new("vagrant::provider::utm")
16
+ end
17
+
18
+ def call(env)
19
+ # This verifies that UTM is installed and the driver is
20
+ # ready to function. If not, then an exception will be raised
21
+ # which will break us out of execution of the middleware sequence.
22
+ Driver::Meta.new.verify!
23
+
24
+ # Carry on.
25
+ @app.call(env)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ module VagrantPlugins
7
+ module Utm
8
+ module Action
9
+ # This action clears forwarded ports on the UTM VM.
10
+ class ClearForwardedPorts
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ unless env[:machine].provider.driver.read_forwarded_ports.empty?
17
+ env[:ui].info I18n.t("vagrant.actions.vm.clear_forward_ports.deleting")
18
+ env[:machine].provider.driver.clear_forwarded_ports
19
+ end
20
+
21
+ @app.call(env)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ module VagrantPlugins
7
+ module Utm
8
+ module Action
9
+ # This class will set the result to be true if the machine is created.
10
+ class Created
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ # Set the result to be true if the machine is created.
17
+ env[:result] = env[:machine].state.id != :not_created
18
+
19
+ # Call the next if we have one (but we shouldn't, since this
20
+ # middleware is built to run with the Call-type middlewares)
21
+ @app.call(env)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ module VagrantPlugins
7
+ module Utm
8
+ module Action
9
+ # This middleware class runs the customizations for the VM.
10
+ class Customize
11
+ def initialize(app, _env, event)
12
+ @app = app
13
+ @event = event
14
+ end
15
+
16
+ def call(env) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
17
+ customizations = []
18
+ env[:machine].provider_config.customizations.each do |event, command|
19
+ customizations << command if event == @event
20
+ end
21
+
22
+ unless customizations.empty?
23
+ env[:ui].info I18n.t("vagrant.actions.vm.customize.running", event: @event)
24
+
25
+ # Execute each customization command.
26
+ customizations.each do |command|
27
+ processed_command = command.collect do |arg|
28
+ arg = env[:machine].id if arg == :id
29
+ arg.to_s
30
+ end
31
+
32
+ begin
33
+ env[:machine].provider.driver.execute_osa_script(
34
+ processed_command
35
+ )
36
+ rescue VagrantPlugins::Utm::Errors::CommandError => e
37
+ raise Vagrant::Errors::VMCustomizationFailed, {
38
+ command: command,
39
+ error: e.inspect
40
+ }
41
+ end
42
+ end
43
+ end
44
+
45
+ @app.call(env)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ module VagrantPlugins
7
+ module Utm
8
+ module Action
9
+ # This action destroys the running machine.
10
+ class Destroy
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ env[:ui].info I18n.t("vagrant.actions.vm.destroy.destroying")
17
+ env[:machine].provider.driver.delete
18
+ env[:machine].id = nil
19
+
20
+ @app.call(env)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
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