Class: VagrantPlugins::ProviderKvm::Action::Export
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderKvm::Action::Export
- Defined in:
- lib/vagrant-kvm/action/export.rb
Instance Attribute Summary collapse
-
#temp_dir ⇒ Object
readonly
Returns the value of attribute temp_dir.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #export ⇒ Object
-
#initialize(app, env) ⇒ Export
constructor
A new instance of Export.
- #recover(env) ⇒ Object
- #setup_temp_dir ⇒ Object
- #xml_path ⇒ Object
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_dir ⇒ Object (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
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 |
#export ⇒ Object
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_dir ⇒ Object
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_path ⇒ Object
51 52 53 |
# File 'lib/vagrant-kvm/action/export.rb', line 51 def xml_path File.join(@env["export.temp_dir"], "box.xml") end |