Class: Vagrant::Communication::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/communication/base.rb

Overview

The base class for any classes that provide an API for communicating with the virtual machine.

There are various stages that require Vagrant to copy files or run commands on the target system, and communication classes provide the abstraction necessary to perform these tasks, via SSH or some other mechanism.

Any subclasses of this class must implement all of the methods below.

Direct Known Subclasses

SSH

Instance Method Summary collapse

Instance Method Details

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

Execute a command on the remote machine.

Parameters:

  • command (String)

    Command to execute.

Yields:

  • (type, data)

    Realtime output of the command being executed.

Yield Parameters:

  • type (String)

    Type of the output, :stdout, :stderr, etc.

  • data (String)

    Data for the given output.

Returns:

  • (Integer)

    Exit code of the command.



34
35
# File 'lib/vagrant/communication/base.rb', line 34

def execute(command, opts=nil)
end

#ready?Boolean

Checks if the target machine is ready for communication.

Returns:

  • (Boolean)


17
18
# File 'lib/vagrant/communication/base.rb', line 17

def ready?
end

#sudo(command, opts = nil) ⇒ Object

Execute a comand with super user privileges.

See #execute for parameter information.



40
41
# File 'lib/vagrant/communication/base.rb', line 40

def sudo(command, opts=nil)
end

#test(command, opts = nil) ⇒ Object

Executes a command and returns a boolean statement if it was successful or not.

This is implemented by default as expecting execute to return 0.



47
48
49
50
51
52
53
# File 'lib/vagrant/communication/base.rb', line 47

def test(command, opts=nil)
  # Disable error checking no matter what
  opts = (opts || {}).merge(:error_check => false)

  # Successful if the exit status is 0
  execute(command, opts) == 0
end

#upload(from, to) ⇒ Object

Upload a file to the virtual machine.

Parameters:

  • from (String)

    Path to a file to upload.

  • to (String)

    Path to where to save this file.



24
25
# File 'lib/vagrant/communication/base.rb', line 24

def upload(from, to)
end