2014-01-13 19:01:50 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
2014-01-13 19:25:29 +00:00
|
|
|
require "vagrant/action/builtin/mixin_synced_folders"
|
|
|
|
|
2014-01-13 19:01:50 +00:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module SyncedFolderRSync
|
|
|
|
module Command
|
|
|
|
class Rsync < Vagrant.plugin("2", :command)
|
2014-01-13 19:25:29 +00:00
|
|
|
include Vagrant::Action::Builtin::MixinSyncedFolders
|
|
|
|
|
2014-01-13 19:01:50 +00:00
|
|
|
def self.synopsis
|
|
|
|
"syncs rsync synced folders to remote machine"
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
opts = OptionParser.new do |o|
|
|
|
|
o.banner = "Usage: vagrant rsync [vm-name]"
|
|
|
|
o.separator ""
|
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the options and return if we don't have any target.
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
|
|
|
|
|
|
|
# Go through each machine and perform the rsync
|
|
|
|
error = false
|
|
|
|
with_target_vms(argv) do |machine|
|
|
|
|
if !machine.communicate.ready?
|
|
|
|
machine.ui.error(I18n.t("vagrant.rsync_communicator_not_ready"))
|
|
|
|
error = true
|
|
|
|
next
|
|
|
|
end
|
2014-01-13 19:25:29 +00:00
|
|
|
|
|
|
|
# Determine the rsync synced folders for this machine
|
|
|
|
folders = synced_folders(machine)[:rsync]
|
|
|
|
next if !folders || folders.empty?
|
|
|
|
|
|
|
|
# Get the SSH info for this machine so we can access it
|
|
|
|
ssh_info = machine.ssh_info
|
|
|
|
|
|
|
|
# Sync them!
|
|
|
|
folders.each do |id, folder_opts|
|
|
|
|
RsyncHelper.rsync_single(machine, ssh_info, folder_opts)
|
|
|
|
end
|
2014-01-13 19:01:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return error ? 1 : 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|