From c36b682e40e46f0e1e48f7d1cc2a24c2eed616a1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 7 Oct 2015 22:22:55 -0400 Subject: [PATCH] providers/virtualbox: fix error if no snapshots --- plugins/providers/virtualbox/action/snapshot_list.rb | 5 +++++ plugins/providers/virtualbox/driver/base.rb | 3 ++- plugins/providers/virtualbox/driver/version_5_0.rb | 6 +++++- templates/locales/en.yml | 7 +++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/plugins/providers/virtualbox/action/snapshot_list.rb b/plugins/providers/virtualbox/action/snapshot_list.rb index e909c5e87..27c1e3d12 100644 --- a/plugins/providers/virtualbox/action/snapshot_list.rb +++ b/plugins/providers/virtualbox/action/snapshot_list.rb @@ -14,6 +14,11 @@ module VagrantPlugins env[:machine].ui.output(snapshot, prefix: false) end + if snapshots.empty? + env[:machine].ui.output(I18n.t("vagrant.actions.vm.snapshot.list_none")) + env[:machine].ui.detail(I18n.t("vagrant.actions.vm.snapshot.list_none_detail")) + end + @app.call(env) end end diff --git a/plugins/providers/virtualbox/driver/base.rb b/plugins/providers/virtualbox/driver/base.rb index 768bd9cef..8dc0ba994 100644 --- a/plugins/providers/virtualbox/driver/base.rb +++ b/plugins/providers/virtualbox/driver/base.rb @@ -386,7 +386,8 @@ module VagrantPlugins if errored raise Vagrant::Errors::VBoxManageError, command: command.inspect, - stderr: r.stderr + stderr: r.stderr, + stdout: r.stdout end end diff --git a/plugins/providers/virtualbox/driver/version_5_0.rb b/plugins/providers/virtualbox/driver/version_5_0.rb index 9f1c14359..9762eda42 100644 --- a/plugins/providers/virtualbox/driver/version_5_0.rb +++ b/plugins/providers/virtualbox/driver/version_5_0.rb @@ -116,10 +116,11 @@ module VagrantPlugins end def list_snapshots(machine_id) - result = [] output = execute( "snapshot", machine_id, "list", "--machinereadable", retryable: true) + + result = [] output.split("\n").each do |line| if line =~ /^SnapshotName.*?="(.+?)"$/i result << $1.to_s @@ -127,6 +128,9 @@ module VagrantPlugins end result.sort + rescue Vagrant::Errors::VBoxManageError => e + return [] if e.extra_data[:stdout].include?("does not have") + raise end def restore_snapshot(machine_id, snapshot_name) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index f6d9e8cbc..5d4e4d912 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1770,6 +1770,13 @@ en: Deleting the snapshot '%{name}'... deleted: |- Snapshot deleted! + list_none: |- + No snapshots have been taken yet! + list_none_detail: |- + You can take a snapshot using `vagrant snapshot save`. Note that + not all providers support this yet. Once a snapshot is taken, you + can list them using this command, and use commands such as + `vagrant snapshot restore` to go back to a certain snapshot. restoring: |- Restoring the snapshot '%{name}'... saving: |-