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
78 79 80 81 82 83 84 |
# 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 ⇒ Object
34 35 36 37 |
# File 'lib/vagrant-vbguest/machine.rb', line 34 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
48 |
# File 'lib/vagrant-vbguest/machine.rb', line 48 def installation_ran?; guest_additions_state.state == :installed end |
#reboot ⇒ Object
52 |
# File 'lib/vagrant-vbguest/machine.rb', line 52 def reboot; box_state.trigger :reboot end |
#reboot? ⇒ Boolean
53 |
# File 'lib/vagrant-vbguest/machine.rb', line 53 def reboot?; box_state.state == :rebooted end |
#rebuild ⇒ Object
39 40 41 42 |
# File 'lib/vagrant-vbguest/machine.rb', line 39 def rebuild return env.ui.warn(I18n.t("vagrant_vbguest.skipped_rebuild")) if [:no_install] && ![:force] guest_additions_state.trigger :rebuild end |
#rebuilt? ⇒ Boolean
50 |
# File 'lib/vagrant-vbguest/machine.rb', line 50 def rebuilt?; guest_additions_state.state == :rebuilt end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 ⇒ Object
44 45 46 |
# File 'lib/vagrant-vbguest/machine.rb', line 44 def start guest_additions_state.trigger :start end |
#started? ⇒ Boolean
49 |
# File 'lib/vagrant-vbguest/machine.rb', line 49 def started?; guest_additions_state.state == :started end |
#state ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# 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) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# 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 |