Status command

This commit is contained in:
Mitchell Hashimoto 2010-04-13 17:02:43 -07:00
parent dc35ce0980
commit 3107fa763f
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,53 @@
module Vagrant
class Commands
# Export and package the current vm
#
# This command requires that an instance be powered off
class Status < Base
Base.subcommand "status", self
description "Shows the status of the current environment."
def execute(args=[])
wrap_output do
if !env.vm
puts <<-msg
The environment has not yet been created. Run `vagrant up` to create the
environment.
msg
else
additional_msg = ""
if env.vm.vm.running?
additional_msg = <<-msg
To stop this VM, you can run `vagrant halt` to shut it down forcefully,
or you can run `vagrant suspend` to simply suspend the virtual machine.
In either case, to restart it again, simply run a `vagrant up`.
msg
elsif env.vm.vm.saved?
additional_msg = <<-msg
To resume this VM, simply run `vagrant up`.
msg
elsif env.vm.vm.powered_off?
additional_msg = <<-msg
To restart this VM, simply run `vagrant up`.
msg
end
if !additional_msg.empty?
additional_msg.chomp!
additional_msg = "\n\n#{additional_msg}"
end
puts <<-msg
The environment has been created. The status of the current environment's
virtual machine is: "#{env.vm.vm.state}."#{additional_msg}
msg
end
end
end
def options_spec(opts)
opts.banner = "Usage: vagrant status"
end
end
end
end

View File

@ -0,0 +1,20 @@
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
class CommandsStatusTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Commands::Status
@persisted_vm = mock("persisted_vm")
@persisted_vm.stubs(:execute!)
@env = mock_environment
@env.stubs(:require_persisted_vm)
@env.stubs(:vm).returns(@persisted_vm)
@instance = @klass.new(@env)
end
context "executing" do
# TODO
end
end