Module: VagrantPlugins::SecuredCloud::Action

Includes:
Vagrant::Action::Builtin
Defined in:
lib/secured-cloud-vagrant/action.rb,
lib/secured-cloud-vagrant/actions/create.rb,
lib/secured-cloud-vagrant/actions/delete.rb,
lib/secured-cloud-vagrant/actions/reboot.rb,
lib/secured-cloud-vagrant/actions/power_on.rb,
lib/secured-cloud-vagrant/actions/power_vm.rb,
lib/secured-cloud-vagrant/actions/power_off.rb,
lib/secured-cloud-vagrant/actions/check_state.rb,
lib/secured-cloud-vagrant/actions/read_ssh_info.rb,
lib/secured-cloud-vagrant/actions/warn_networks.rb,
lib/secured-cloud-vagrant/actions/has_public_ips.rb,
lib/secured-cloud-vagrant/actions/wait_for_state.rb,
lib/secured-cloud-vagrant/actions/warn_provision.rb,
lib/secured-cloud-vagrant/actions/assign_public_ips.rb,
lib/secured-cloud-vagrant/actions/release_ips_confirm.rb

Defined Under Namespace

Classes: AssignPublicIps, CheckState, Create, Delete, HasPublicIps, PowerOff, PowerOn, PowerVm, ReadSshInfo, Reboot, ReleaseIpsConfirm, WaitForState, WarnNetworks, WarnProvision

Class Method Summary collapse

Class Method Details

.destroyObject

This action is called to delete the VM



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
95
96
97
98
99
100
# File 'lib/secured-cloud-vagrant/action.rb', line 62

def self.destroy

  @logger.debug("Calling 'DESTROY' action ... ")

  return Vagrant::Action::Builder.new.tap do |builder|

    # Validate the configurations
    builder.use ConfigValidate

    builder.use Call, CheckState do |env, b|

      case env[:machine_state]
      when :not_created
        env[:ui].info I18n.t('secured_cloud_vagrant.info.not_created')
      else
        b.use Call, DestroyConfirm do |env2, b2|
  
          if(env2[:result])
    
            # Power OFF the VM if it's ON
            if(env[:machine_state] == :active)
              b2.use PowerOff
              b2.use WaitForState
            end

            b2.use Call, HasPublicIps do |env3, b3|

              if(env3[:has_public_ips])
                b3.use ReleaseIpsConfirm
              end
  
              b3.use Delete
            end
          end
        end
      end
    end
  end
end

.haltObject

This action is called to halt the VM



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/secured-cloud-vagrant/action.rb', line 103

def self.halt

  @logger.debug("Calling 'HALT' action ... ")

  return Vagrant::Action::Builder.new.tap do |builder|

    # Validate the configurations
    builder.use ConfigValidate

    builder.use Call, CheckState do |env, b|

      case env[:machine_state]
      when :active
        b.use PowerOff
      when :stopped
        env[:ui].info I18n.t('secured_cloud_vagrant.info.already_off')
      when :not_created
        env[:ui].info I18n.t('secured_cloud_vagrant.info.not_created')
      end
    end
  end

end

.provisionObject

This action is called to provision a remote VM



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/secured-cloud-vagrant/action.rb', line 48

def self.provision

  @logger.debug("Calling 'PROVISION' action ... ")

  return Vagrant::Action::Builder.new.tap do |builder|

    builder.use WarnProvision

  end

end

.read_machine_stateObject

This action is called to get the state of the VM



230
231
232
233
234
235
236
237
238
239
240
# File 'lib/secured-cloud-vagrant/action.rb', line 230

def self.read_machine_state

  @logger.debug("Calling 'READ_MACHINE_STATE' action ... ")

  return Vagrant::Action::Builder.new.tap do |builder|

    builder.use ConfigValidate
    builder.use CheckState
  end

end

.read_ssh_infoObject

This action is called to get the SSH information to connect to the VM



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/secured-cloud-vagrant/action.rb', line 203

def self.read_ssh_info

  @logger.debug("Calling 'READ_SSH_INFO' action ... ")

  return Vagrant::Action::Builder.new.tap do |builder|

  # Validate the configurations
    builder.use ConfigValidate

    builder.use Call, CheckState do |env, b|

      case env[:machine_state]
      when :not_created
        env[:ui].info I18n.t('secured_cloud_vagrant.states.not_created.long',
        :vm_name => env[:machine].provider_config.vm.name)
      when :active, :stopped
        b.use ReadSshInfo
      end

    end

  end

end

.reloadObject

This action is called to halt the VM



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/secured-cloud-vagrant/action.rb', line 128

def self.reload

  @logger.debug("Calling 'RELOAD' action ... ")

  return Vagrant::Action::Builder.new.tap do |builder|

  # Validate the configurations
    builder.use ConfigValidate

    builder.use Call, CheckState do |env, b|

      case env[:machine_state]
      when :active
        b.use Reboot
      when :stopped
        b.use PowerOn
      when :not_created
        env[:ui].info I18n.t('secured_cloud_vagrant.states.not_created.long', :vm_name => env[:machine].provider_config.vm.name)
      end
    end
  end

end

.sshObject

This action is called to connect to the VM through SSH



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/secured-cloud-vagrant/action.rb', line 153

def self.ssh

  @logger.debug("Calling 'SSH' action ... ")

  return Vagrant::Action::Builder.new.tap do |builder|

  # Validate the configurations
    builder.use ConfigValidate

    builder.use Call, CheckState do |env, b|

      case env[:machine_state]
      when :active
        b.use SSHExec
      when :not_created, :stopped
        vm_name = (env[:vm_name].nil? || env[:vm_name].empty?) ? env[:machine].provider_config.vm.name : env[:vm_name]
        env[:ui].info I18n.t("secured_cloud_vagrant.states.#{env[:machine_state]}.long", :vm_name => vm_name)
      end
    end
  end

end

.ssh_runObject

This action is called to connect to run a single SSH command



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/secured-cloud-vagrant/action.rb', line 177

def self.ssh_run

  @logger.debug("Calling 'SSH_RUN' action ... ")

  return Vagrant::Action::Builder.new.tap do |builder|

  # Validate the configurations
    builder.use ConfigValidate

    builder.use Call, CheckState do |env, b|

      case env[:machine_state]
      when :active
        b.use SSHRun
      when :not_created, :stopped
        vm_name = (env[:vm_name].nil? || env[:vm_name].empty?) ? env[:machine].provider_config.vm.name : env[:vm_name]
        env[:ui].info I18n.t("secured_cloud_vagrant.states.#{env[:machine_state]}.long", :vm_name => vm_name)
      end

    end

  end

end

.upObject

This action is called to bring the box up from nothing



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/secured-cloud-vagrant/action.rb', line 17

def self.up

  @logger.debug("Calling 'UP' action ... ")

  return Vagrant::Action::Builder.new.tap do |builder|

    builder.use ConfigValidate

    builder.use Call, CheckState do |env, b|

      case env[:machine_state]
      when :active
        env[:ui].info I18n.t('secured_cloud_vagrant.info.already_active')
      when :stopped
        b.use PowerOn
        b.use provision
      when :not_created
        b.use Create
        b.use AssignPublicIps
        b.use provision
      end

    end

    builder.use WarnNetworks

  end

end