Permalink
Browse files

improved startup

  • Loading branch information...
1 parent 98911ba commit ed67c567291b09e748dd25a232d51ab498f333a0 @ebertech committed Dec 10, 2012
Showing with 30 additions and 7 deletions.
  1. +30 −7 lib/virtualbox/guest_control/machine.rb
@@ -52,7 +52,6 @@ def initialize(name, uuid)
before_transition any => :running do |machine, transition|
Shellter.run!(machine.vbox_manage, "startvm", ":name", :name => machine.name)
machine.wait_until { machine.running? }
- machine.wait_until { machine.guest_additions_started? }
end
before_transition :running => :poweroff do |machine, transition|
@@ -91,6 +90,17 @@ def execute(*arguments)
end
end
+ state :starting do
+ def status
+ "Starting Up"
+ end
+
+ def execute(*arguments)
+ wait_until { running? }
+ execute(*arguments)
+ end
+ end
+
state :running do
def status
"Running"
@@ -155,7 +165,16 @@ def wait_until
end
def state
- environment[:VMState]
+ state_name = environment[:VMState]
+ if state_name == "running"
+ if guest_additions_started?
+ state_name
+ else
+ "starting"
+ end
+ else
+ state_name
+ end
end
def guest_additions_started?
@@ -183,12 +202,16 @@ def restart!
def environment
- result = Shellter.run!(vbox_manage, "showvminfo", ":name", "--machinereadable", :name => name)
- {}.with_indifferent_access.tap do |map|
- result.stdout.read.lines.each do |line|
- name, value = line.strip.split("=").map { |y| y.gsub(/(^"|"$)/, "") }
- map[name] = value
+ begin
+ result = Shellter.run!(vbox_manage, "showvminfo", ":name", "--machinereadable", :name => name)
+ {}.with_indifferent_access.tap do |map|
+ result.stdout.read.lines.each do |line|
+ name, value = line.strip.split("=").map { |y| y.gsub(/(^"|"$)/, "") }
+ map[name] = value
+ end
end
+ rescue
+ {}
end
end

0 comments on commit ed67c56

Please sign in to comment.