Module: VagrantPlugins::Cloudcenter::Action

Includes:
Vagrant::Action::Builtin
Defined in:
lib/vagrant-cloudcenter/action.rb,
lib/vagrant-cloudcenter/action/deploy.rb,
lib/vagrant-cloudcenter/action/is_created.rb,
lib/vagrant-cloudcenter/action/is_stopped.rb,
lib/vagrant-cloudcenter/action/read_state.rb,
lib/vagrant-cloudcenter/action/read_ssh_info.rb,
lib/vagrant-cloudcenter/action/stop_instance.rb,
lib/vagrant-cloudcenter/action/start_instance.rb,
lib/vagrant-cloudcenter/action/terminate_instance.rb

Defined Under Namespace

Classes: Deploy, IsCreated, IsStopped, ReadSSHInfo, ReadState, StartInstance, StopInstance, TerminateInstance

Class Method Summary collapse

Class Method Details

.action_destroyObject

This action is called to destroy the remote machine.



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

def self.action_destroy
  Vagrant::Action::Builder.new.tap do |b|
    b.use Call, DestroyConfirm do |env, b1|
      if env[:result]
        b1.use ConfigValidate
        b1.use Call, IsCreated do |env, b2|
          if env[:result] != :created
            env[:ui].info(I18n.t("cloudcenter.not_created"))
          else
            b2.use TerminateInstance
          end
        end
      else
        env[:ui].info(I18n.t("cloudcenter.will_not_destroy", name: env[:machine].name))
      end

    end
  end
end

.action_haltObject

This action is called to halt the remote machine.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/vagrant-cloudcenter/action.rb', line 59

def self.action_halt
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b1|
      if env[:result] != :created
        env[:ui].info(I18n.t("cloudcenter.not_created"))
      else
        b1.use Call, IsStopped do |env2, b2|
          if env2[:result] != :stopped
            env2[:ui].info(I18n.t("cloudcenter.stopping"))
            b2.use StopInstance 
          else
              env2[:ui].info(I18n.t("cloudcenter.already_stopped"))
          end
        end
      end
    end
  end
end

.action_prepare_bootObject



30
31
32
33
34
35
# File 'lib/vagrant-cloudcenter/action.rb', line 30

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

.action_provisionObject

This action is called when ‘vagrant provision` is called.



185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/vagrant-cloudcenter/action.rb', line 185

def self.action_provision
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      if env[:result] != :created
        env[:ui].info(I18n.t("cloudcenter.not_created"))
      else
        b2.use Provision
      end

     
    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.



105
106
107
108
109
110
# File 'lib/vagrant-cloudcenter/action.rb', line 105

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

.action_read_stateObject

resulting state is expected to be put into the ‘:machine_state_id` key.



133
134
135
136
137
138
# File 'lib/vagrant-cloudcenter/action.rb', line 133

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

.action_reloadObject

The current implementation uses the CloudCenter Jobs API which starts/stops the entire job instead of an individual VM which requires knowledge of the VM ID. There is no reboot/reload option for the jobs API so instead we will stop the job and then start the job



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

def self.action_reload
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env1, b1|   
      if env1[:result] == :created
        b1.use Call, IsStopped do |env2, b2|
          if env2[:result] == :stopped
            env2[:ui].info(I18n.t("cloudcenter.already_stopped"))
            env2[:ui].info(I18n.t("cloudcenter.starting"))
            b2.use action_prepare_boot
            b2.use StartInstance 
          else
            b2.use StopInstance
            b2.use action_prepare_boot
            b2.use StartInstance 
          end
        end
      else
        env[:ui].info(I18n.t("cloudcenter.not_created"))
      end
    end

  end
end

.action_resumeObject

This action is called to resume the remote machine.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/vagrant-cloudcenter/action.rb', line 80

def self.action_resume
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b1|
      if env[:result] != :created
        env[:ui].info(I18n.t("cloudcenter.not_created"))
      else
        b1.use Call, IsStopped do |env2, b2|
          if env2[:result] == :stopped
            env2[:ui].info(I18n.t("cloudcenter.starting"))
            b2.use action_prepare_boot
            b2.use StartInstance 
          else
              env2[:ui].info(I18n.t("cloudcenter.already_running"))
          end
        end
      end
    end
  end
end

.action_sshObject

This action is called to SSH into the machine.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/vagrant-cloudcenter/action.rb', line 113

def self.action_ssh
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate

    b.use Call, IsCreated do |env, b2|

      if env[:result] != :created
        env[:ui].info(I18n.t("cloudcenter.not_created"))
      else
        b2.use ReadSSHInfo
        b2.use SSHExec
      end
      
    end
  end
end

.action_syncObject



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

def self.action_sync
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b1|
      if env[:result] != :created
        env[:ui].info(I18n.t("cloudcenter.not_created"))
      else
        b1.use ReadSSHInfo
        b1.use SyncedFolders
      end
      
    end
  end
end

.action_upObject

This action is called to bring the box up from nothing.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/vagrant-cloudcenter/action.rb', line 141

def self.action_up
  Vagrant::Action::Builder.new.tap do |b|
    b.use HandleBox
    b.use ConfigValidate
    b.use BoxCheckOutdated
    b.use ReadState
    b.use Call, IsCreated do |env1, b1|   
      if env1[:result] == :created
        b1.use Call, IsStopped do |env2, b2|
          if env2[:result] == :stopped
            env2[:ui].info(I18n.t("cloudcenter.starting"))
            b2.use action_prepare_boot
            b2.use StartInstance 
          else
            env2[:ui].info(I18n.t("cloudcenter.already_running"))
          end
        end
      else
        env1[:ui].info(I18n.t("cloudcenter.deploying"))
        b1.use action_prepare_boot
        b1.use Deploy
      end
    end

  end
end