|
| 1 | +#------------------------------------------------------------------------- |
| 2 | +# Copyright (c) Microsoft Open Technologies, Inc. |
| 3 | +# All Rights Reserved. Licensed under the MIT License. |
| 4 | +#-------------------------------------------------------------------------- |
| 5 | + |
| 6 | +require "pathname" |
| 7 | +require "vagrant/action/builder" |
| 8 | + |
| 9 | +module VagrantPlugins |
| 10 | + module HyperV |
| 11 | + module Action |
| 12 | + # Include the built-in modules so we can use them as top-level things. |
| 13 | + include Vagrant::Action::Builtin |
| 14 | + |
| 15 | + def self.action_reload |
| 16 | + Vagrant::Action::Builder.new.tap do |b| |
| 17 | + b.use ConfigValidate |
| 18 | + b.use Call, IsCreated do |env, b2| |
| 19 | + if !env[:result] |
| 20 | + b2.use MessageNotCreated |
| 21 | + next |
| 22 | + end |
| 23 | + b2.use action_halt |
| 24 | + b2.use Call, WaitForState, :off, 120 do |env2, b3| |
| 25 | + if env2[:result] |
| 26 | + b3.use action_up |
| 27 | + else |
| 28 | + env2[:ui].info("Machine did not reload, Check machine's status") |
| 29 | + end |
| 30 | + end |
| 31 | + end |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + def self.action_halt |
| 36 | + Vagrant::Action::Builder.new.tap do |b| |
| 37 | + b.use ConfigValidate |
| 38 | + b.use Call, IsCreated do |env, b2| |
| 39 | + if !env[:result] |
| 40 | + b2.use MessageNotCreated |
| 41 | + next |
| 42 | + end |
| 43 | + b2.use StopInstance |
| 44 | + end |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + def self.action_start |
| 49 | + Vagrant::Action::Builder.new.tap do |b| |
| 50 | + b.use StartInstance |
| 51 | + b.use ShareFolders |
| 52 | + b.use SyncFolders |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + def self.action_up |
| 57 | + Vagrant::Action::Builder.new.tap do |b| |
| 58 | + b.use HandleBoxUrl |
| 59 | + b.use ConfigValidate |
| 60 | + b.use Call, IsCreated do |env1, b1| |
| 61 | + if env1[:result] |
| 62 | + b1.use Call, IsStopped do |env2, b2| |
| 63 | + if env2[:result] |
| 64 | + b2.use action_start |
| 65 | + else |
| 66 | + b2.use MessageAlreadyCreated |
| 67 | + end |
| 68 | + end |
| 69 | + else |
| 70 | + b1.use Import |
| 71 | + b1.use action_start |
| 72 | + end |
| 73 | + end |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + def self.action_read_state |
| 78 | + Vagrant::Action::Builder.new.tap do |b| |
| 79 | + b.use ConfigValidate |
| 80 | + b.use ReadState |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + def self.action_ssh |
| 85 | + Vagrant::Action::Builder.new.tap do |b| |
| 86 | + b.use ConfigValidate |
| 87 | + b.use Call, IsCreated do |env, b2| |
| 88 | + if !env[:result] |
| 89 | + b2.use MessageNotCreated |
| 90 | + next |
| 91 | + end |
| 92 | + b2.use Call, IsStopped do |env1, b3| |
| 93 | + if env1[:result] |
| 94 | + b3.use MessageNotRunning |
| 95 | + else |
| 96 | + b3.use SSHExec |
| 97 | + end |
| 98 | + end |
| 99 | + end |
| 100 | + end |
| 101 | + end |
| 102 | + |
| 103 | + def self.action_read_guest_ip |
| 104 | + Vagrant::Action::Builder.new.tap do |b| |
| 105 | + b.use ConfigValidate |
| 106 | + b.use ReadGuestIP |
| 107 | + end |
| 108 | + end |
| 109 | + |
| 110 | + |
| 111 | + # The autoload farm |
| 112 | + action_root = Pathname.new(File.expand_path("../action", __FILE__)) |
| 113 | + autoload :IsCreated, action_root.join("is_created") |
| 114 | + autoload :IsStopped, action_root.join("is_stopped") |
| 115 | + autoload :ReadState, action_root.join("read_state") |
| 116 | + autoload :Import, action_root.join("import") |
| 117 | + autoload :StartInstance, action_root.join('start_instance') |
| 118 | + autoload :StopInstance, action_root.join('stop_instance') |
| 119 | + autoload :MessageNotCreated, action_root.join('message_not_created') |
| 120 | + autoload :MessageAlreadyCreated, action_root.join('message_already_created') |
| 121 | + autoload :MessageNotRunning, action_root.join('message_not_running') |
| 122 | + autoload :SyncFolders, action_root.join('sync_folders') |
| 123 | + autoload :WaitForState, action_root.join('wait_for_state') |
| 124 | + autoload :ReadGuestIP, action_root.join('read_guest_ip') |
| 125 | + autoload :ShareFolders, action_root.join('share_folders') |
| 126 | + end |
| 127 | + end |
| 128 | +end |
0 commit comments