Cleaner upgrade process and backup previous .vagrant file

This commit is contained in:
Mitchell Hashimoto 2010-09-07 10:24:59 -07:00
parent 446d1155fe
commit baccbd047d
2 changed files with 24 additions and 10 deletions

View File

@ -1,3 +1,5 @@
require 'fileutils'
module Vagrant
module Command
class UpgradeTo060Command < Base
@ -12,19 +14,29 @@ module Vagrant
return
end
if !@env.local_data.empty?
local_data = @env.local_data
if !local_data.empty?
if local_data[:active]
@env.ui.confirm "vagrant.commands.upgrade_to_060.already_done", :_prefix => false
return
end
# Backup the previous file
@env.ui.info "vagrant.commands.upgrade_to_060.backing_up", :_prefix => false
FileUtils.cp(local_data.file_path, "#{local_data.file_path}.bak-#{Time.now.to_i}")
# Gather the previously set virtual machines into a single
# active hash
active = @env.local_data.inject({}) do |acc, data|
active = local_data.inject({}) do |acc, data|
key, uuid = data
acc[key.to_sym] = uuid
acc
end
# Set the active hash to the active list and save it
@env.local_data.clear
@env.local_data[:active] = active
@env.local_data.commit
local_data.clear
local_data[:active] = active
local_data.commit
end
@env.ui.confirm "vagrant.commands.upgrade_to_060.complete", :_prefix => false

View File

@ -127,15 +127,17 @@ en:
up:
vm_created: "VM already created. Booting if its not already running..."
upgrade_to_060:
already_done: "Environment appears to already be upgraded to 0.6.0. Doing nothing!"
ask: "Are you sure you want to execute this command?"
backing_up: "Backing up previous .vagrant file..."
complete: "Environment upgraded to 0.6.0 successfully."
info: |-
This command will upgrade the current environment from a pre-0.6.0
environment to a 0.6.x compatible environment. Running this command
on a 0.6.0 environment may cause corrupt virtual machines, however,
so verify now that this is your first time running this command and
that this environment was created pre-0.6.0.
ask: "Are you sure you want to execute this command?"
multiple times should be okay. This command will make a backup file
prior to making any changes. Therefore, if anything goes wrong, then
restore that file to ".vagrant" in the same directory as the Vagrantfile.
quit: "Not executing this command by user request. Quitting..."
complete: "Environment upgraded to 0.6.0 successfully."
version:
output: "Vagrant version %{version}"