Class: VagrantVbguest::Machine
- Inherits:
-
Object
- Object
- VagrantVbguest::Machine
- Defined in:
- lib/vagrant-vbguest/machine.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#installer ⇒ Object
readonly
Returns the value of attribute installer.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#vm ⇒ Object
readonly
Returns the value of attribute vm.
Instance Method Summary collapse
- #info ⇒ Object
-
#initialize(vm, options) ⇒ Machine
constructor
A new instance of Machine.
- #install ⇒ Object
- #installation_ran? ⇒ Boolean
- #reboot ⇒ Object
- #reboot? ⇒ Boolean
- #rebuild ⇒ Object
- #rebuilt? ⇒ Boolean
- #run ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #state ⇒ Object
- #steps(state) ⇒ Object
Constructor Details
#initialize(vm, options) ⇒ Machine
Returns a new instance of Machine.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/vagrant-vbguest/machine.rb', line 8 def initialize vm, @vm = vm @env = vm.env @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, ) end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/vagrant-vbguest/machine.rb', line 6 def env @env end |
#installer ⇒ Object (readonly)
Returns the value of attribute installer.
6 7 8 |
# File 'lib/vagrant-vbguest/machine.rb', line 6 def installer @installer end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/vagrant-vbguest/machine.rb', line 6 def @options end |
#vm ⇒ Object (readonly)
Returns the value of attribute vm.
6 7 8 |
# File 'lib/vagrant-vbguest/machine.rb', line 6 def vm @vm end |
Instance Method Details
#info ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/vagrant-vbguest/machine.rb', line 90 def info { :vm_name => vm.name, :host_version => installer.host_version, :guest_version => installer.guest_version } end |
#install ⇒ Object
37 38 39 40 |
# File 'lib/vagrant-vbguest/machine.rb', line 37 def install return env.ui.warn(I18n.t("vagrant_vbguest.skipped_installation")) if [:no_install] && ![:force] guest_additions_state.trigger :install end |
#installation_ran? ⇒ Boolean
51 |
# File 'lib/vagrant-vbguest/machine.rb', line 51 def installation_ran?; guest_additions_state.state == :installed end |
#reboot ⇒ Object
55 |
# File 'lib/vagrant-vbguest/machine.rb', line 55 def reboot; box_state.trigger :reboot end |
#reboot? ⇒ Boolean
56 |
# File 'lib/vagrant-vbguest/machine.rb', line 56 def reboot?; box_state.state == :rebooted end |
#rebuild ⇒ Object
42 43 44 45 |
# File 'lib/vagrant-vbguest/machine.rb', line 42 def rebuild return env.ui.warn(I18n.t("vagrant_vbguest.skipped_rebuild")) if [:no_install] && ![:force] guest_additions_state.trigger :rebuild end |
#rebuilt? ⇒ Boolean
53 |
# File 'lib/vagrant-vbguest/machine.rb', line 53 def rebuilt?; guest_additions_state.state == :rebuilt end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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") case self.send(command) when nil # skipped return false when false # machine state change error env.ui.error(I18n.t('vagrant_vbguest.machine_loop_guard', :command => command, :state => guest_additions_state.state)) return false end return run if current_state != state end true end |
#start ⇒ Object
47 48 49 |
# File 'lib/vagrant-vbguest/machine.rb', line 47 def start guest_additions_state.trigger :start end |
#started? ⇒ Boolean
52 |
# File 'lib/vagrant-vbguest/machine.rb', line 52 def started?; guest_additions_state.state == :started end |
#state ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/vagrant-vbguest/machine.rb', line 69 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 # some sort of distro installation bot no `vboxadd` tools to trigger rebuilds or manual starts return :dirty if installer.provides_vboxadd_tools? && !installer.vboxadd_tools_available? if host_version != guest_version return :unmatched if host_version > guest_version || [:allow_downgrade] || [:force] return :not_running if !running # still need to check this here, so we don't miss it before running into "skipped_downgrade" return :skipped_downgrade if host_version < guest_version end return :not_running if !running return :ok end |
#steps(state) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/vagrant-vbguest/machine.rb', line 58 def steps(state) case state when :clean, :dirty, :unmatched [:install].tap { |l| l << :reboot if installer.reboot_after_install? } when :not_running installation_ran? ? [:reboot] : [:start, :rebuild, :reboot] else [] end end |