Class: VagrantPlugins::Vmpooler::Action::TakeSnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vmpooler/action/take_snapshot.rb

Overview

This reboots a running server, if there is one.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ TakeSnapshot

Returns a new instance of TakeSnapshot.



8
9
10
11
# File 'lib/vagrant-vmpooler/action/take_snapshot.rb', line 8

def initialize(app, env)
  @app    = app
  @logger = Log4r::Logger.new("vagrant_vmpooler::action::take_snapshot")
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-vmpooler/action/take_snapshot.rb', line 13

def call(env)
  if env[:machine].id
    env[:ui].info(I18n.t("vagrant_vmpooler.snapshoting_server"))
    # make api call to snapshot server
    provider_config = env[:machine].provider_config

    token = provider_config.token
    url = provider_config.url
    verbose = provider_config.verbose
    hostname = env[:machine].id
    response = Pooler.snapshot(verbose, url, hostname, token)
    if response['ok'] == false
      env[:ui].info(I81n.t("vagrant_vmpooler.errors.failed_snapshot"))
      env[:ui].info(response)
    end
  end

  @app.call(env)
end