Class: VagrantVbguest::Machine

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vbguest/machine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, 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

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



6
7
8
# File 'lib/vagrant-vbguest/machine.rb', line 6

def env
  @env
end

#installerObject (readonly)

Returns the value of attribute installer.



6
7
8
# File 'lib/vagrant-vbguest/machine.rb', line 6

def installer
  @installer
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/vagrant-vbguest/machine.rb', line 6

def options
  @options
end

#vmObject (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

#infoObject



78
79
80
81
82
83
# File 'lib/vagrant-vbguest/machine.rb', line 78

def info
  {
    :host_version => installer.host_version,
    :guest_version => installer.guest_version
  }
end

#installObject



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 options[:no_install] && !options[:force]
  guest_additions_state.trigger :install
end

#installation_ran?Boolean

Returns:

  • (Boolean)


48
# File 'lib/vagrant-vbguest/machine.rb', line 48

def installation_ran?; guest_additions_state == :installed end

#rebootObject



52
# File 'lib/vagrant-vbguest/machine.rb', line 52

def reboot;  box_state.trigger :reboot end

#reboot?Boolean

Returns:

  • (Boolean)


53
# File 'lib/vagrant-vbguest/machine.rb', line 53

def reboot?; box_state.state == :rebooted end

#rebuildObject



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 options[:no_install] && !options[:force]
  guest_additions_state.trigger :rebuild
end

#rebuilt?Boolean

Returns:

  • (Boolean)


50
# File 'lib/vagrant-vbguest/machine.rb', line 50

def rebuilt?; guest_additions_state == :rebuilt end

#runObject



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

#startObject



44
45
46
# File 'lib/vagrant-vbguest/machine.rb', line 44

def start
  guest_additions_state.trigger :start
end

#started?Boolean

Returns:

  • (Boolean)


49
# File 'lib/vagrant-vbguest/machine.rb', line 49

def started?; guest_additions_state == :started end

#stateObject



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