class VagrantVbguest::Machine
Attributes
env[R]
installer[R]
options[R]
vm[R]
Public Class Methods
new(vm, options)
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 8 def initialize vm, options @vm = vm @env = vm.env @options = options @logger = Log4r::Logger.new("vagrant::plugins::vbguest-machine") @logger.debug("initialize vbguest machine for VM '#{vm.name}' (#{vm.to_s})") @installer = Installer.new vm, options end
Public Instance Methods
info()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 78 def info { :vm_name => vm.name, :host_version => installer.host_version, :guest_version => installer.guest_version } end
install()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 34 def install return env.ui.warn(I18n.t("vagrant_vbguest.skipped_installation")) if options[:no_install] && !options[:force] guest_additions_state.trigger :install end
installation_ran?()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 48 def installation_ran?; guest_additions_state.state == :installed end
reboot()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 52 def reboot; box_state.trigger :reboot end
reboot?()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 53 def reboot?; box_state.state == :rebooted end
rebuild()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 39 def rebuild return env.ui.warn(I18n.t("vagrant_vbguest.skipped_rebuild")) if options[:no_install] && !options[:force] guest_additions_state.trigger :rebuild end
rebuilt?()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 50 def rebuilt?; guest_additions_state.state == :rebuilt end
run()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 19 def run current_state = state runlist = steps(current_state) @logger.debug("Runlist for state #{current_state} is: #{runlist}") while (command = runlist.shift) @logger.debug("Running command #{command} from runlist") if !self.send(command) env.ui.error('vagrant_vbguest.machine_loop_guard', :command => command, :state => current_state) return false end return run if current_state != state end true end
start()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 44 def start guest_additions_state.trigger :start end
started?()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 49 def started?; guest_additions_state.state == :started end
state()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 66 def state guest_version = installer.guest_version(true) host_version = installer.host_version running = installer.running? @logger.debug("Current states for VM '#{vm.name}' are : guest_version=#{guest_version} : host_version=#{host_version} : running=#{running}") return :clean if !guest_version return :unmatched if host_version != guest_version return :not_running if !running return :ok end
steps(state)
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 55 def steps(state) case state when :clean, :unmatched [:install] when :not_running installation_ran? ? [:reboot] : [:start, :rebuild, :reboot] else [] end end
Protected Instance Methods
box_state()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 100 def box_state @box_state ||= MicroMachine.new(:first_boot).tap { |m| m.when :reboot, :first_boot => :rebooted } end
guest_additions_state()
click to toggle source
# File lib/vagrant-vbguest/machine.rb, line 88 def guest_additions_state @guest_additions_state ||= MicroMachine.new(:pending).tap { |m| m.when :install, :pending => :installed m.when :start, :pending => :started m.when :rebuild, :pending => :rebuilt, :started => :rebuilt m.on(:installed) { installer.install } m.on(:started) { installer.start } m.on(:rebuilt) { installer.rebuild } } end