Class: Vagrant::Plugin::V1::Communicator

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/plugin/v1/communicator.rb

Overview

Base class for a communicator in Vagrant. A communicator is responsible for communicating with a machine in some way. There are various stages of Vagrant that require things such as uploading files to the machine, executing shell commands, etc. Implementors of this class are expected to provide this functionality in some way.

Note that a communicator must provide all of the methods in this base class. There is currently no way for one communicator to provide say a more efficient way of uploading a file, but not provide shell execution. This sort of thing will come in a future version.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ Communicator

Initializes the communicator with the machine that we will be communicating with. This base method does nothing (it doesn’t even store the machine in an instance variable for you), so you’re expected to override this and do something with the machine if you care about it.

Parameters:

  • machine (Machine)

    The machine this instance is expected to communicate with.



35
36
# File 'lib/vagrant/plugin/v1/communicator.rb', line 35

def initialize(machine)
end

Class Method Details

.match?(machine) ⇒ Boolean

This returns true/false depending on if the given machine can be communicated with using this communicator. If this returns ‘true`, then this class will be used as the primary communication method for the machine.

Returns:

  • (Boolean)


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

def self.match?(machine)
  false
end

Instance Method Details

#download(from, to) ⇒ Object

Download a file from the remote machine to the local machine.

Parameters:

  • from (String)

    Path of the file on the remote machine.

  • to (String)

    Path of where to save the file locally.



51
52
# File 'lib/vagrant/plugin/v1/communicator.rb', line 51

def download(from, to)
end

#execute(command, opts = nil) {|type, data| ... } ⇒ Integer

Execute a command on the remote machine. The exact semantics of this method are up to the implementor, but in general the users of this class will expect this to be a shell.

This method gives you no way to write data back to the remote machine, so only execute commands that don’t expect input.

Parameters:

  • command (String)

    Command to execute.

Yields:

  • (type, data)

    Realtime output of the command being executed.

Yield Parameters:

  • type (String)

    Type of the output. This can be ‘:stdout`, `:stderr`, etc. The exact types are up to the implementor.

  • data (String)

    Data for the given output.

Returns:

  • (Integer)

    Exit code of the command.



76
77
# File 'lib/vagrant/plugin/v1/communicator.rb', line 76

def execute(command, opts=nil)
end

#ready?Boolean

Checks if the target machine is ready for communication. If this returns true, then all the other methods for communicating with the machine are expected to be functional.

Returns:

  • (Boolean)


43
44
45
# File 'lib/vagrant/plugin/v1/communicator.rb', line 43

def ready?
  false
end

#sudo(command, opts = nil) ⇒ Object

Executes a command on the remote machine with administrative privileges. See #execute for documentation, as the API is the same.

See Also:



84
85
# File 'lib/vagrant/plugin/v1/communicator.rb', line 84

def sudo(command, opts=nil)
end

#test(command, opts = nil) ⇒ Object

Executes a command and returns true if the command succeeded, and false otherwise. By default, this executes as a normal user, and it is up to the communicator implementation if they expose an option for running tests as an administrator.

See Also:



93
94
# File 'lib/vagrant/plugin/v1/communicator.rb', line 93

def test(command, opts=nil)
end

#upload(from, to) ⇒ Object

Upload a file to the remote machine.

Parameters:

  • from (String)

    Path of the file locally to upload.

  • to (String)

    Path of where to save the file on the remote machine.



59
60
# File 'lib/vagrant/plugin/v1/communicator.rb', line 59

def upload(from, to)
end