vagrant-allegro-nfs 1.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/CHANGELOG +8 -0
- data/Gemfile +14 -0
- data/LICENSE +13 -0
- data/README.md +48 -0
- data/Rakefile +12 -0
- data/Vagrantfile.dist +121 -0
- data/elevated-script.bat +48 -0
- data/lib/vagrant-allegro-nfs/cap/nfs.rb +142 -0
- data/lib/vagrant-allegro-nfs/config.rb +26 -0
- data/lib/vagrant-allegro-nfs/host.rb +8 -0
- data/lib/vagrant-allegro-nfs/plugin.rb +74 -0
- data/lib/vagrant-allegro-nfs/synced_folder.rb +11 -0
- data/lib/vagrant-allegro-nfs/version.rb +5 -0
- data/lib/vagrant-allegro-nfs/windows_service.rb +88 -0
- data/lib/vagrant-allegro-nfs.rb +18 -0
- data/locales/en.yml +9 -0
- data/spec/classes/cap_nfs_spec.rb +91 -0
- data/spec/classes/windows_service_spec.rb +126 -0
- data/spec/spec_helper.rb +3 -0
- data/vagrant-allegro-nfs.gemspec +22 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae1823637c3546d58db7f0a91f3001176f5b0ced
|
4
|
+
data.tar.gz: 16417fe2955e10994b7907e7afd6908a1ff5c187
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5ce62c7cd7ef3c2fcf69aaa926dd6e71a85e3d773e18654b3b6d670d6b8e26f524bc689d14de1292b3faa48d57118480b7a91266171e13baf1be60cf431c49c
|
7
|
+
data.tar.gz: 9a075afa851bafee810738bc465e9dfff9933f4d2d54a45c4a2acb727e721268c1cc530dd27e51c07024a719cf4ecb58a22fd74ccfab10d0ac1168e8e46360f3
|
data/.gitignore
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
# We depend on Vagrant for development, but we don't add it as a
|
5
|
+
# gem dependency because we expect to be installed within the
|
6
|
+
# Vagrant environment itself using `vagrant plugin`.
|
7
|
+
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => "v1.8.5"
|
8
|
+
gem "rspec"
|
9
|
+
gem "rake"
|
10
|
+
end
|
11
|
+
|
12
|
+
group :plugins do
|
13
|
+
gem "vagrant-allegro-nfs", path: "."
|
14
|
+
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,48 @@
|
|
1
|
+
# Vagrant Allegro NFS
|
2
|
+
|
3
|
+
Manage and adds support for NFS on windows, using Allegro NFS Server.
|
4
|
+
|
5
|
+
## Supported Platforms
|
6
|
+
|
7
|
+
Only tested with Vagrant 1.8.0 or later and with Virtualbox 5.0 on Windows 10.
|
8
|
+
|
9
|
+
Supported guests:
|
10
|
+
|
11
|
+
* Linux
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```
|
16
|
+
$ vagrant plugin install vagrant-allegro-nfs
|
17
|
+
```
|
18
|
+
|
19
|
+
## Allegro NFS
|
20
|
+
|
21
|
+
You need to install Allegro NFS Server to use this plugin. Allegro NFS is
|
22
|
+
shareware and can be evaluated for 30 days.
|
23
|
+
|
24
|
+
You can get it here:
|
25
|
+
|
26
|
+
http://nfsforwindows.com/
|
27
|
+
|
28
|
+
## Contribute
|
29
|
+
|
30
|
+
To contribute, you will need the following requirements:
|
31
|
+
* Ruby >= 2.2
|
32
|
+
* Bundler = 1.12.5
|
33
|
+
|
34
|
+
First, install all dependencies: `bundle install --path vendor/bundle`
|
35
|
+
Then you can use the `Vagrantfile.dist` file to run a box with virtualbox:
|
36
|
+
|
37
|
+
```
|
38
|
+
#!bash
|
39
|
+
|
40
|
+
cp Vagrantfile.dist Vagrantfile
|
41
|
+
bundle exec vagrant up
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
## Thanks to
|
46
|
+
|
47
|
+
* @simonswine [vagrant-hanewin](https://github.com/simonswine/vagrant-hanewin-nfs) for his work on his plugin.
|
48
|
+
* @GM-Alex [vagrant-winnfsd](https://github.com/GM-Alex/vagrant-winnfsd) idea and basic structure of this plugin.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
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
|
+
# This installs the tasks that help with gem creation and
|
11
|
+
# publishing.
|
12
|
+
Bundler::GemHelper.install_tasks
|
data/Vagrantfile.dist
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
5
|
+
VAGRANTFILE_API_VERSION = "2"
|
6
|
+
|
7
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
8
|
+
# All Vagrant configuration is done here. The most common configuration
|
9
|
+
# options are documented and commented below. For a complete reference,
|
10
|
+
# please see the online documentation at vagrantup.com.
|
11
|
+
|
12
|
+
# Every Vagrant virtual environment requires a box to build off of.
|
13
|
+
config.vm.box = "puphpet/debian75-x64"
|
14
|
+
|
15
|
+
# The url from where the 'config.vm.box' box will be fetched if it
|
16
|
+
# doesn't already exist on the user's system.
|
17
|
+
# config.vm.box_url = "http://domain.com/path/to/above.box"
|
18
|
+
|
19
|
+
# Create a forwarded port mapping which allows access to a specific port
|
20
|
+
# within the machine from a port on the host machine. In the example below,
|
21
|
+
# accessing "localhost:8080" will access port 80 on the guest machine.
|
22
|
+
# config.vm.network "forwarded_port", guest: 80, host: 8080
|
23
|
+
|
24
|
+
# Create a private network, which allows host-only access to the machine
|
25
|
+
# using a specific IP.
|
26
|
+
# config.vm.network "private_network", ip: "192.168.33.10"
|
27
|
+
|
28
|
+
# Create a public network, which generally matched to bridged network.
|
29
|
+
# Bridged networks make the machine appear as another physical device on
|
30
|
+
# your network.
|
31
|
+
# config.vm.network "public_network"
|
32
|
+
|
33
|
+
# If true, then any SSH connections made will enable agent forwarding.
|
34
|
+
# Default value: false
|
35
|
+
# config.ssh.forward_agent = true
|
36
|
+
|
37
|
+
# Share an additional folder to the guest VM. The first argument is
|
38
|
+
# the path on the host to the actual folder. The second argument is
|
39
|
+
# the path on the guest to mount the folder. And the optional third
|
40
|
+
# argument is a set of non-required options.
|
41
|
+
config.vm.synced_folder "../", "/var/www", :nfs => true
|
42
|
+
config.vm.synced_folder ".", "/var/vagrant", :nfs => true
|
43
|
+
|
44
|
+
config.vm.network "private_network", ip: "192.168.56.40"
|
45
|
+
|
46
|
+
# Provider-specific configuration so you can fine-tune various
|
47
|
+
# backing providers for Vagrant. These expose provider-specific options.
|
48
|
+
# Example for VirtualBox:
|
49
|
+
#
|
50
|
+
# config.vm.provider "virtualbox" do |vb|
|
51
|
+
# # Don't boot with headless mode
|
52
|
+
# vb.gui = true
|
53
|
+
#
|
54
|
+
# # Use VBoxManage to customize the VM. For example to change memory:
|
55
|
+
# vb.customize ["modifyvm", :id, "--memory", "1024"]
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# View the documentation for the provider you're using for more
|
59
|
+
# information on available options.
|
60
|
+
|
61
|
+
# Enable provisioning with Puppet stand alone. Puppet manifests
|
62
|
+
# are contained in a directory path relative to this Vagrantfile.
|
63
|
+
# You will need to create the manifests directory and a manifest in
|
64
|
+
# the file base.pp in the manifests_path directory.
|
65
|
+
#
|
66
|
+
# An example Puppet manifest to provision the message of the day:
|
67
|
+
#
|
68
|
+
# # group { "puppet":
|
69
|
+
# # ensure => "present",
|
70
|
+
# # }
|
71
|
+
# #
|
72
|
+
# # File { owner => 0, group => 0, mode => 0644 }
|
73
|
+
# #
|
74
|
+
# # file { '/etc/motd':
|
75
|
+
# # content => "Welcome to your Vagrant-built virtual machine!
|
76
|
+
# # Managed by Puppet.\n"
|
77
|
+
# # }
|
78
|
+
#
|
79
|
+
# config.vm.provision "puppet" do |puppet|
|
80
|
+
# puppet.manifests_path = "manifests"
|
81
|
+
# puppet.manifest_file = "site.pp"
|
82
|
+
# end
|
83
|
+
|
84
|
+
# Enable provisioning with chef solo, specifying a cookbooks path, roles
|
85
|
+
# path, and data_bags path (all relative to this Vagrantfile), and adding
|
86
|
+
# some recipes and/or roles.
|
87
|
+
#
|
88
|
+
# config.vm.provision "chef_solo" do |chef|
|
89
|
+
# chef.cookbooks_path = "../my-recipes/cookbooks"
|
90
|
+
# chef.roles_path = "../my-recipes/roles"
|
91
|
+
# chef.data_bags_path = "../my-recipes/data_bags"
|
92
|
+
# chef.add_recipe "mysql"
|
93
|
+
# chef.add_role "web"
|
94
|
+
#
|
95
|
+
# # You may also specify custom JSON attributes:
|
96
|
+
# chef.json = { :mysql_password => "foo" }
|
97
|
+
# end
|
98
|
+
|
99
|
+
# Enable provisioning with chef server, specifying the chef server URL,
|
100
|
+
# and the path to the validation key (relative to this Vagrantfile).
|
101
|
+
#
|
102
|
+
# The Opscode Platform uses HTTPS. Substitute your organization for
|
103
|
+
# ORGNAME in the URL and validation key.
|
104
|
+
#
|
105
|
+
# If you have your own Chef Server, use the appropriate URL, which may be
|
106
|
+
# HTTP instead of HTTPS depending on your configuration. Also change the
|
107
|
+
# validation key to validation.pem.
|
108
|
+
#
|
109
|
+
# config.vm.provision "chef_client" do |chef|
|
110
|
+
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
|
111
|
+
# chef.validation_key_path = "ORGNAME-validator.pem"
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# If you're using the Opscode platform, your validator client is
|
115
|
+
# ORGNAME-validator, replacing ORGNAME with your organization name.
|
116
|
+
#
|
117
|
+
# If you have your own Chef Server, the default validation client name is
|
118
|
+
# chef-validator, unless you changed the configuration.
|
119
|
+
#
|
120
|
+
# chef.validation_client_name = "ORGNAME-validator"
|
121
|
+
end
|
data/elevated-script.bat
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
@ECHO OFF
|
2
|
+
setlocal EnableDelayedExpansion
|
3
|
+
|
4
|
+
NET FILE 1>NUL 2>NUL
|
5
|
+
if '%errorlevel%' == '0' ( goto START ) else ( goto getPrivileges )
|
6
|
+
|
7
|
+
:getPrivileges
|
8
|
+
if '%1'=='ELEV' ( goto START )
|
9
|
+
|
10
|
+
set "batchPath=%~f0"
|
11
|
+
set "batchArgs=ELEV"
|
12
|
+
|
13
|
+
::Add quotes to the batch path, if needed
|
14
|
+
set "script=%0"
|
15
|
+
set script=%script:"=%
|
16
|
+
IF '%0'=='!script!' ( GOTO PathQuotesDone )
|
17
|
+
set "batchPath=""%batchPath%"""
|
18
|
+
:PathQuotesDone
|
19
|
+
|
20
|
+
::Add quotes to the arguments, if needed.
|
21
|
+
:ArgLoop
|
22
|
+
IF '%1'=='' ( GOTO EndArgLoop ) else ( GOTO AddArg )
|
23
|
+
:AddArg
|
24
|
+
set "arg=%1"
|
25
|
+
set arg=%arg:"=%
|
26
|
+
IF '%1'=='!arg!' ( GOTO NoQuotes )
|
27
|
+
set "batchArgs=%batchArgs% "%1""
|
28
|
+
GOTO QuotesDone
|
29
|
+
:NoQuotes
|
30
|
+
set "batchArgs=%batchArgs% %1"
|
31
|
+
:QuotesDone
|
32
|
+
shift
|
33
|
+
GOTO ArgLoop
|
34
|
+
:EndArgLoop
|
35
|
+
|
36
|
+
::Create and run the vb script to elevate the batch file
|
37
|
+
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
|
38
|
+
ECHO UAC.ShellExecute "cmd", "/c ""!batchPath! !batchArgs!""", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
|
39
|
+
"%temp%\OEgetPrivileges.vbs"
|
40
|
+
exit /B
|
41
|
+
|
42
|
+
:START
|
43
|
+
::Remove the elevation tag and set the correct working directory
|
44
|
+
IF '%1'=='ELEV' ( shift /1 )
|
45
|
+
cd /d %~dp0
|
46
|
+
|
47
|
+
::Do your admin thing here...
|
48
|
+
sc %1 %2 %3 %4 %5
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'vagrant-allegro-nfs'
|
2
|
+
require 'vagrant-allegro-nfs/windows_service'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module VagrantAllegroNfs
|
6
|
+
module Cap
|
7
|
+
class NFS
|
8
|
+
def self.nfs_config_file_path
|
9
|
+
VagrantAllegroNfs.get_nfs_dir.join('nfs.cfg')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.logger
|
13
|
+
Log4r::Logger.new("vagrant::hosts::windows::nfs")
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.service_name
|
17
|
+
"NFSserver"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.nfs_export(env, ui, id, ips, folders)
|
21
|
+
# Get some values we need before we do anything
|
22
|
+
output = "
|
23
|
+
((common-lisp-user::*nfs-set-mtime-on-write* nil)
|
24
|
+
(common-lisp-user::*nfs-debug-timings* nil)
|
25
|
+
(common-lisp-user::*nfs-gc-debug* nil)
|
26
|
+
(common-lisp-user::*nfs-debug-filter* 268435455)
|
27
|
+
(common-lisp-user::*nfs-debug* nil)
|
28
|
+
(nlm:*nlm-port* nil) (nlm:*nlm-debug* nil)
|
29
|
+
(nsm:*nsm-port* nil) (nsm:*nsm-debug* nil)
|
30
|
+
(common-lisp-user::*attr-cache-reap-time* 5)
|
31
|
+
(common-lisp-user::*nfs-dircache-update-interval* 2)
|
32
|
+
(common-lisp-user::*log-rotation-file-size-magnitude*
|
33
|
+
1048576)
|
34
|
+
(common-lisp-user::*log-rotation-file-count* 1)
|
35
|
+
(common-lisp-user::*log-rotation-file-size* 0)
|
36
|
+
(mount:*showmount-disabled* nil)
|
37
|
+
(mount:*mountd-port-number* nil)
|
38
|
+
(mount:*mountd-debug* nil)
|
39
|
+
(portmap:*use-system-portmapper* :auto)
|
40
|
+
(portmap:*portmap-debug* nil)
|
41
|
+
(common-lisp-user::*disable-persistent-fhandles* nil)
|
42
|
+
(common-lisp-user::*executable-types*
|
43
|
+
(\"exe\" \"com\" \"bat\"))
|
44
|
+
(define-user-list \"root\" 0)
|
45
|
+
(define-user-list \"everyone\" t)
|
46
|
+
(define-host-list \"all\" t)
|
47
|
+
"
|
48
|
+
|
49
|
+
output += "(define-host-list \"%s\" \"%s\")" % [id, ips.join("\" \"")]
|
50
|
+
|
51
|
+
folders.each do |folder, opts|
|
52
|
+
if opts[:nfs] = true
|
53
|
+
# Build config
|
54
|
+
|
55
|
+
|
56
|
+
# Rewrite path for
|
57
|
+
drive=opts[:hostpath][0].downcase
|
58
|
+
mountPath = "/#{drive}/#{opts[:hostpath][3..-1]}"
|
59
|
+
|
60
|
+
output += "(define-export :name \"%s\"
|
61
|
+
:path \"%s\"
|
62
|
+
:uid 9999
|
63
|
+
:gid 9999
|
64
|
+
:umask 0
|
65
|
+
:set-mode-bits 0
|
66
|
+
:hosts-allow (\"%s\")
|
67
|
+
:rw-users (\"everyone\")
|
68
|
+
:ro-users (\"everyone\"))" % [mountPath, opts[:hostpath].gsub('\\', '\\\\'), id]
|
69
|
+
|
70
|
+
opts[:hostpath] = mountPath
|
71
|
+
# Add mountoptions
|
72
|
+
opts[:mount_options] = ['vers=3','udp','nolock']
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
output += ")"
|
77
|
+
# Remove entries with id
|
78
|
+
nfs_cleanup(id)
|
79
|
+
|
80
|
+
# Append to config
|
81
|
+
logger.info("Write nfs exports")
|
82
|
+
open(nfs_config_file_path, 'w') do |f|
|
83
|
+
f.write output
|
84
|
+
f.flush
|
85
|
+
f.close
|
86
|
+
end
|
87
|
+
|
88
|
+
# restart nfs
|
89
|
+
logger.info("Restart nfs")
|
90
|
+
nfs_apply_command = env.host.capability(:nfs_apply_command)
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.nfs_installed(env)
|
94
|
+
true
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.nfs_cleanup(id)
|
98
|
+
return if !File.exist?(nfs_config_file_path)
|
99
|
+
|
100
|
+
#id_re = Regexp.escape(id.to_s)
|
101
|
+
|
102
|
+
output = ""
|
103
|
+
|
104
|
+
# read per line
|
105
|
+
open(nfs_config_file_path, 'r').each do |line|
|
106
|
+
match = line.scan(/##VAGRANT#([^#]*)#/)
|
107
|
+
if match.length > 0
|
108
|
+
next if match[0][0] == id.to_s
|
109
|
+
end
|
110
|
+
output += line
|
111
|
+
end
|
112
|
+
|
113
|
+
# write to file
|
114
|
+
open(nfs_config_file_path, 'w') do |f|
|
115
|
+
f.write output
|
116
|
+
f.flush
|
117
|
+
f.close
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.nfs_prune(environment, ui, valid_ids)
|
122
|
+
# TODO Implement me
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.nfs_apply_command(env)
|
126
|
+
service = WindowsService.new('nfs')
|
127
|
+
service.restart
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.nfs_check_command(env)
|
131
|
+
service = WindowsService.new('nfs')
|
132
|
+
service.status
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.nfs_start_command(env)
|
136
|
+
service = WindowsService.new('nfs')
|
137
|
+
service.start
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
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 VagrantAllegroNfs
|
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 || 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,74 @@
|
|
1
|
+
begin
|
2
|
+
require 'vagrant'
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant Allegro NFS plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
if Vagrant::VERSION < "1.5.0"
|
8
|
+
raise "The Vagrant Allegro NFS plugin is only compatible with Vagrant 1.5.0+"
|
9
|
+
end
|
10
|
+
|
11
|
+
module VagrantPlugins
|
12
|
+
module VagrantAllegroNfs
|
13
|
+
class Plugin < Vagrant.plugin(2)
|
14
|
+
name 'vagrant-allegro-nfs'
|
15
|
+
|
16
|
+
description <<-DESC
|
17
|
+
This plugin adds NFS support on Windows for Vagrant with the Allegro NFS Server.
|
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_nfs", "windows") do
|
33
|
+
require_relative "host"
|
34
|
+
Host
|
35
|
+
end
|
36
|
+
|
37
|
+
host_capability("windows_nfs", "nfs_export") do
|
38
|
+
require_relative "cap/nfs"
|
39
|
+
Cap::NFS
|
40
|
+
end
|
41
|
+
|
42
|
+
host_capability("windows_nfs", "nfs_installed") do
|
43
|
+
require_relative "cap/nfs"
|
44
|
+
Cap::NFS
|
45
|
+
end
|
46
|
+
|
47
|
+
host_capability("windows_nfs", "nfs_prune") do
|
48
|
+
require_relative "cap/nfs"
|
49
|
+
Cap::NFS
|
50
|
+
end
|
51
|
+
|
52
|
+
host_capability("windows_nfs", "nfs_apply_command") do
|
53
|
+
require_relative "cap/nfs"
|
54
|
+
Cap::NFS
|
55
|
+
end
|
56
|
+
|
57
|
+
host_capability("windows_nfs", "nfs_check_command") do
|
58
|
+
require_relative "cap/nfs"
|
59
|
+
Cap::NFS
|
60
|
+
end
|
61
|
+
|
62
|
+
host_capability("windows_nfs", "nfs_start_command") do
|
63
|
+
require_relative "cap/nfs"
|
64
|
+
Cap::NFS
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.init_plugin
|
68
|
+
I18n.load_path << File.expand_path('locales/en.yml', VagrantAllegroNfs.source_root)
|
69
|
+
I18n.reload!
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require Vagrant.source_root.join("plugins/synced_folders/nfs/synced_folder")
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module VagrantAllegroNfs
|
5
|
+
class SyncedFolder < VagrantPlugins::SyncedFolderNFS::SyncedFolder
|
6
|
+
def usable?(machine,raise_error=false)
|
7
|
+
return true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module VagrantAllegroNfs
|
5
|
+
# Class reprents a windows service and allows
|
6
|
+
# to control this service via the sc command
|
7
|
+
class WindowsService
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@name = name
|
11
|
+
@sc_cmd = "sc"
|
12
|
+
@logger = Log4r::Logger.new("vagrant::hosts::windows")
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
# Run sc command
|
17
|
+
def run_cmd(command, elevation)
|
18
|
+
elevation_script = File.expand_path('elevated-script.bat', VagrantAllegroNfs.source_root)
|
19
|
+
if elevation == true
|
20
|
+
cmd = "#{elevation_script} #{command} \"#{@name}\""
|
21
|
+
else
|
22
|
+
cmd = "#{@sc_cmd} #{command} \"#{@name}\""
|
23
|
+
end
|
24
|
+
|
25
|
+
@logger.debug "WindowsServer run cmd #{cmd}"
|
26
|
+
stdout, stderr, status = Open3.capture3(cmd)
|
27
|
+
|
28
|
+
# Get allowed exit status
|
29
|
+
if command == 'start'
|
30
|
+
allowed_exitstatus = [0, 32]
|
31
|
+
elsif command == 'stop'
|
32
|
+
allowed_exitstatus = [0, 38]
|
33
|
+
else
|
34
|
+
allowed_exitstatus = [0]
|
35
|
+
end
|
36
|
+
|
37
|
+
# Check exitstatus
|
38
|
+
if allowed_exitstatus.include? status.exitstatus
|
39
|
+
return stdout
|
40
|
+
elsif status.exitstatus == 5
|
41
|
+
raise "Permission denied"
|
42
|
+
elsif [36,103].include? status.exitstatus
|
43
|
+
raise "Service #{@name} not found"
|
44
|
+
else
|
45
|
+
raise "Unknown return code #{status.exitstatus}: #{stdout}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def start
|
50
|
+
run_cmd('start', true)
|
51
|
+
wait_for_status('RUNNING')
|
52
|
+
end
|
53
|
+
|
54
|
+
def stop
|
55
|
+
run_cmd('stop', true)
|
56
|
+
wait_for_status('STOPPED')
|
57
|
+
end
|
58
|
+
|
59
|
+
def restart
|
60
|
+
stop
|
61
|
+
start
|
62
|
+
end
|
63
|
+
|
64
|
+
def status
|
65
|
+
output = run_cmd('query', false)
|
66
|
+
# Match state
|
67
|
+
status = /STATE[\s:]+\d+\s+([\S]+)/.match(output)
|
68
|
+
if status.nil?
|
69
|
+
return nil
|
70
|
+
else
|
71
|
+
return status[1]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Waits until service has desired state
|
76
|
+
def wait_for_status(state,sleep_duration=0.1, max_tries=20)
|
77
|
+
try = 0
|
78
|
+
while status != state do
|
79
|
+
try += 1
|
80
|
+
sleep(sleep_duration)
|
81
|
+
if try >= max_tries
|
82
|
+
raise "Error waiting for state '#{state}'"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module VagrantAllegroNfs
|
3
|
+
require 'vagrant-allegro-nfs/version'
|
4
|
+
require 'vagrant-allegro-nfs/plugin'
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.get_nfs_dir
|
11
|
+
Pathname.new("C:/AllegroNFS/")
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.get_nfs_path(file)
|
15
|
+
get_nfs_dir.join(file)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
require 'vagrant-allegro-nfs/cap/nfs'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
|
6
|
+
describe VagrantPlugins::VagrantAllegroNfs::Cap::NFS do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@tempfile = Tempfile.new("nfs_config")
|
10
|
+
@NFS = VagrantPlugins::VagrantAllegroNfs::Cap::NFS
|
11
|
+
@NFS.stub(:nfs_config_file_path).and_return(@tempfile.path)
|
12
|
+
|
13
|
+
@host = double()
|
14
|
+
@host.stub(:capability).and_return(true)
|
15
|
+
|
16
|
+
@env = double()
|
17
|
+
@env.stub(:host).and_return(@host)
|
18
|
+
|
19
|
+
@folders = {
|
20
|
+
'test123' =>
|
21
|
+
{
|
22
|
+
:nfs => true,
|
23
|
+
:hostpath => 'C:/localdev/test'
|
24
|
+
},
|
25
|
+
}
|
26
|
+
@id = "208a0b6b-b713-427b-9c7f-2721ec819b80"
|
27
|
+
@ips = ['127.0.0.1','123.45.78.19']
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#nfs_export" do
|
31
|
+
context "not existing config file" do
|
32
|
+
|
33
|
+
it {
|
34
|
+
@NFS.stub(:nfs_config_file_path).and_return(@tempfile.path+"dasda")
|
35
|
+
|
36
|
+
@tempfile.close
|
37
|
+
expect { @NFS.nfs_export(
|
38
|
+
@env,
|
39
|
+
nil,
|
40
|
+
@id,
|
41
|
+
@ips,
|
42
|
+
@folders,
|
43
|
+
) }.not_to raise_error
|
44
|
+
|
45
|
+
content = open(@NFS.nfs_config_file_path).read()
|
46
|
+
content.should match(/C:\\localdev\\test/)
|
47
|
+
|
48
|
+
}
|
49
|
+
end
|
50
|
+
context "already existing config" do
|
51
|
+
before(:each) do
|
52
|
+
@config_old = "C:\\localdev\\test -mapall:1000:1000 127.0.0.1 ##VAGRANT#208a0b6b-b713-427b-9c7f-2721ec819b80#\nC:\\localdev\\test -mapall:1000:1000 123.45.78.19 ##VAGRANT#208a0b6b-b713-427b-9c7f-2721ec819b80#\n"
|
53
|
+
@tempfile.write(@config_old)
|
54
|
+
@tempfile.flush
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "correct config should not change" do
|
58
|
+
it {
|
59
|
+
|
60
|
+
expect { @NFS.nfs_export(
|
61
|
+
@env,
|
62
|
+
nil,
|
63
|
+
@id,
|
64
|
+
@ips,
|
65
|
+
@folders,
|
66
|
+
) }.not_to raise_error
|
67
|
+
|
68
|
+
content = open(@NFS.nfs_config_file_path).read()
|
69
|
+
content.should eq(@config_old)
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "changed ip should change config" do
|
74
|
+
it {
|
75
|
+
|
76
|
+
expect { @NFS.nfs_export(
|
77
|
+
@env,
|
78
|
+
nil,
|
79
|
+
@id,
|
80
|
+
['1.2.3.4'],
|
81
|
+
@folders,
|
82
|
+
) }.not_to raise_error
|
83
|
+
|
84
|
+
content = open(@NFS.nfs_config_file_path).read()
|
85
|
+
content.lines.count.should eq(1)
|
86
|
+
content.should match(/1\.2\.3\.4/)
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
require "vagrant-allegro-nfs/windows_service"
|
3
|
+
|
4
|
+
describe VagrantPlugins::VagrantAllegroNfs::WindowsService do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@name = 'service1'
|
8
|
+
@service = VagrantPlugins::VagrantAllegroNfs::WindowsService.new(@name)
|
9
|
+
@stdout_running = "adfadf\n STATE : 4 RUNNING \n asds"
|
10
|
+
@stdout_stopped = "adfadf\n STATE : 1 STOPPED \n asds"
|
11
|
+
@double_open3 = double('Open3')
|
12
|
+
stub_const("Open3", @double_open3)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "existing service" do
|
16
|
+
context "is running" do
|
17
|
+
describe '#status' do
|
18
|
+
it {
|
19
|
+
@double_open3.should_receive(:capture3)
|
20
|
+
.with("sc query \"#{@name}\"")
|
21
|
+
.and_return([@stdout_running,"",double(:exitstatus => 0)])
|
22
|
+
@service.status.should eq("RUNNING")
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#stop' do
|
27
|
+
it {
|
28
|
+
@double_open3.should_receive(:capture3)
|
29
|
+
.with("sc stop \"#{@name}\"")
|
30
|
+
.and_return(["","",double(:exitstatus => 0)])
|
31
|
+
@double_open3.should_receive(:capture3)
|
32
|
+
.with("sc query \"#{@name}\"")
|
33
|
+
.and_return([@stdout_running,"",double(:exitstatus => 0)])
|
34
|
+
@double_open3.should_receive(:capture3)
|
35
|
+
.with("sc query \"#{@name}\"")
|
36
|
+
.and_return([@stdout_stopped,"",double(:exitstatus => 0)])
|
37
|
+
@service.stop
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#start' do
|
42
|
+
it {
|
43
|
+
@double_open3.should_receive(:capture3)
|
44
|
+
.with("sc start \"#{@name}\"")
|
45
|
+
.and_return(["Already running","",double(:exitstatus => 32)])
|
46
|
+
@double_open3.should_receive(:capture3)
|
47
|
+
.with("sc query \"#{@name}\"")
|
48
|
+
.and_return([@stdout_running,"",double(:exitstatus => 0)])
|
49
|
+
@service.start
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "is not running" do
|
55
|
+
describe '#status' do
|
56
|
+
it {
|
57
|
+
@double_open3.should_receive(:capture3)
|
58
|
+
.with("sc query \"#{@name}\"")
|
59
|
+
.and_return([@stdout_stopped,"",double(:exitstatus => 0)])
|
60
|
+
@service.status.should eq("STOPPED")
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#stop' do
|
65
|
+
it {
|
66
|
+
@double_open3.should_receive(:capture3)
|
67
|
+
.with("sc stop \"#{@name}\"")
|
68
|
+
.and_return(["","",double(:exitstatus => 38)])
|
69
|
+
@double_open3.should_receive(:capture3)
|
70
|
+
.with("sc query \"#{@name}\"")
|
71
|
+
.and_return([@stdout_stopped,"",double(:exitstatus => 0)])
|
72
|
+
@service.stop
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#start' do
|
77
|
+
it {
|
78
|
+
@double_open3.should_receive(:capture3)
|
79
|
+
.with("sc start \"#{@name}\"")
|
80
|
+
.and_return(["Already running","",double(:exitstatus => 0)])
|
81
|
+
@double_open3.should_receive(:capture3)
|
82
|
+
.with("sc query \"#{@name}\"")
|
83
|
+
.and_return(["UNPARSABLE","",double(:exitstatus => 0)])
|
84
|
+
@double_open3.should_receive(:capture3)
|
85
|
+
.with("sc query \"#{@name}\"")
|
86
|
+
.and_return([@stdout_running,"",double(:exitstatus => 0)])
|
87
|
+
@service.start
|
88
|
+
}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "not existing service" do
|
94
|
+
before(:each) do
|
95
|
+
@name = 'service_not1'
|
96
|
+
@service = VagrantPlugins::VagrantAllegroNfs::WindowsService.new(@name)
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#status' do
|
100
|
+
it {
|
101
|
+
@double_open3.should_receive(:capture3)
|
102
|
+
.with("sc query \"#{@name}\"")
|
103
|
+
.and_return([@stdout_stopped,"",double(:exitstatus => 103)])
|
104
|
+
expect { @service.status }.to raise_error(/not found/)
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#stop' do
|
109
|
+
it {
|
110
|
+
@double_open3.should_receive(:capture3)
|
111
|
+
.with("sc stop \"#{@name}\"")
|
112
|
+
.and_return([@stdout_stopped,"",double(:exitstatus => 36)])
|
113
|
+
expect { @service.stop }.to raise_error(/not found/)
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#start' do
|
118
|
+
it {
|
119
|
+
@double_open3.should_receive(:capture3)
|
120
|
+
.with("sc start \"#{@name}\"")
|
121
|
+
.and_return([@stdout_stopped,"",double(:exitstatus => 36)])
|
122
|
+
expect { @service.start }.to raise_error(/not found/)
|
123
|
+
}
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
require "vagrant-allegro-nfs/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'vagrant-allegro-nfs'
|
6
|
+
gem.version = VagrantPlugins::VagrantAllegroNfs::VERSION
|
7
|
+
|
8
|
+
gem.summary = 'Adds NFS support for Windows with Allegro NFS'
|
9
|
+
gem.description = <<-EOD
|
10
|
+
Manage and adds support for NFS on windows.
|
11
|
+
EOD
|
12
|
+
|
13
|
+
gem.authors = 'Christian Simon'
|
14
|
+
gem.email = 'simon@swine.de'
|
15
|
+
gem.homepage = 'https://github.com/simonswine/vagrant-allegro-nfs'
|
16
|
+
|
17
|
+
gem.has_rdoc = true
|
18
|
+
gem.license = 'Apache 2.0'
|
19
|
+
|
20
|
+
gem.files = `git ls-files -z`.split("\x0")
|
21
|
+
gem.require_path = 'lib'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-allegro-nfs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Simon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |2
|
14
|
+
Manage and adds support for NFS on windows.
|
15
|
+
email: simon@swine.de
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- CHANGELOG
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- Vagrantfile.dist
|
27
|
+
- elevated-script.bat
|
28
|
+
- lib/vagrant-allegro-nfs.rb
|
29
|
+
- lib/vagrant-allegro-nfs/cap/nfs.rb
|
30
|
+
- lib/vagrant-allegro-nfs/config.rb
|
31
|
+
- lib/vagrant-allegro-nfs/host.rb
|
32
|
+
- lib/vagrant-allegro-nfs/plugin.rb
|
33
|
+
- lib/vagrant-allegro-nfs/synced_folder.rb
|
34
|
+
- lib/vagrant-allegro-nfs/version.rb
|
35
|
+
- lib/vagrant-allegro-nfs/windows_service.rb
|
36
|
+
- locales/en.yml
|
37
|
+
- spec/classes/cap_nfs_spec.rb
|
38
|
+
- spec/classes/windows_service_spec.rb
|
39
|
+
- spec/spec_helper.rb
|
40
|
+
- vagrant-allegro-nfs.gemspec
|
41
|
+
homepage: https://github.com/simonswine/vagrant-allegro-nfs
|
42
|
+
licenses:
|
43
|
+
- Apache 2.0
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.4.5.1
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Adds NFS support for Windows with Allegro NFS
|
65
|
+
test_files: []
|