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,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Utm
5
+ module Action
6
+ # This action destroys the running machine.
7
+ class Export
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
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)
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Utm
5
+ module Action
6
+ # This action is responsible for halting (stopping) the VM.
7
+ class ForcedHalt
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ current_state = env[:machine].state.id
14
+ if current_state == :started
15
+ env[:ui].info I18n.t("vagrant.actions.vm.halt.force")
16
+ env[:machine].provider.driver.halt
17
+ end
18
+
19
+ # Sleep for a second to verify that the VM properly
20
+ # cleans itself up.
21
+ sleep 1 unless env["vagrant.test"]
22
+
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,90 @@
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 forwards ports on VM based on user configuration.
10
+ class ForwardPorts
11
+ include Util::CompileForwardedPorts
12
+
13
+ def initialize(app, _env)
14
+ @app = app
15
+ end
16
+
17
+ #--------------------------------------------------------------
18
+ # Execution
19
+ #--------------------------------------------------------------
20
+ def call(env)
21
+ @env = env
22
+
23
+ # Get the ports we're forwarding
24
+ env[:forwarded_ports] ||= compile_forwarded_ports(env[:machine].config)
25
+
26
+ # Warn if we're port forwarding to any privileged ports...
27
+ env[:forwarded_ports].each do |fp|
28
+ if fp.host_port <= 1024
29
+ env[:ui].warn I18n.t("vagrant.actions.vm.forward_ports.privileged_ports")
30
+ break
31
+ end
32
+ end
33
+
34
+ env[:ui].output(I18n.t("vagrant.actions.vm.forward_ports.forwarding"))
35
+ forward_ports
36
+
37
+ @app.call(env)
38
+ end
39
+
40
+ def forward_ports # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
41
+ ports = []
42
+
43
+ interfaces = @env[:machine].provider.driver.read_network_interfaces
44
+
45
+ @env[:forwarded_ports].each do |fp| # rubocop:disable Metrics/BlockLength
46
+ message_attributes = {
47
+ adapter: fp.adapter,
48
+ guest_port: fp.guest_port,
49
+ host_port: fp.host_port
50
+ }
51
+
52
+ @env[:ui].detail(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry", **message_attributes))
53
+
54
+ # Verify we have the network interface to attach to
55
+ unless interfaces[fp.adapter]
56
+ raise Vagrant::Errors::ForwardPortAdapterNotFound,
57
+ adapter: fp.adapter.to_s,
58
+ guest: fp.guest_port.to_s,
59
+ host: fp.host_port.to_s
60
+ end
61
+
62
+ # Port forwarding requires the network interface to be a 'Emulated VLAN' interface,
63
+ # so verify that that is the case.
64
+ if interfaces[fp.adapter][:type] != :emulated
65
+ @env[:ui].detail(I18n.t("vagrant_utm.actions.vm.forward_ports.non_emulated",
66
+ **message_attributes))
67
+ next
68
+ end
69
+
70
+ # Add the options to the ports array to send to the driver later
71
+ ports << {
72
+ adapter: fp.adapter,
73
+ guestip: fp.guest_ip,
74
+ guestport: fp.guest_port,
75
+ hostip: fp.host_ip,
76
+ hostport: fp.host_port,
77
+ name: fp.id,
78
+ protocol: fp.protocol
79
+ }
80
+ end
81
+
82
+ # We only need to forward ports if there are any to forward
83
+ return if ports.empty?
84
+
85
+ @env[:machine].provider.driver.forward_ports(ports)
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Utm
5
+ module Action
6
+ # This action imports the virtual machine to UTM.
7
+ class Import
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ import(env)
14
+ end
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
21
+
22
+ env[:ui].info I18n.t("vagrant_utm.messages.importing_utm_file", name: utm_file_url)
23
+
24
+ # Import the UTM VM file
25
+ driver.import(utm_file_url)
26
+
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.
30
+
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
34
+
35
+ @app.call(env)
36
+ end
37
+
38
+ def recover(env)
39
+ return unless env[:machine] && env[:machine].state.id != Vagrant::MachineState::NOT_CREATED_ID
40
+ return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
41
+
42
+ # If we're not supposed to destroy on error then just return
43
+ return unless env[:destroy_on_error]
44
+
45
+ # Interrupted, destroy the VM. We note that we don't want to
46
+ # validate the configuration here, and we don't want to confirm
47
+ # we want to destroy.
48
+ destroy_env = env.clone
49
+ destroy_env[:config_validate] = false
50
+ destroy_env[:force_confirm_destroy] = true
51
+
52
+ # We don't want to double-execute any hooks attached to
53
+ # machine_action_up. Instead we should be honoring destroy hooks.
54
+ # Changing the action name here should make the Builder do the
55
+ # right thing.
56
+ destroy_env[:raw_action_name] = :destroy
57
+ destroy_env[:action_name] = :machine_action_destroy
58
+ env[:action_runner].run(Action.action_destroy, destroy_env)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ 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 middleware checks if the machine is paused and sets the result.
10
+ class IsPaused
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 paused.
17
+ env[:result] = env[:machine].state.id == :paused
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,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 middleware checks if the machine is running (UTM started) and sets the result.
10
+ class IsRunning
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 running.
17
+ env[:result] = env[:machine].state.id == :started
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,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 middleware checks if the machine is stopped and sets the result.
10
+ class IsStopped
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 stopped.
17
+ env[:result] = env[:machine].state.id == :stopped
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,22 @@
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
+ # Print VM is already running message.
10
+ class MessageAlreadyRunning
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ env[:ui].info I18n.t("vagrant.commands.common.vm_already_running")
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
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ module VagrantPlugins
7
+ module Utm
8
+ module Action
9
+ # Print VM not created message.
10
+ class MessageNotCreated
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ env[:ui].info I18n.t("vagrant.commands.common.vm_not_created")
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
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ module VagrantPlugins
7
+ module Utm
8
+ module Action
9
+ # Print VM not running message.
10
+ class MessageNotRunning
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ env[:ui].info I18n.t("vagrant.commands.common.vm_not_running")
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
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ module VagrantPlugins
7
+ module Utm
8
+ module Action
9
+ # Print VM not stopped message.
10
+ class MessageNotStopped
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ env[:ui].info I18n.t("vagrant_utm.commands.common.vm_not_stopped")
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
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
+ # Print VM will not be created message.
10
+ class MessageWillNotCreate
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ env[:ui].info I18n.t("vagrant_utm.commands.up.will_not_create",
17
+ name: env[:machine].name)
18
+ @app.call(env)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
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
+ # Print VM will not be destroyed message.
10
+ class MessageWillNotDestroy
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ env[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy",
17
+ name: env[:machine].name)
18
+ @app.call(env)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
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 is responsible for preparing forwarded port
10
+ class PrepareForwardedPortCollisionParams
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env) # rubocop:disable Metrics/AbcSize
16
+ # Get the forwarded ports used by other virtual machines and
17
+ # consider those in use as well.
18
+ env[:port_collision_extra_in_use] = env[:machine].provider.driver.read_used_ports
19
+
20
+ # Build the remap for any existing collision detections
21
+ remap = {}
22
+ env[:port_collision_remap] = remap
23
+ env[:machine].provider.driver.read_forwarded_ports.each do |_nic, name, hostport, _guestport|
24
+ env[:machine].config.vm.networks.each do |type, options|
25
+ next if type != :forwarded_port
26
+
27
+ # UTM port forwarding does not have name field
28
+ # We use the host port as the name (key) since that is what should be unique
29
+ # If the host port matches the name(host port) of the forwarded port, then
30
+ # remap.
31
+ if options[:host] == name
32
+ remap[options[:host]] = hostport
33
+ break
34
+ end
35
+ end
36
+ end
37
+
38
+ @app.call(env)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Utm
5
+ module Action
6
+ # This action is responsible for resuming the VM.
7
+ class Resume
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ current_state = env[:machine].state.id
14
+ if current_state == :paused
15
+ env[:ui].info I18n.t("vagrant.actions.vm.resume.unpausing")
16
+ env[:machine].provider.driver.start
17
+ end
18
+
19
+ @app.call(env)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Utm
5
+ module Action
6
+ # This action destroys the running machine.
7
+ class SetId
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ env[:machine].id = env[:machine].provider.driver.last_uuid
14
+ env[:ui].info I18n.t("vagrant_utm.messages.setting_id", id: env[:machine].id)
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) HashiCorp, Inc.
4
+ # SPDX-License-Identifier: BUSL-1.1
5
+
6
+ require "log4r"
7
+
8
+ module VagrantPlugins
9
+ module Utm
10
+ module Action
11
+ # This action sets the name of the VM (UTM 'Name' field)
12
+ class SetName
13
+ def initialize(app, _env)
14
+ @logger = Log4r::Logger.new("vagrant::action::vm::setname")
15
+ @app = app
16
+ end
17
+
18
+ def call(env) # rubocop:disable Metrics/AbcSize
19
+ name = env[:machine].provider_config.name
20
+
21
+ # If we already set the name before, then don't do anything
22
+ sentinel = env[:machine].data_dir.join("action_set_name")
23
+ if !name && sentinel.file?
24
+ @logger.info("Default name was already set before, not doing it again.")
25
+ return @app.call(env)
26
+ end
27
+
28
+ # If no name was manually set, then use a default
29
+ unless name
30
+ prefix = "#{env[:root_path].basename}_#{env[:machine].name}"
31
+ prefix.gsub!(/[^-a-z0-9_]/i, "")
32
+
33
+ # milliseconds + random number suffix to allow for simultaneous
34
+ # `vagrant up` of the same box in different dirs
35
+ name = prefix + "_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100_000)}"
36
+ end
37
+
38
+ # TODO: Verify the name is not taken
39
+ # vms = env[:machine].provider.driver.read_vms
40
+ # raise Vagrant::Errors::VMNameExists, name: name if \
41
+ # vms.key?(name) && vms[name] != env[:machine].id
42
+
43
+ # if vms.key?(name)
44
+ # @logger.info("Not setting the name because our name is already set.")
45
+ # else
46
+ env[:ui].info(I18n.t(
47
+ "vagrant.actions.vm.set_name.setting_name", name: name
48
+ ))
49
+ env[:machine].provider.driver.set_name(name)
50
+ # end
51
+
52
+ # Create the sentinel
53
+ sentinel.open("w") do |f|
54
+ f.write(Time.now.to_i.to_s)
55
+ end
56
+
57
+ @app.call(env)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,34 @@
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 deletes a snapshot of the machine.
10
+ class SnapshotDelete
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ env[:ui].info(I18n.t(
17
+ "vagrant.actions.vm.snapshot.deleting",
18
+ name: env[:snapshot_name]
19
+ ))
20
+ env[:machine].provider.driver.delete_snapshot(
21
+ env[:machine].id, env[:snapshot_name]
22
+ )
23
+
24
+ env[:ui].success(I18n.t(
25
+ "vagrant.actions.vm.snapshot.deleted",
26
+ name: env[:snapshot_name]
27
+ ))
28
+
29
+ @app.call(env)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
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
+ class SnapshotRestore # rubocop:disable Style/Documentation
10
+ def initialize(app, _env)
11
+ @app = app
12
+ end
13
+
14
+ def call(env)
15
+ env[:ui].info(I18n.t(
16
+ "vagrant.actions.vm.snapshot.restoring",
17
+ name: env[:snapshot_name]
18
+ ))
19
+ env[:machine].provider.driver.restore_snapshot(
20
+ env[:machine].id, env[:snapshot_name]
21
+ )
22
+
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,34 @@
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 saves a snapshot of the VM.
10
+ class SnapshotSave
11
+ def initialize(app, _env)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ env[:ui].info(I18n.t(
17
+ "vagrant.actions.vm.snapshot.saving",
18
+ name: env[:snapshot_name]
19
+ ))
20
+ env[:machine].provider.driver.create_snapshot(
21
+ env[:machine].id, env[:snapshot_name]
22
+ )
23
+
24
+ env[:ui].success(I18n.t(
25
+ "vagrant.actions.vm.snapshot.saved",
26
+ name: env[:snapshot_name]
27
+ ))
28
+
29
+ @app.call(env)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end