Class: VagrantPluginDummy::Communication::DummyCommunicator

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-plugin-dummy/communication/communicator.rb

Overview

Provides no communication with the machine.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ DummyCommunicator

Returns a new instance of DummyCommunicator.



17
18
19
20
21
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 17

def initialize(machine)
  @machine = machine
  @logger = Log4r::Logger.new("vagrant_plugin_dummy::communication::dummycommunicator")
  @logger.debug("initializing DummyCommunicator")
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



10
11
12
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 10

def logger
  @logger
end

#machineObject (readonly)

Returns the value of attribute machine.



11
12
13
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 11

def machine
  @machine
end

Class Method Details

.match?(machine) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 13

def self.match?(machine)
  machine.config.vm.guest.eql? :dummy
end

Instance Method Details

#download(from, to = nil) ⇒ Object



87
88
89
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 87

def download(from, to=nil)
  @logger.warn("DummyCommunicator.download isn't implemented")
end

#execute(command, opts = {}, &block) ⇒ Object Also known as: sudo



73
74
75
76
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 73

def execute(command, opts={}, &block)
  @logger.warn("DummyCommunicator.execute isn't implemented")
  return 0
end

#ready?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 23

def ready?
  provider = @machine.provider_name.id2name
  # NOTE: There is no timeout here.  We should probably have one...
  if provider == 'virtualbox'
    return ready_virtualbox?
  elsif provider == 'vmware_workstation' or provider == 'vmware_fusion'
    return ready_vmware?
  end
end

#ready_virtualbox?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 33

def ready_virtualbox?
  @logger.debug("Checking the status of NIC 0")
  nic_0_status = ''
  while nic_0_status !~ /Up/ do
    nic_0_status = @machine.provider.driver.execute('guestproperty', 'get', @machine.id, '/VirtualBox/GuestInfo/Net/0/Status') || ''
    @logger.debug("NIC 0 Status: "+ nic_0_status)
  end
  return true
end

#ready_vmware?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 43

def ready_vmware?
  @logger.debug("Checking if IP address is assigned")
  ip = nil
  while not ip do
    ip = nil
    # Try to get process list from guest, even with fake credentials
    # otherwise getGuestIPAddress will not return any value
    begin
        @machine.provider.driver.send(:vmrun, *['-gu', 'user',
                                                '-gp', 'password',
                                                'listProcessesInGuest',
                                                @machine.id])
    rescue Exception => e
        @logger.warn(e.message)
    end

    begin
        resp =  @machine.provider.driver.send(:vmrun, *['getGuestIPAddress', @machine.id])
    rescue Exception => e
        @logger.warn(e.message)
        sleep(1)
    else
        m = /(?<ip>\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3})/.match(resp.stdout)
        ip = (resp.exit_code == 0 and m) ? m['ip'] : nil
    end
    @logger.debug("Machine IP: #{ip}")
  end
  return true
end

#sessionObject



91
92
93
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 91

def session
  @session ||= new_session
end

#test(command, opts = nil) ⇒ Object



79
80
81
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 79

def test(command, opts=nil)
  return false unless @machine.config.vm.guest.eql? :dummy
end

#upload(from, to) ⇒ Object



83
84
85
# File 'lib/vagrant-plugin-dummy/communication/communicator.rb', line 83

def upload(from, to)
  @logger.warn("DummyCommunicator.upload isn't implemented")
end