Class: VagrantPlugins::ProviderKvm::Action::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-kvm/action/export.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Export

Returns a new instance of Export.



9
10
11
# File 'lib/vagrant-kvm/action/export.rb', line 9

def initialize(app, env)
  @app = app
end

Instance Attribute Details

#temp_dirObject (readonly)

Returns the value of attribute temp_dir.



7
8
9
# File 'lib/vagrant-kvm/action/export.rb', line 7

def temp_dir
  @temp_dir
end

Instance Method Details

#call(env) ⇒ Object

Raises:

  • (Vagrant::Errors::VMPowerOffToPackage)


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vagrant-kvm/action/export.rb', line 13

def call(env)
  @env = env

  raise Vagrant::Errors::VMPowerOffToPackage if \
    @env[:machine].provider.state.id != :poweroff

  setup_temp_dir
  export

  @app.call(env)

  recover(env) # called to cleanup temp directory
end

#exportObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vagrant-kvm/action/export.rb', line 39

def export
  @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting")
  @env[:machine].provider.driver.export(xml_path) do |progress|
    @env[:ui].clear_line
    @env[:ui].report_progress(progress.percent, 100, false)
  end

  # Clear the line a final time so the next data can appear
  # alone on the line.
  @env[:ui].clear_line
end

#recover(env) ⇒ Object



27
28
29
30
31
# File 'lib/vagrant-kvm/action/export.rb', line 27

def recover(env)
  if temp_dir && File.exist?(temp_dir)
    FileUtils.rm_rf(temp_dir)
  end
end

#setup_temp_dirObject



33
34
35
36
37
# File 'lib/vagrant-kvm/action/export.rb', line 33

def setup_temp_dir
  @env[:ui].info I18n.t("vagrant.actions.vm.export.create_dir")
  @temp_dir = @env["export.temp_dir"] = @env[:tmp_path].join(Time.now.to_i.to_s)
  FileUtils.mkpath(@env["export.temp_dir"])
end

#xml_pathObject



51
52
53
# File 'lib/vagrant-kvm/action/export.rb', line 51

def xml_path
  File.join(@env["export.temp_dir"], "box.xml")
end