Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smb synced folders for Windows "guests" #47

Merged
merged 9 commits into from
May 22, 2015
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

## 0.7.0 (unreleased)

* ...
* Change folder synchronization mechanism for Windows guests from the naive WinRM
uploader, which is quite slow, to the built-in Vagrant SMB folder sync. No change
to non-windows folder sync.([#46](https://github.com/tknerr/vagrant-managed-servers/issues/46))

## 0.6.1 (released 2015-04-02)

Expand Down
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ group :development do
# We depend on Vagrant for development, but we don't add it as a
# gem dependency because we expect to be installed within the
# Vagrant environment itself using `vagrant plugin`.
gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
gem "vagrant", git: "https://github.com/mitchellh/vagrant.git", ref: "v1.7.2"
end

group :plugins do
gem "vagrant-managed-servers", path: "."
gem "vagrant-omnibus", "1.4.1"
gem "vagrant-berkshelf", "3.0.1"
end
gem "vagrant-winrm-syncedfolders"
end
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,18 @@ config.vm.define 'my-windows-server' do |windows|
end
end
```
Synchronization of files using WinRM is known to be slow, so it is recommended
that you disable synched folders that aren't critical. For instance, to disable the
default /vagrant share, you could use the following code:

### Synced folders
Vagrant Managed Servers will try several different mechanisms to sync folders for Windows guests. In order of priority:

1. [SMB](http://docs.vagrantup.com/v2/synced-folders/smb.html) - requires running from a Windows host, an Administrative console, and Powershell 3 or greater. Note that there is a known [bug](https://github.com/mitchellh/vagrant/issues/3139) which causes the Powershell version check to hang for Powershell 2
2. [WinRM](https://github.com/cimpress-mcp/vagrant-winrm-syncedfolders) - uses the WinRM communicator and is reliable, but can be slow for large numbers of files.
3. [RSync](http://docs.vagrantup.com/v2/synced-folders/rsync.html) - requires `rsync.exe` installed and on your path.

Vagrant will try to use the best folder synchronization mechanism given your host and guest capabilities, but you can force a different type of folder sync with the `type` parameter of the `synced_folder` property in your Vagrantfile.

```ruby
windows.vm.synced_folder '.', '/vagrant', disabled: true
windows.vm.synced_folder '.', '/vagrant', type: "winrm"
```

## Development
Expand Down
59 changes: 45 additions & 14 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,66 @@
Vagrant.configure("2") do |config|

#
# fake a managed server by bringing up a virtualbox vm
# fake a managed linux server by bringing up a virtualbox vm
#
config.vm.define :fake_managed_server do |fms_config|
fms_config.vm.box = "chef/ubuntu-12.04-i386"
fms_config.vm.network :private_network, ip: "192.168.40.35"
fms_config.berkshelf.enabled = false
config.vm.define :local_linux do |ll_config|
ll_config.vm.box = "chef/ubuntu-12.04-i386"
ll_config.vm.network :private_network, ip: "192.168.40.35"
ll_config.berkshelf.enabled = false
ll_config.vm.synced_folder ".", "/vagrant", disabled: true
end

#
# configure managed provider to connect to `fake_managed_server`
# configure managed provider to connect to `local_linux`
#
config.vm.define :my_server do |ms_config|
config.vm.define :managed_linux do |ml_config|

ms_config.vm.box = "tknerr/managed-server-dummy"
ml_config.vm.box = "tknerr/managed-server-dummy"

ms_config.omnibus.chef_version = "12.0.3"
ms_config.berkshelf.enabled = true
ms_config.vm.provider :managed do |managed_config, override|
ml_config.omnibus.chef_version = "12.0.3"
ml_config.berkshelf.enabled = true

ml_config.vm.provider :managed do |managed_config, override|
managed_config.server = "192.168.40.35"
override.ssh.username = "vagrant"
override.ssh.private_key_path = ".vagrant/machines/fake_managed_server/virtualbox/private_key"
override.ssh.private_key_path = ".vagrant/machines/local_linux/virtualbox/private_key"
end

ms_config.vm.provision :chef_solo do |chef|
ml_config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = [ './cookbooks' ]
chef.add_recipe "apt"
chef.add_recipe "apache2"
end
end



#
# fake a managed windows server by bringing up a virtualbox vm
#
config.vm.define :local_windows do |lw_config|
lw_config.vm.box = "boxcutter/eval-win7x86-enterprise"
lw_config.vm.network :private_network, ip: "192.168.40.36"
lw_config.berkshelf.enabled = false
lw_config.vm.synced_folder ".", "/vagrant", disabled: true
end

#
# configure managed provider to connect to `local_windows`
#
config.vm.define :managed_windows do |mw_config|

mw_config.vm.box = "tknerr/managed-server-dummy"

mw_config.berkshelf.enabled = false

mw_config.vm.communicator = :winrm
mw_config.winrm.username = 'vagrant'
mw_config.winrm.password = 'vagrant'

mw_config.vm.provider :managed do |managed, override|
managed.server = '192.168.40.36'
end
end

end
25 changes: 9 additions & 16 deletions lib/vagrant-managed-servers/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@ def self.action_up

b2.use LinkServer
end
=begin
b.use HandleBoxUrl
b.use ConfigValidate
b.use Call, IsReachable do |env, b2|
if env[:result]
b2.use !MessageNotReachable
next
end

b2.use Provision
b2.use SyncFolders
b2.use WarnNetworks
b2.use LinkServer
end
=end
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just removing commented out code for cleanliness.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! :-) 👍

end

Expand Down Expand Up @@ -77,7 +62,15 @@ def self.action_provision
end

b3.use Provision
b3.use SyncFolders
if env[:machine].config.vm.communicator == :winrm
# Use the builtin vagrant folder sync for Windows target servers.
# This gives us SMB folder sharing, which is much faster than the
# WinRM uploader for any non-trivial number of files.
b3.use Vagrant::Action::Builtin::SyncedFolders
else
# Vagrant managed servers custom implementation
b3.use SyncFolders
end
end
end
end
Expand Down
16 changes: 0 additions & 16 deletions lib/vagrant-managed-servers/action/sync_folders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,6 @@ def call(env)
hostpath = File.expand_path(data[:hostpath], env[:root_path])
guestpath = data[:guestpath]

# Windows doesn't support ssh or rsync natively. Use winrm instead
if (env[:machine].config.vm.communicator == :winrm) then
env[:ui].info(I18n.t('vagrant_managed_servers.winrm_upload',
:hostpath => hostpath,
:guestpath => guestpath))
env[:machine].communicate.tap do |comm|
# When syncing many files, we've see SEC_E_INVALID_TOKEN errors
# that appear to be transient (try again and it goes away). Let's
# retry a few times to add some robustness.
retryable(tries: 3, sleep: 1) do
comm.upload(hostpath, guestpath)
end
end
next
end

unless Vagrant::Util::Which.which('rsync')
env[:ui].warn(I18n.t('vagrant_managed_servers.rsync_not_found_warning'))
break
Expand Down
1 change: 1 addition & 0 deletions vagrant-managed-servers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"
s.rubyforge_project = "vagrant-managed-servers"

s.add_runtime_dependency "vagrant-winrm-syncedfolders"
s.add_development_dependency "rake"
s.add_development_dependency "rspec-core", "~> 2.14.7"
s.add_development_dependency "rspec-expectations", "~> 2.14.5"
Expand Down