Module: VagrantPlugins::Utm::Action
- Includes:
- Vagrant::Action::Builtin
- Defined in:
- lib/vagrant_utm/action.rb,
lib/vagrant_utm/action/boot.rb,
lib/vagrant_utm/action/export.rb,
lib/vagrant_utm/action/import.rb,
lib/vagrant_utm/action/resume.rb,
lib/vagrant_utm/action/set_id.rb,
lib/vagrant_utm/action/created.rb,
lib/vagrant_utm/action/destroy.rb,
lib/vagrant_utm/action/package.rb,
lib/vagrant_utm/action/suspend.rb,
lib/vagrant_utm/action/set_name.rb,
lib/vagrant_utm/action/check_utm.rb,
lib/vagrant_utm/action/customize.rb,
lib/vagrant_utm/action/is_paused.rb,
lib/vagrant_utm/action/ip_address.rb,
lib/vagrant_utm/action/is_running.rb,
lib/vagrant_utm/action/is_stopped.rb,
lib/vagrant_utm/action/forced_halt.rb,
lib/vagrant_utm/action/check_created.rb,
lib/vagrant_utm/action/check_running.rb,
lib/vagrant_utm/action/forward_ports.rb,
lib/vagrant_utm/action/snapshot_save.rb,
lib/vagrant_utm/action/check_qemu_img.rb,
lib/vagrant_utm/action/boot_disposable.rb,
lib/vagrant_utm/action/snapshot_delete.rb,
lib/vagrant_utm/action/check_accessible.rb,
lib/vagrant_utm/action/snapshot_restore.rb,
lib/vagrant_utm/action/wait_for_running.rb,
lib/vagrant_utm/action/match_mac_address.rb,
lib/vagrant_utm/action/message_not_created.rb,
lib/vagrant_utm/action/message_not_running.rb,
lib/vagrant_utm/action/message_not_stopped.rb,
lib/vagrant_utm/action/package_setup_files.rb,
lib/vagrant_utm/action/package_vagrantfile.rb,
lib/vagrant_utm/action/prepare_nfs_settings.rb,
lib/vagrant_utm/action/check_guest_additions.rb,
lib/vagrant_utm/action/clear_forwarded_ports.rb,
lib/vagrant_utm/action/package_setup_folders.rb,
lib/vagrant_utm/action/prepare_nfs_valid_ids.rb,
lib/vagrant_utm/action/message_already_running.rb,
lib/vagrant_utm/action/message_will_not_create.rb,
lib/vagrant_utm/action/message_will_not_destroy.rb,
lib/vagrant_utm/action/prepare_forwarded_port_collision_params.rb
Overview
Contains all the supported actions of the UTM provider.
Defined Under Namespace
Classes: Boot, BootDisposable, CheckAccessible, CheckCreated, CheckGuestAdditions, CheckQemuImg, CheckRunning, CheckUtm, ClearForwardedPorts, Created, Customize, Destroy, Export, ForcedHalt, ForwardPorts, Import, IpAddress, IsPaused, IsRunning, IsStopped, MatchMACAddress, MessageAlreadyRunning, MessageNotCreated, MessageNotRunning, MessageNotStopped, MessageWillNotCreate, MessageWillNotDestroy, Package, PackageSetupFiles, PackageSetupFolders, PackageVagrantfile, PrepareForwardedPortCollisionParams, PrepareNFSSettings, PrepareNFSValidIds, Resume, SetId, SetName, SnapshotDelete, SnapshotRestore, SnapshotSave, Suspend, WaitForRunning
Class Method Summary collapse
-
.action_boot ⇒ Object
This action boots the VM, assuming the VM is in a state that requires a bootup (i.e. not saved).
-
.action_destroy ⇒ Object
This is the action that is primarily responsible for completely freeing the resources of the underlying virtual machine.
-
.action_halt ⇒ Object
This action is primarily responsible for halting the VM.
-
.action_ip_address ⇒ Object
This action returns ip address of the machine.
-
.action_package ⇒ Object
This action packages the virtual machine into a single box file.
-
.action_provision ⇒ Object
This action just runs the provisioners on the machine.
-
.action_reload ⇒ Object
This action is responsible for reloading the machine, which brings it down, sucks in new configuration, and brings the machine back up with the new configuration.
-
.action_resume ⇒ Object
This action is primarily responsible for resuming the suspended VM.
-
.action_snapshot_delete ⇒ Object
This is the action that is primarily responsible for deleting a snapshot.
-
.action_snapshot_restore ⇒ Object
This is the action that is primarily responsible for restoring a snapshot.
-
.action_snapshot_save ⇒ Object
This is the action that is primarily responsible for saving a snapshot.
-
.action_ssh ⇒ Object
This is the action that will exec into an SSH shell.
-
.action_ssh_run ⇒ Object
This is the action that will run a single SSH command.
-
.action_start ⇒ Object
This action starts a VM, assuming it is already imported and exists.
-
.action_start_disposable ⇒ Object
This action starts VM in disposable mode.
-
.action_suspend ⇒ Object
This action is primarily responsible for suspending the VM.
-
.action_sync_folders ⇒ Object
This is the action that is called to sync folders to a running machine without a reboot.
-
.action_up ⇒ Object
This action brings the machine up from nothing, including importing the box, configuring metadata, and booting.
Class Method Details
.action_boot ⇒ Object
This action boots the VM, assuming the VM is in a state that requires a bootup (i.e. not saved).
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/vagrant_utm/action.rb', line 62 def self.action_boot # rubocop:disable Metrics/AbcSize Vagrant::Action::Builder.new.tap do |b| b.use CheckAccessible b.use SetName b.use ClearForwardedPorts b.use Provision b.use EnvSet, port_collision_repair: true b.use PrepareForwardedPortCollisionParams b.use HandleForwardedPortCollisions b.use PrepareNFSValidIds b.use SyncedFolderCleanup b.use SyncedFolders b.use PrepareNFSSettings b.use ForwardPorts b.use SetHostname b.use Customize, "pre-boot" b.use Boot b.use Customize, "post-boot" # UTM does not have a running state, if you want to # wait manually for the VM to be running, use the following: # b.use WaitForRunning # Since we use forwarded ports , we do not query ip address of VM # for Vagrant communicator. # So we can rely on WaitForCommunicator to wait for VM to be up and running # Machine need to be up and running before we can connect to it. # TODO: change valid states to starting, started, running (after UTM provides running state) b.use WaitForCommunicator, %i[starting started] b.use Customize, "post-comm" b.use CheckGuestAdditions end end |
.action_destroy ⇒ Object
This is the action that is primarily responsible for completely freeing the resources of the underlying virtual machine. UTM equivalent of ‘utmctl delete <uuid>`
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/vagrant_utm/action.rb', line 99 def self.action_destroy # rubocop:disable Metrics/AbcSize Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use Call, Created do |env1, b2| unless env1[:result] b2.use MessageNotCreated next end b2.use Call, DestroyConfirm do |env2, b3| if env2[:result] b3.use ConfigValidate b3.use ProvisionerCleanup, :before b3.use CheckAccessible b3.use action_halt b3.use Destroy b3.use PrepareNFSValidIds b3.use SyncedFolderCleanup else b3.use MessageWillNotDestroy end end end end end |
.action_halt ⇒ Object
This action is primarily responsible for halting the VM. gracefully or by force. UTM equivalent of ‘utmctl stop <uuid>`
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/vagrant_utm/action.rb', line 128 def self.action_halt Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use Call, Created do |env, b2| if env[:result] b2.use CheckAccessible # if VM is paused, resume it before halting # utmctl stop will not work on paused VM b2.use Call, IsPaused do |env2, b3| next unless env2[:result] b3.use Resume end b2.use Call, GracefulHalt, :stopped, :started do |env2, b3| b3.use ForcedHalt unless env2[:result] end else b2.use MessageNotCreated end end end end |
.action_ip_address ⇒ Object
This action returns ip address of the machine. UTM equivalent of ‘utmctl ip-address <uuid>`
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/vagrant_utm/action.rb', line 155 def self.action_ip_address Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use ConfigValidate b.use Call, IsRunning do |env1, b2| unless env1[:result] b2.use MessageNotRunning next end # If the VM is running, then get the IP address. b2.use IpAddress end end end |
.action_package ⇒ Object
This action packages the virtual machine into a single box file.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/vagrant_utm/action.rb', line 171 def self.action_package # rubocop:disable Metrics/AbcSize Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use Call, Created do |env, b2| unless env[:result] b2.use MessageNotCreated next end b2.use PackageSetupFolders b2.use PackageSetupFiles b2.use CheckAccessible b2.use action_halt b2.use ClearForwardedPorts b2.use PrepareNFSValidIds b2.use SyncedFolderCleanup b2.use Package b2.use Export b2.use PackageVagrantfile end end end |
.action_provision ⇒ Object
This action just runs the provisioners on the machine.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/vagrant_utm/action.rb', line 195 def self.action_provision Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use ConfigValidate b.use Call, Created do |env1, b2| unless env1[:result] b2.use MessageNotCreated next end b2.use Call, IsRunning do |env2, b3| unless env2[:result] b3.use MessageNotRunning next end b3.use CheckAccessible b3.use Provision end end end end |
.action_reload ⇒ Object
This action is responsible for reloading the machine, which brings it down, sucks in new configuration, and brings the machine back up with the new configuration.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/vagrant_utm/action.rb', line 221 def self.action_reload Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use Call, Created do |env1, b2| unless env1[:result] b2.use MessageNotCreated next end b2.use ConfigValidate b2.use action_halt b2.use action_start end end end |
.action_resume ⇒ Object
This action is primarily responsible for resuming the suspended VM. UTM equivalent of ‘utmctl start <uuid>`
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/vagrant_utm/action.rb', line 239 def self.action_resume Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use Call, Created do |env, b2| if env[:result] b2.use CheckAccessible # if VM is paused , QEMU still holds the port # so we disable port collision check while resuming # lsof -i tcp:8989 # COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME # QEMULaunc 27754 xxxxxxxxx 21u IPv4 0x41d02c3ade4c04f1 0t0 TCP *:sunwebadmins (LISTEN) # b2.use EnvSet, port_collision_repair: false # b2.use PrepareForwardedPortCollisionParams # b2.use HandleForwardedPortCollisions b2.use Resume b2.use Provision b2.use WaitForCommunicator, %i[resuming started] else b2.use MessageNotCreated end end end end |
.action_snapshot_delete ⇒ Object
This is the action that is primarily responsible for deleting a snapshot
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/vagrant_utm/action.rb', line 266 def self.action_snapshot_delete Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use CheckQemuImg b.use Call, Created do |env, b2| if env[:result] # qemu-img needs write-lock to file, so VM should be stopped b2.use Call, IsStopped do |env2, b3| if env2[:result] b3.use SnapshotDelete else b3.use MessageNotStopped end end else b2.use MessageNotCreated end end end end |
.action_snapshot_restore ⇒ Object
This is the action that is primarily responsible for restoring a snapshot
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/vagrant_utm/action.rb', line 288 def self.action_snapshot_restore # rubocop:disable Metrics/AbcSize Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use CheckQemuImg b.use Call, Created do |env, b2| raise Vagrant::Errors::VMNotCreatedError unless env[:result] b2.use CheckAccessible b2.use EnvSet, force_halt: true b2.use action_halt b2.use SnapshotRestore b2.use Call, IsEnvSet, :snapshot_delete do |env2, b3| b3.use action_snapshot_delete if env2[:result] end b2.use Call, IsEnvSet, :snapshot_start do |env2, b3| b3.use action_start if env2[:result] end end end end |
.action_snapshot_save ⇒ Object
This is the action that is primarily responsible for saving a snapshot
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/vagrant_utm/action.rb', line 312 def self.action_snapshot_save Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use CheckQemuImg b.use Call, Created do |env, b2| if env[:result] # qemu-img does offline snapshot, so VM should be stopped b2.use Call, IsStopped do |env2, b3| if env2[:result] b3.use SnapshotSave else b3.use MessageNotStopped end end else b2.use MessageNotCreated end end end end |
.action_ssh ⇒ Object
This is the action that will exec into an SSH shell.
334 335 336 337 338 339 340 341 342 |
# File 'lib/vagrant_utm/action.rb', line 334 def self.action_ssh Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use CheckCreated b.use CheckAccessible b.use CheckRunning b.use SSHExec end end |
.action_ssh_run ⇒ Object
This is the action that will run a single SSH command.
345 346 347 348 349 350 351 352 353 |
# File 'lib/vagrant_utm/action.rb', line 345 def self.action_ssh_run Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use CheckCreated b.use CheckAccessible b.use CheckRunning b.use SSHRun end end |
.action_start ⇒ Object
This action starts a VM, assuming it is already imported and exists. A precondition of this action is that the VM exists.
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/vagrant_utm/action.rb', line 357 def self.action_start Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use ConfigValidate b.use BoxCheckOutdated b.use Call, IsRunning do |env, b2| # If the VM is running, run the necessary provisioners if env[:result] b2.use action_provision next end b2.use Call, IsPaused do |env2, b3| if env2[:result] b3.use Resume next end # The VM is not paused, so we must have to boot it up # like normal. Boot! b3.use action_boot end end end end |
.action_start_disposable ⇒ Object
This action starts VM in disposable mode. UTM equivalent of ‘utmctl start <uuid> –disposable`
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/vagrant_utm/action.rb', line 385 def self.action_start_disposable Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use ConfigValidate b.use CheckCreated b.use Call, IsRunning do |env1, b2| if env1[:result] b2.use MessageAlreadyRunning next end # If the VM is NOT running, then start in disposable mode b2.use BootDisposable end end end |
.action_suspend ⇒ Object
This action is primarily responsible for suspending the VM. UTM equivalent of ‘utmctl suspend <uuid>`
404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/vagrant_utm/action.rb', line 404 def self.action_suspend Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm b.use Call, Created do |env, b2| if env[:result] b2.use CheckAccessible b2.use Suspend else b2.use MessageNotCreated end end end end |
.action_sync_folders ⇒ Object
This is the action that is called to sync folders to a running machine without a reboot.
420 421 422 423 424 425 426 |
# File 'lib/vagrant_utm/action.rb', line 420 def self.action_sync_folders Vagrant::Action::Builder.new.tap do |b| b.use PrepareNFSValidIds b.use SyncedFolders b.use PrepareNFSSettings end end |
.action_up ⇒ Object
This action brings the machine up from nothing, including importing the box, configuring metadata, and booting.
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/vagrant_utm/action.rb', line 430 def self.action_up Vagrant::Action::Builder.new.tap do |b| b.use CheckUtm # Handle box_url downloading early so that if the Vagrantfile # references any files in the box or something it all just # works fine. b.use Call, Created do |env, b2| b2.use HandleBox unless env[:result] end b.use ConfigValidate b.use Call, Created do |env, b2| # If the VM is NOT created yet, then do the setup steps unless env[:result] b2.use CheckAccessible b2.use Customize, "pre-import" b2.use Import b2.use MatchMACAddress end end b.use EnvSet, cloud_init: true b.use action_start end end |