Class: Vagrant::Plugin::Remote::Communicator

Inherits:
V2::Communicator show all
Defined in:
lib/vagrant/plugin/remote/communicator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from V2::Communicator

match?

Constructor Details

#initialize(machine, **kwargs) ⇒ Communicator

Returns a new instance of Communicator.



12
13
14
15
16
17
18
19
20
21
# File 'lib/vagrant/plugin/remote/communicator.rb', line 12

def initialize(machine, **kwargs)
  @logger = Log4r::Logger.new("vagrant::remote::communicator")
  @logger.debug("initializing communicator with remote backend")
  @machine = machine
  @client = kwargs.fetch(:client, machine.client.communicate)
  if @client.nil?
    raise ArgumentError,
      "Remote client is required for `#{self.class.name}`"
  end
end

Instance Attribute Details

#clientObject

Add an attribute accesor for the client when applied to the Communicator class



10
11
12
# File 'lib/vagrant/plugin/remote/communicator.rb', line 10

def client
  @client
end

Instance Method Details

#download(from, to) ⇒ Object



33
34
35
36
# File 'lib/vagrant/plugin/remote/communicator.rb', line 33

def download(from, to)
  @logger.debug("remote communicator, downloading #{from} -> #{to}")
  @client.download(@machine, from, to)
end

#execute(cmd, opts = nil) {|:stdout, res.stdout| ... } ⇒ Object

Yields:

  • (:stdout, res.stdout)


43
44
45
46
47
48
49
# File 'lib/vagrant/plugin/remote/communicator.rb', line 43

def execute(cmd, opts=nil, &block)
  @logger.debug("remote communicator, executing command")
  res = @client.execute(@machine, cmd, opts)
  yield :stdout, res.stdout if block_given?
  yield :stderr, res.stderr if block_given?
  res.exit_code
end

#ready?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/vagrant/plugin/remote/communicator.rb', line 23

def ready?
  @logger.debug("remote communicator, checking if it's ready")
  @client.ready(@machine)
end

#reset!Object



64
65
66
67
# File 'lib/vagrant/plugin/remote/communicator.rb', line 64

def reset!
  @logger.debug("remote communicator, reseting")
  @client.reset(@machine)
end

#sudo(cmd, opts = nil) {|:stdout, res.stdout| ... } ⇒ Object

Yields:

  • (:stdout, res.stdout)


51
52
53
54
55
56
57
# File 'lib/vagrant/plugin/remote/communicator.rb', line 51

def sudo(cmd, opts=nil, &block)
  @logger.debug("remote communicator, executing (privileged) command")
  res = @client.privileged_execute(@machine, cmd, opts)
  yield :stdout, res.stdout if block_given?
  yield :stderr, res.stderr if block_given?
  res.exit_code
end

#test(cmd, opts = nil) ⇒ Object



59
60
61
62
# File 'lib/vagrant/plugin/remote/communicator.rb', line 59

def test(cmd, opts=nil)
  @logger.debug("remote communicator, testing command")
  @client.test(@machine, cmd, opts)
end

#to_protoObject



69
70
71
# File 'lib/vagrant/plugin/remote/communicator.rb', line 69

def to_proto
  client.proto
end

#upload(from, to) ⇒ Object



38
39
40
41
# File 'lib/vagrant/plugin/remote/communicator.rb', line 38

def upload(from, to)
  @logger.debug("remote communicator, uploading #{from} -> #{to}")
  @client.upload(@machine, from, to)
end

#wait_for_ready(time) ⇒ Object



28
29
30
31
# File 'lib/vagrant/plugin/remote/communicator.rb', line 28

def wait_for_ready(time)
  @logger.debug("remote communicator, waiting for ready")
  @client.wait_for_ready(@machine, time)
end