Module: VagrantPlugins::VCenter::Action

Includes:
Vagrant::Action::Builtin
Defined in:
lib/vagrant-vcenter/action.rb,
lib/vagrant-vcenter/action/resume.rb,
lib/vagrant-vcenter/action/destroy.rb,
lib/vagrant-vcenter/action/suspend.rb,
lib/vagrant-vcenter/action/build_vm.rb,
lib/vagrant-vcenter/action/power_on.rb,
lib/vagrant-vcenter/action/is_paused.rb,
lib/vagrant-vcenter/action/power_off.rb,
lib/vagrant-vcenter/action/is_created.rb,
lib/vagrant-vcenter/action/is_running.rb,
lib/vagrant-vcenter/action/read_state.rb,
lib/vagrant-vcenter/action/read_ssh_info.rb,
lib/vagrant-vcenter/action/connect_vcenter.rb,
lib/vagrant-vcenter/action/inventory_check.rb,
lib/vagrant-vcenter/action/announce_ssh_exec.rb,
lib/vagrant-vcenter/action/disconnect_vcenter.rb,
lib/vagrant-vcenter/action/message_not_created.rb,
lib/vagrant-vcenter/action/prepare_nfs_settings.rb,
lib/vagrant-vcenter/action/message_cannot_suspend.rb,
lib/vagrant-vcenter/action/message_already_running.rb,
lib/vagrant-vcenter/action/message_will_not_destroy.rb

Overview

Actions to be performed by the vagrant-vcenter provider.

Defined Under Namespace

Classes: AnnounceSSHExec, BuildVM, ConnectvCenter, Destroy, DisconnectvCenter, InventoryCheck, IsCreated, IsPaused, IsRunning, MessageAlreadyRunning, MessageCannotSuspend, MessageNotCreated, MessageWillNotDestroy, PowerOff, PowerOn, PrepareNFSSettings, ReadSSHInfo, ReadState, Resume, Suspend

Class Method Summary collapse

Class Method Details

.action_bootObject

Vagrant commands This action boots the VM, assuming the VM is in a state that requires a bootup (i.e. not saved).



13
14
15
16
17
18
19
20
# File 'lib/vagrant-vcenter/action.rb', line 13

def self.action_boot
  Vagrant::Action::Builder.new.tap do |b|
    b.use PowerOn
    b.use PrepareNFSSettings
    b.use Provision
    b.use SyncedFolders
  end
end

.action_destroyObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/vagrant-vcenter/action.rb', line 92

def self.action_destroy
  Vagrant::Action::Builder.new.tap do |b|
    b.use Call, DestroyConfirm do |env, b2|
      if env[:result]
        b2.use ConfigValidate
        b2.use ConnectvCenter
        b2.use Call, IsCreated do |env2, b3|
          unless env2[:result]
            b3.use MessageNotCreated
            next
          end
          b3.use Call, IsRunning do |env3, b4|
          # If the VM is running, must power off
            b4.use action_halt if env3[:result]
            b4.use Destroy
          end
        end
      else
        b2.use MessageWillNotDestroy
      end
    end
  end
end

.action_haltObject



61
62
63
64
65
66
67
68
69
# File 'lib/vagrant-vcenter/action.rb', line 61

def self.action_halt
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConnectvCenter
    b.use Call, IsPaused do |env, b2|
      b2.use Resume if env[:result]
      b2.use PowerOff
    end
  end
end

.action_provisionObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/vagrant-vcenter/action.rb', line 116

def self.action_provision
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectvCenter
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end
      b2.use PrepareNFSSettings
      b2.use Provision
      b2.use SyncedFolders
    end
  end
end

.action_read_ssh_infoObject

This action is called to read the SSH info of the machine. The resulting state is expected to be put into the ‘:machine_ssh_info` key.



135
136
137
138
139
140
141
# File 'lib/vagrant-vcenter/action.rb', line 135

def self.action_read_ssh_info
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectvCenter
    b.use ReadSSHInfo
  end
end

.action_read_stateObject

This action is called to read the state of the machine. The resulting state is expected to be put into the ‘:machine_state_id` key.



146
147
148
149
150
151
152
# File 'lib/vagrant-vcenter/action.rb', line 146

def self.action_read_state
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectvCenter
    b.use ReadState
  end
end

.action_reloadObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vagrant-vcenter/action.rb', line 22

def self.action_reload
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectvCenter
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end
      b2.use action_halt
      b2.use action_start
      b2.use DisconnectvCenter
    end
  end
end

.action_resumeObject



85
86
87
88
89
90
# File 'lib/vagrant-vcenter/action.rb', line 85

def self.action_resume
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConnectvCenter
    b.use Resume
  end
end

.action_sshObject



154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/vagrant-vcenter/action.rb', line 154

def self.action_ssh
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectvCenter
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end
      b2.use AnnounceSSHExec
    end
  end
end

.action_ssh_runObject



168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/vagrant-vcenter/action.rb', line 168

def self.action_ssh_run
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectvCenter
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end
      b2.use SSHRun
    end
  end
end

.action_startObject

This action starts a VM, assuming it is already imported and exists. A precondition of this action is that the VM exists.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vagrant-vcenter/action.rb', line 40

def self.action_start
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectvCenter
    b.use Call, IsRunning do |env, b2|
      # If the VM is running, then our work here is done, exit
      if env[:result]
        b2.use MessageAlreadyRunning
        next
      end
      b2.use Call, IsPaused do |env2, b3|
        if env2[:result]
          b3.use Resume
          next
        end
        b3.use action_boot
      end
    end
  end
end

.action_suspendObject



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/vagrant-vcenter/action.rb', line 71

def self.action_suspend
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConnectvCenter
    b.use Call, IsRunning do |env, b2|
      # If the VM is stopped, can't suspend
      if !env[:result]
        b2.use MessageCannotSuspend
      else
        b2.use Suspend
      end
    end
  end
end

.action_upObject



182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/vagrant-vcenter/action.rb', line 182

def self.action_up
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectvCenter
    b.use Call, IsCreated do |env, b2|
      b2.use HandleBox unless env[:result]
    end
    b.use InventoryCheck
    b.use Call, IsCreated do |env, b2|
      b2.use BuildVM unless env[:result]
    end
    b.use action_start
  end
end