From c5ec4b4a307aa13f1403b6220b74e0dca9ba92ec Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 17 Dec 2011 11:53:26 -0800 Subject: [PATCH] Provision, reload, resume --- lib/vagrant.rb | 3 +++ lib/vagrant/command.rb | 3 +++ lib/vagrant/command/provision.rb | 31 ++++++++++++++++++++++--------- lib/vagrant/command/reload.rb | 23 ++++++++++++++++++----- lib/vagrant/command/resume.rb | 23 ++++++++++++++++++----- 5 files changed, 64 insertions(+), 19 deletions(-) diff --git a/lib/vagrant.rb b/lib/vagrant.rb index e5691e9df..37423c71b 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -96,6 +96,9 @@ I18n.load_path << File.expand_path("templates/locales/en.yml", Vagrant.source_ro # Register the built-in commands Vagrant.commands.register(:destroy) { Vagrant::Command::Destroy } Vagrant.commands.register(:halt) { Vagrant::Command::Halt } +Vagrant.commands.register(:provision) { Vagrant::Command::Provision } +Vagrant.commands.register(:reload) { Vagrant::Command::Reload } +Vagrant.commands.register(:resume) { Vagrant::Command::Resume } Vagrant.commands.register(:up) { Vagrant::Command::Up } # Register the built-in config keys diff --git a/lib/vagrant/command.rb b/lib/vagrant/command.rb index 468f9215a..8e4917bf2 100644 --- a/lib/vagrant/command.rb +++ b/lib/vagrant/command.rb @@ -4,6 +4,9 @@ module Vagrant autoload :Destroy, 'vagrant/command/destroy' autoload :Halt, 'vagrant/command/halt' + autoload :Provision, 'vagrant/command/provision' + autoload :Reload, 'vagrant/command/reload' + autoload :Resume, 'vagrant/command/resume' autoload :Up, 'vagrant/command/up' end end diff --git a/lib/vagrant/command/provision.rb b/lib/vagrant/command/provision.rb index 7ae75677c..38227c335 100644 --- a/lib/vagrant/command/provision.rb +++ b/lib/vagrant/command/provision.rb @@ -1,20 +1,33 @@ +require 'optparse' + module Vagrant module Command - class ProvisionCommand < NamedBase - register "provision", "Rerun the provisioning scripts on a running VM" - + class Provision < Base def execute - target_vms.each do |vm| + options = {} + + opts = OptionParser.new do |opts| + opts.banner = "Usage: vagrant provision [vm-name]" + end + + # Parse the options + argv = parse_options(opts) + return if !argv + + # Go over each VM and provision! + @logger.debug("'provision' each target VM...") + with_target_vms(argv[0]) do |vm| if vm.created? - if !vm.vm.accessible? - raise Errors::VMInaccessible - elsif vm.vm.running? + if vm.vm.running? + @logger.info("Provisioning: #{vm.name}") vm.provision else - vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_running") + @logger.info("#{vm.name} not running. Not provisioning.") + vm.ui.info I18n.t("vagrant.commands.common.vm_not_running") end else - vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created") + @logger.info("#{vm.name} not created. Not provisioning.") + vm.ui.info I18n.t("vagrant.commands.common.vm_not_created") end end end diff --git a/lib/vagrant/command/reload.rb b/lib/vagrant/command/reload.rb index e359cb6c8..d4280072a 100644 --- a/lib/vagrant/command/reload.rb +++ b/lib/vagrant/command/reload.rb @@ -1,14 +1,27 @@ +require 'optparse' + module Vagrant module Command - class ReloadCommand < NamedBase - register "reload", "Reload the environment, halting it then restarting it." - + class Reload < Base def execute - target_vms.each do |vm| + options = {} + + opts = OptionParser.new do |opts| + opts.banner = "Usage: vagrant reload [vm-name]" + end + + # Parse the options + argv = parse_options(opts) + return if !argv + + @logger.debug("'reload' each target VM...") + with_target_vms(argv[0]) do |vm| if vm.created? + @logger.info("Reloading: #{vm.name}") vm.reload else - vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created") + @logger.info("Not created: #{vm.name}. Not reloading.") + vm.ui.info I18n.t("vagrant.commands.common.vm_not_created") end end end diff --git a/lib/vagrant/command/resume.rb b/lib/vagrant/command/resume.rb index be9171954..cd0ab3d1c 100644 --- a/lib/vagrant/command/resume.rb +++ b/lib/vagrant/command/resume.rb @@ -1,14 +1,27 @@ +require 'optparse' + module Vagrant module Command - class ResumeCommand < NamedBase - register "resume", "Resume a suspended Vagrant environment." - + class Resume < Base def execute - target_vms.each do |vm| + options = {} + + opts = OptionParser.new do |opts| + opts.banner = "Usage: vagrant resume [vm-name]" + end + + # Parse the options + argv = parse_options(opts) + return if !argv + + @logger.debug("'resume' each target VM...") + with_target_vms(argv[0]) do |vm| if vm.created? + @logger.info("Resume: #{vm.name}") vm.resume else - vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created") + @logger.info("Not created: #{vm.name}. Not resuming.") + vm.ui.info I18n.t("vagrant.commands.common.vm_not_created") end end end