vagrant-winnfsd 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +16 -0
- data/CHANGELOG +11 -0
- data/Gemfile +11 -0
- data/LICENSE +13 -0
- data/README.md +17 -0
- data/Rakefile +21 -0
- data/bin/nfsservice.bat +41 -0
- data/bin/winnfsd.exe +0 -0
- data/lib/vagrant-winnfsd.rb +18 -0
- data/lib/vagrant-winnfsd/config.rb +26 -0
- data/lib/vagrant-winnfsd/host.rb +65 -0
- data/lib/vagrant-winnfsd/plugin.rb +59 -0
- data/lib/vagrant-winnfsd/synced_folder.rb +48 -0
- data/lib/vagrant-winnfsd/version.rb +5 -0
- data/locales/en.yml +13 -0
- data/spec/vagrant-winnfsd/config_spec.rb +11 -0
- data/vagrant-winnfsd.gemspec +53 -0
- metadata +70 -0
data/.gitignore
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
# We depend on Vagrant for development, but we don't add it as a
|
7
|
+
# gem dependency because we expect to be installed within the
|
8
|
+
# Vagrant environment itself using `vagrant plugin`.
|
9
|
+
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :branch => "master"
|
10
|
+
gem "rspec"
|
11
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2013 Alexander Schneider - Jankowfsky AG
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Vagrant WinNFSd
|
2
|
+
|
3
|
+
Manage and adds support for NFS on windows.
|
4
|
+
|
5
|
+
## Supported Platforms
|
6
|
+
|
7
|
+
As of version 1.0.0 or later Vagrant 1.4 is required.
|
8
|
+
|
9
|
+
Supported guests:
|
10
|
+
|
11
|
+
* Linux
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```
|
16
|
+
$ vagrant plugin install vagrant-winnfsd
|
17
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
#require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
# Immediately sync all stdout so that tools like buildbot can
|
6
|
+
# immediately load in the output.
|
7
|
+
$stdout.sync = true
|
8
|
+
$stderr.sync = true
|
9
|
+
|
10
|
+
# Change to the directory of this file.
|
11
|
+
Dir.chdir(File.expand_path("../", __FILE__))
|
12
|
+
|
13
|
+
# This installs the tasks that help with gem creation and
|
14
|
+
# publishing.
|
15
|
+
Bundler::GemHelper.install_tasks
|
16
|
+
|
17
|
+
# Install the `spec` task so that we can run tests.
|
18
|
+
#RSpec::Core::RakeTask.new
|
19
|
+
|
20
|
+
# Default task is to run the unit tests
|
21
|
+
#task :default => "spec"
|
data/bin/nfsservice.bat
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
@echo off
|
2
|
+
tasklist /nh /fi "imagename eq winnfsd.exe" 2>nul | grep -i -c "winnfsd.exe" >nfsservicetmp
|
3
|
+
set /p RUNNINGTASKS=<nfsservicetmp
|
4
|
+
del nfsservicetmp
|
5
|
+
|
6
|
+
if %1==status (
|
7
|
+
:: printf "[NFS] Status: "
|
8
|
+
if %RUNNINGTASKS% == 0 (
|
9
|
+
:: printf "halted\n"
|
10
|
+
exit 1
|
11
|
+
) else (
|
12
|
+
:: printf "running\n"
|
13
|
+
exit 0
|
14
|
+
)
|
15
|
+
)
|
16
|
+
|
17
|
+
if %1==start (
|
18
|
+
printf "[NFS] Start: "
|
19
|
+
if %RUNNINGTASKS% == 0 (
|
20
|
+
start "%~dp0winnfsd" -log off -pathFile %2
|
21
|
+
printf "started\n"
|
22
|
+
) else (
|
23
|
+
printf "already running\n"
|
24
|
+
)
|
25
|
+
|
26
|
+
exit 0
|
27
|
+
)
|
28
|
+
|
29
|
+
if %1==halt (
|
30
|
+
printf "[NFS] Halt: "
|
31
|
+
if %RUNNINGTASKS% == 0 (
|
32
|
+
printf "not running\n"
|
33
|
+
) else (
|
34
|
+
taskkill /f /im "winnfsd.exe" >nul
|
35
|
+
printf "halt\n"
|
36
|
+
)
|
37
|
+
|
38
|
+
exit 0
|
39
|
+
)
|
40
|
+
|
41
|
+
exit 1
|
data/bin/winnfsd.exe
ADDED
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module VagrantWinNFSd
|
3
|
+
require 'vagrant-winnfsd/version'
|
4
|
+
require 'vagrant-winnfsd/plugin'
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.get_binary_path
|
11
|
+
source_root.join("bin")
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.get_path_for_file(file)
|
15
|
+
get_binary_path.join(file).to_s.gsub('/', '\\')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
require Vagrant.source_root.join("plugins/kernel_v2/config/vm")
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module VagrantWinNFSd
|
6
|
+
class Config < VagrantPlugins::Kernel_V2::VMConfig
|
7
|
+
def finalize!
|
8
|
+
switch_back = {}
|
9
|
+
|
10
|
+
@__synced_folders.each do |id, options|
|
11
|
+
if (options[:nfs] || options[:type] == :nfs) && Vagrant::Util::Platform.windows?
|
12
|
+
switch_back[id] = true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
super
|
17
|
+
|
18
|
+
@__synced_folders.each do |id, options|
|
19
|
+
if options[:type] != :nfs && !switch_back[id].nil?
|
20
|
+
options[:type] = :nfs
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require Vagrant.source_root.join("plugins/hosts/windows/host")
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module VagrantWinNFSd
|
5
|
+
class Host < Vagrant.plugin("2", :host)
|
6
|
+
def self.match?
|
7
|
+
Vagrant::Util::Platform.windows?
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(*args)
|
11
|
+
super
|
12
|
+
|
13
|
+
@logger = Log4r::Logger.new("vagrant::hosts::windows")
|
14
|
+
|
15
|
+
executable = VagrantWinNFSd.get_path_for_file("nfsservice.bat")
|
16
|
+
@nfs_check_command = "\"#{executable}\" status"
|
17
|
+
@nfs_start_command = "\"#{executable}\" start"
|
18
|
+
@nfs_stop_command = "\"#{executable}\" halt"
|
19
|
+
@nfs_path_file = "nfspaths"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Windows does not support NFS
|
23
|
+
def nfs?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def nfs_export(id, ips, folders)
|
28
|
+
@ui.info I18n.t("vagrant_winnfsd.hosts.windows.nfs_export")
|
29
|
+
sleep 0.5
|
30
|
+
|
31
|
+
folders.each do |k, opts|
|
32
|
+
hostpath = opts[:hostpath].dup
|
33
|
+
hostpath.gsub!("'", "'\\\\''")
|
34
|
+
hostpath.gsub('/', '\\')
|
35
|
+
system("echo #{hostpath} >>#@nfs_path_file")
|
36
|
+
end
|
37
|
+
|
38
|
+
system("#@nfs_start_command .\\#@nfs_path_file")
|
39
|
+
sleep 2
|
40
|
+
end
|
41
|
+
|
42
|
+
def nfs_prune(valid_ids)
|
43
|
+
@ui.info I18n.t("vagrant_winnfsd.hosts.windows.nfs_prune")
|
44
|
+
@logger.info("Pruning invalid NFS entries...")
|
45
|
+
nfs_cleanup()
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def nfs_running?
|
51
|
+
system("#@nfs_check_command")
|
52
|
+
end
|
53
|
+
|
54
|
+
def nfs_cleanup()
|
55
|
+
if nfs_running?
|
56
|
+
system("#@nfs_stop_command")
|
57
|
+
end
|
58
|
+
|
59
|
+
if !nfs_running? && File.exist?(@nfs_path_file)
|
60
|
+
File.delete(@nfs_path_file)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
begin
|
2
|
+
require 'vagrant'
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant WinNFSd plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
if Vagrant::VERSION < "1.4.0"
|
8
|
+
raise "The Vagrant AWS plugin is only compatible with Vagrant 1.4.0+"
|
9
|
+
end
|
10
|
+
|
11
|
+
module VagrantPlugins
|
12
|
+
module VagrantWinNFSd
|
13
|
+
class Plugin < Vagrant.plugin(2)
|
14
|
+
name 'WinNFSd'
|
15
|
+
|
16
|
+
description <<-DESC
|
17
|
+
This plugin adds NFS support on Windows for Vagrant.
|
18
|
+
DESC
|
19
|
+
|
20
|
+
action_hook(:init_i18n, :environment_load) { init_plugin }
|
21
|
+
|
22
|
+
config("vm") do |env|
|
23
|
+
require_relative "config"
|
24
|
+
Config
|
25
|
+
end
|
26
|
+
|
27
|
+
synced_folder("nfs") do
|
28
|
+
require_relative "synced_folder"
|
29
|
+
SyncedFolder
|
30
|
+
end
|
31
|
+
|
32
|
+
host("windows") do
|
33
|
+
require_relative "host"
|
34
|
+
Host
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.init_plugin
|
38
|
+
I18n.load_path << File.expand_path('locales/en.yml', VagrantWinNFSd.source_root)
|
39
|
+
I18n.reload!
|
40
|
+
|
41
|
+
rule_name = "VagrantWinNFSd"
|
42
|
+
program = VagrantWinNFSd.get_path_for_file("winnfsd.exe")
|
43
|
+
rule_exist = "netsh advfirewall firewall show rule name=\"%s\">nul"
|
44
|
+
|
45
|
+
unless system(sprintf(rule_exist, rule_name))
|
46
|
+
rule = "netsh advfirewall firewall add rule name=\"%s\" dir=\"%s\" action=allow protocol=any program=\"%s\" profile=any>nul"
|
47
|
+
in_rule = sprintf(rule, rule_name, 'in', program)
|
48
|
+
out_rule = sprintf(rule, rule_name, 'out', program)
|
49
|
+
|
50
|
+
if !system(in_rule) || !system(out_rule)
|
51
|
+
puts I18n.t("vagrant_winnfsd.firewall.error")
|
52
|
+
puts "#{in_rule}\n"
|
53
|
+
puts "#{out_rule}\n"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
require Vagrant.source_root.join("plugins/synced_folders/nfs/synced_folder")
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module VagrantWinNFSd
|
6
|
+
class SyncedFolder < VagrantPlugins::SyncedFolderNFS::SyncedFolder
|
7
|
+
def enable(machine, folders, nfsopts)
|
8
|
+
raise Vagrant::Errors::NFSNoHostIP if !nfsopts[:nfs_host_ip]
|
9
|
+
raise Vagrant::Errors::NFSNoGuestIP if !nfsopts[:nfs_machine_ip]
|
10
|
+
|
11
|
+
machine_ip = nfsopts[:nfs_machine_ip]
|
12
|
+
machine_ip = [machine_ip] if !machine_ip.is_a?(Array)
|
13
|
+
|
14
|
+
# Prepare the folder, this means setting up various options
|
15
|
+
# and such on the folder itself.
|
16
|
+
folders.each { |id, opts| prepare_folder(machine, opts) }
|
17
|
+
|
18
|
+
# Export the folders
|
19
|
+
machine.ui.info I18n.t("vagrant.actions.vm.nfs.exporting")
|
20
|
+
machine.env.host.nfs_export(machine.id, machine_ip, folders)
|
21
|
+
|
22
|
+
# Mount
|
23
|
+
machine.ui.info I18n.t("vagrant.actions.vm.nfs.mounting")
|
24
|
+
|
25
|
+
# Only mount folders that have a guest path specified.
|
26
|
+
mount_folders = {}
|
27
|
+
folders.each do |id, opts|
|
28
|
+
if Vagrant::Util::Platform.windows?
|
29
|
+
unless opts[:mount_options]
|
30
|
+
mount_opts = ["vers=#{opts[:nfs_version]}"]
|
31
|
+
mount_opts << "udp" if opts[:nfs_udp]
|
32
|
+
mount_opts << "nolock"
|
33
|
+
|
34
|
+
opts[:mount_options] = mount_opts
|
35
|
+
end
|
36
|
+
|
37
|
+
opts[:hostpath] = '/' + opts[:hostpath].gsub(':', '').gsub('\\', '/')
|
38
|
+
end
|
39
|
+
mount_folders[id] = opts.dup if opts[:guestpath]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Mount them!
|
43
|
+
machine.guest.capability(
|
44
|
+
:mount_nfs_folder, nfsopts[:nfs_host_ip], mount_folders)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
vagrant_winnfsd:
|
4
|
+
hosts:
|
5
|
+
windows:
|
6
|
+
nfs_export: |-
|
7
|
+
Preparing to edit nfs mounting file.
|
8
|
+
nfs_prune: |-
|
9
|
+
Pruning invalid NFS exports.
|
10
|
+
firewall:
|
11
|
+
error: |-
|
12
|
+
It seems that you don't have the prevelegs to change the firewall rules. NFS will not work without that firewall
|
13
|
+
changes. Run Vagrant as administartor or execute the following comands as administartor:
|
@@ -0,0 +1,53 @@
|
|
1
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
require "vagrant-winnfsd/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'vagrant-winnfsd'
|
6
|
+
gem.version = VagrantPlugins::VagrantWinNFSd::VERSION
|
7
|
+
|
8
|
+
gem.summary = 'Adds NFS support for Windows'
|
9
|
+
gem.description = <<-EOD
|
10
|
+
Manage and adds support for NFS on windows.
|
11
|
+
EOD
|
12
|
+
|
13
|
+
gem.authors = 'Alexander Schneider'
|
14
|
+
gem.email = 'alexander.schneider@jankowfsky.com'
|
15
|
+
gem.homepage = 'https://github.com/gm-alex/vagrant-winnfsd'
|
16
|
+
|
17
|
+
gem.has_rdoc = true
|
18
|
+
gem.license = 'Apache 2.0'
|
19
|
+
|
20
|
+
# The following block of code determines the files that should be included
|
21
|
+
# in the gem. It does this by reading all the files in the directory where
|
22
|
+
# this gemspec is, and parsing out the ignored files from the gitignore.
|
23
|
+
# Note that the entire gitignore(5) syntax is not supported, specifically
|
24
|
+
# the "!" syntax, but it should mostly work correctly.
|
25
|
+
root_path = File.dirname(__FILE__)
|
26
|
+
all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
|
27
|
+
all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
|
28
|
+
gitignore_path = File.join(root_path, ".gitignore")
|
29
|
+
gitignore = File.readlines(gitignore_path)
|
30
|
+
gitignore.map! { |line| line.chomp.strip }
|
31
|
+
gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
|
32
|
+
|
33
|
+
unignored_files = all_files.reject do |file|
|
34
|
+
# Ignore any directories, the gemspec only cares about files
|
35
|
+
next true if File.directory?(file)
|
36
|
+
|
37
|
+
# Ignore any paths that match anything in the gitignore. We do
|
38
|
+
# two tests here:
|
39
|
+
#
|
40
|
+
# - First, test to see if the entire path matches the gitignore.
|
41
|
+
# - Second, match if the basename does, this makes it so that things
|
42
|
+
# like '.DS_Store' will match sub-directories too (same behavior
|
43
|
+
# as git).
|
44
|
+
#
|
45
|
+
gitignore.any? do |ignore|
|
46
|
+
File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
|
47
|
+
File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
gem.files = unignored_files
|
52
|
+
gem.require_path = 'lib'
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-winnfsd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexander Schneider
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! ' Manage and adds support for NFS on windows.
|
15
|
+
|
16
|
+
'
|
17
|
+
email: alexander.schneider@jankowfsky.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- bin/nfsservice.bat
|
23
|
+
- bin/winnfsd.exe
|
24
|
+
- CHANGELOG
|
25
|
+
- Gemfile
|
26
|
+
- lib/vagrant-winnfsd/config.rb
|
27
|
+
- lib/vagrant-winnfsd/host.rb
|
28
|
+
- lib/vagrant-winnfsd/plugin.rb
|
29
|
+
- lib/vagrant-winnfsd/synced_folder.rb
|
30
|
+
- lib/vagrant-winnfsd/version.rb
|
31
|
+
- lib/vagrant-winnfsd.rb
|
32
|
+
- LICENSE
|
33
|
+
- locales/en.yml
|
34
|
+
- Rakefile
|
35
|
+
- README.md
|
36
|
+
- spec/vagrant-winnfsd/config_spec.rb
|
37
|
+
- vagrant-winnfsd.gemspec
|
38
|
+
- .gitignore
|
39
|
+
homepage: https://github.com/gm-alex/vagrant-winnfsd
|
40
|
+
licenses:
|
41
|
+
- Apache 2.0
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
hash: 956270419
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
hash: 956270419
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.28
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Adds NFS support for Windows
|
70
|
+
test_files: []
|