Module: VagrantLXD::Action

Extended by:
Vagrant::Action::Builtin
Defined in:
lib/vagrant-lxd/action.rb

Defined Under Namespace

Classes: CheckForSyncedFolderSupport, ConnectionValidate, LXD, Message, Package, RemoveData

Class Method Summary collapse

Class Method Details

.destroyObject



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/vagrant-lxd/action.rb', line 192

def destroy
  builder do |b|
    b.use Call, IsState, Vagrant::MachineState::NOT_CREATED_ID do |env, c|
      if env[:result]
        next
      else
        c.use Call, DestroyConfirm do |env, d|
          if env[:result]
            d.use halt
            d.use Message, :info, 'Destroying machine and associated data...'
            d.use LXD.action(:destroy)
            d.use RemoveData
          else
            d.use Message, :info, 'Machine will not be destroyed.'
          end
        end
      end
    end
  end
end

.haltObject



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/vagrant-lxd/action.rb', line 213

def halt
  builder do |b|
    b.use Call, state do |env, c|
      case env[:machine_state]
      when Vagrant::MachineState::NOT_CREATED_ID
        next
      when :stopped
        c.use Message, :info, 'Machine is already stopped.'
      when :frozen, :running
        c.use Message, :info, 'Stopping machine...'
        c.use LXD.action(:halt)
      else
        c.use Message, :error, "Machine cannot be stopped while #{env[:machine_state]}."
      end
    end
  end
end

.infoObject



361
362
363
# File 'lib/vagrant-lxd/action.rb', line 361

def info
  builder { |b| b.use LXD.action(:info) }
end

.packageObject



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/vagrant-lxd/action.rb', line 373

def package
  builder do |b|
    b.use Call, state do |env, c|
      case env[:machine_state]
      when Vagrant::MachineState::NOT_CREATED_ID
        next
      when :frozen, :running
        c.use halt
      end

      c.use Message, :info, 'Packaging machine...'
      c.use LXD.action(:package)
      c.use Package
      c.use Vagrant::Action::General::Package
    end
  end
end

.provisionObject



288
289
290
291
292
293
294
295
296
297
298
# File 'lib/vagrant-lxd/action.rb', line 288

def provision
  builder do |b|
    b.use Call, IsState, Vagrant::MachineState::NOT_CREATED_ID do |env, c|
      if env[:result]
        next
      else
        c.use Provision
      end
    end
  end
end

.reloadObject



274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/vagrant-lxd/action.rb', line 274

def reload
  builder do |b|
    b.use Call, state do |env, c|
      case env[:machine_state]
      when Vagrant::MachineState::NOT_CREATED_ID
        next
      when :frozen, :running
        c.use halt
      end
      c.use resume
    end
  end
end

.resumeObject



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/vagrant-lxd/action.rb', line 249

def resume
  builder do |b|
    b.use Call, state do |env, c|
      case env[:machine_state]
      when Vagrant::MachineState::NOT_CREATED_ID
        next
      when :running
        c.use Message, :info, 'Machine is already running.'
      when :frozen, :stopped
        c.use Message, :info, 'Resuming machine...'
        c.use CheckForSyncedFolderSupport
        c.use LXD.action(:configure)
        c.use Provision
        c.use SetHostname
        c.use SyncedFolders
        c.use LXD.action(:resume)
        c.use LXD.action(:reconnect)
        c.use WaitForCommunicator
      else
        c.use Message, :error, "Machine cannot be resumed while #{env[:machine_state]}."
      end
    end
  end
end

.snapshot_deleteObject



343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/vagrant-lxd/action.rb', line 343

def snapshot_delete
  builder do |b|
    b.use Call, IsState, Vagrant::MachineState::NOT_CREATED_ID do |env, c|
      if env[:result]
        next
      else
        c.use Message, :info, I18n.t('vagrant.actions.vm.snapshot.deleting', name: env[:snapshot_name])
        c.use LXD.action(:snapshot_delete), env[:snapshot_name]
        c.use Message, :info, I18n.t('vagrant.actions.vm.snapshot.deleted', name: env[:snapshot_name])
      end
    end
  end
end

.snapshot_listObject



300
301
302
303
304
305
306
307
308
309
310
# File 'lib/vagrant-lxd/action.rb', line 300

def snapshot_list
  builder do |b|
    b.use Call, IsState, Vagrant::MachineState::NOT_CREATED_ID do |env, c|
      if env[:result]
        next
      else
        c.use LXD.action(:snapshot_list)
      end
    end
  end
end

.snapshot_restoreObject



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/vagrant-lxd/action.rb', line 326

def snapshot_restore
  builder do |b|
    b.use Call, IsState, Vagrant::MachineState::NOT_CREATED_ID do |env, c|
      if env[:result]
        next
      else
        c.use Message, :info, I18n.t('vagrant.actions.vm.snapshot.restoring', name: env[:snapshot_name])
        c.use LXD.action(:snapshot_restore), env[:snapshot_name]
        c.use Message, :success, I18n.t('vagrant.actions.vm.snapshot.restored', name: env[:snapshot_name])
        c.use Call, IsEnvSet, :snapshot_delete do |env, d|
          d.use snapshot_delete if env[:result]
        end
      end
    end
  end
end

.snapshot_saveObject



312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/vagrant-lxd/action.rb', line 312

def snapshot_save
  builder do |b|
    b.use Call, IsState, Vagrant::MachineState::NOT_CREATED_ID do |env, c|
      if env[:result]
        next
      else
        c.use Message, :info, I18n.t('vagrant.actions.vm.snapshot.saving', name: env[:snapshot_name])
        c.use LXD.action(:snapshot_save), env[:snapshot_name]
        c.use Message, :success, I18n.t('vagrant.actions.vm.snapshot.saved', name: env[:snapshot_name])
      end
    end
  end
end

.sshObject



365
366
367
# File 'lib/vagrant-lxd/action.rb', line 365

def ssh
  builder { |b| b.use SSHExec }
end

.ssh_runObject



369
370
371
# File 'lib/vagrant-lxd/action.rb', line 369

def ssh_run
  builder { |b| b.use SSHRun }
end

.stateObject



357
358
359
# File 'lib/vagrant-lxd/action.rb', line 357

def state
  builder { |b| b.use LXD.action(:state) }
end

.suspendObject



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/vagrant-lxd/action.rb', line 231

def suspend
  builder do |b|
    b.use Call, state do |env, c|
      case env[:machine_state]
      when Vagrant::MachineState::NOT_CREATED_ID
        next
      when :frozen
        c.use Message, :info, 'Machine is already suspended.'
      when :running
        c.use Message, :info, 'Suspending machine...'
        c.use LXD.action(:suspend)
      else
        c.use Message, :error, "Machine cannot be suspended while #{env[:machine_state]}."
      end
    end
  end
end

.upObject



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/vagrant-lxd/action.rb', line 167

def up
  builder do |b|
    b.use Call, state do |env, c|
      case env[:machine_state]
      when Vagrant::MachineState::NOT_CREATED_ID
        c.use Message, :info, 'Machine has not been created yet, starting...'
        c.use HandleBox
        c.use CheckForSyncedFolderSupport
        c.use LXD.action(:create)
        c.use Provision
        c.use SetHostname
        c.use SyncedFolders
        c.use LXD.action(:resume)
        c.use WaitForCommunicator
      when :running
        c.use Message, :info, 'Machine is already running.'
      when :frozen, :stopped
        c.use resume
      else
        c.use Message, :error, "Machine cannot be started while #{env[:machine_state]}."
      end
    end
  end
end