Class: Vagrant::Smartos::Zones::Util::Rsync

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/smartos/zones/util/rsync.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Rsync

Returns a new instance of Rsync.



8
9
10
# File 'lib/vagrant/smartos/zones/util/rsync.rb', line 8

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/vagrant/smartos/zones/util/rsync.rb', line 6

def connection
  @connection
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/vagrant/smartos/zones/util/rsync.rb', line 12

def available?
  Vagrant::Util::Subprocess.execute(*%w(which rsync)).exit_code == 0
end

#download(from, to) ⇒ Object



16
17
18
# File 'lib/vagrant/smartos/zones/util/rsync.rb', line 16

def download(from, to)
  Vagrant::Util::Subprocess.execute(*rsync_command, '-e', ssh_command, remote(from), to, notify: [:stdout])
end

#identity_fileObject



32
33
34
# File 'lib/vagrant/smartos/zones/util/rsync.rb', line 32

def identity_file
  connection.options[:keys].first
end

#remote(file) ⇒ Object



36
37
38
# File 'lib/vagrant/smartos/zones/util/rsync.rb', line 36

def remote(file)
  "#{remote_user}@#{connection.host}:#{file}"
end

#remote_portObject



40
41
42
# File 'lib/vagrant/smartos/zones/util/rsync.rb', line 40

def remote_port
  connection.options[:port]
end

#remote_userObject



44
45
46
# File 'lib/vagrant/smartos/zones/util/rsync.rb', line 44

def remote_user
  connection.options[:user]
end

#rsync_commandObject



24
25
26
# File 'lib/vagrant/smartos/zones/util/rsync.rb', line 24

def rsync_command
  %w(rsync -avz --progress)
end

#ssh_commandObject



28
29
30
# File 'lib/vagrant/smartos/zones/util/rsync.rb', line 28

def ssh_command
  "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i #{identity_file} -p #{remote_port}"
end

#upload(from, to) ⇒ Object



20
21
22
# File 'lib/vagrant/smartos/zones/util/rsync.rb', line 20

def upload(from, to)
  Vagrant::Util::Subprocess.execute(*rsync_command, '-e', ssh_command, from, remote(to), notify: [:stdout])
end