Skip to content

Commit

Permalink
First commit of the project files
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Schneider committed Dec 12, 2013
1 parent d125289 commit 51c071b
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# RubyMine
.idea

# Bundler/Rubygems
*.gem
.bundle
pkg/*
tags
Gemfile.lock

# Vagrant
.vagrant
Vagrantfile

# Other
nfspaths
11 changes: 11 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CHANGELOG
=========

1.0.0
-----

2013-12-12

First release


11 changes: 11 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source "https://rubygems.org"

gemspec

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 => "git://github.com/mitchellh/vagrant.git", :branch => "master"
gem "rspec"
end
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2013 Alexander Schneider - Jankowfsky AG

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
1 change: 0 additions & 1 deletion README

This file was deleted.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Vagrant WinNFSd

Manage and adds support for NFS on windows.

## Supported Platforms

As of version 1.0.0 or later Vagrant 1.4 is required.

Supported guests:

* Linux

## Installation

```
$ vagrant plugin install vagrant-winnfsd
```
21 changes: 21 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'rubygems'
require 'bundler/setup'
#require 'rspec/core/rake_task'

# Immediately sync all stdout so that tools like buildbot can
# immediately load in the output.
$stdout.sync = true
$stderr.sync = true

# Change to the directory of this file.
Dir.chdir(File.expand_path("../", __FILE__))

# This installs the tasks that help with gem creation and
# publishing.
Bundler::GemHelper.install_tasks

# Install the `spec` task so that we can run tests.
#RSpec::Core::RakeTask.new

# Default task is to run the unit tests
#task :default => "spec"
41 changes: 41 additions & 0 deletions bin/nfsservice.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@echo off
tasklist /nh /fi "imagename eq winnfsd.exe" 2>nul | grep -i -c "winnfsd.exe" >nfsservicetmp
set /p RUNNINGTASKS=<nfsservicetmp
del nfsservicetmp

if %1==status (
:: printf "[NFS] Status: "
if %RUNNINGTASKS% == 0 (
:: printf "halted\n"
exit 1
) else (
:: printf "running\n"
exit 0
)
)

if %1==start (
printf "[NFS] Start: "
if %RUNNINGTASKS% == 0 (
start "%~dp0winnfsd" -log off -pathFile %2
printf "started\n"
) else (
printf "already running\n"
)

exit 0
)

if %1==halt (
printf "[NFS] Halt: "
if %RUNNINGTASKS% == 0 (
printf "not running\n"
) else (
taskkill /f /im "winnfsd.exe" >nul
printf "halt\n"
)

exit 0
)

exit 1
Binary file added bin/winnfsd.exe
Binary file not shown.
18 changes: 18 additions & 0 deletions lib/vagrant-winnfsd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module VagrantPlugins
module VagrantWinNFSd
require 'vagrant-winnfsd/version'
require 'vagrant-winnfsd/plugin'

def self.source_root
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
end

def self.get_binary_path
source_root.join("bin")
end

def self.get_path_for_file(file)
get_binary_path.join(file).to_s.gsub('/', '\\')
end
end
end
26 changes: 26 additions & 0 deletions lib/vagrant-winnfsd/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'vagrant'
require Vagrant.source_root.join("plugins/kernel_v2/config/vm")

module VagrantPlugins
module VagrantWinNFSd
class Config < VagrantPlugins::Kernel_V2::VMConfig
def finalize!
switch_back = {}

@__synced_folders.each do |id, options|
if (options[:nfs] || options[:type] == :nfs) && Vagrant::Util::Platform.windows?
switch_back[id] = true
end
end

super

@__synced_folders.each do |id, options|
if options[:type] != :nfs && !switch_back[id].nil?
options[:type] = :nfs
end
end
end
end
end
end
65 changes: 65 additions & 0 deletions lib/vagrant-winnfsd/host.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require Vagrant.source_root.join("plugins/hosts/windows/host")

module VagrantPlugins
module VagrantWinNFSd
class Host < Vagrant.plugin("2", :host)
def self.match?
Vagrant::Util::Platform.windows?
end

def initialize(*args)
super

@logger = Log4r::Logger.new("vagrant::hosts::windows")

executable = VagrantWinNFSd.get_path_for_file("nfsservice.bat")
@nfs_check_command = "\"#{executable}\" status"
@nfs_start_command = "\"#{executable}\" start"
@nfs_stop_command = "\"#{executable}\" halt"
@nfs_path_file = "nfspaths"
end

# Windows does not support NFS
def nfs?
true
end

def nfs_export(id, ips, folders)
@ui.info I18n.t("vagrant_winnfsd.hosts.windows.nfs_export")
sleep 0.5

folders.each do |k, opts|
hostpath = opts[:hostpath].dup
hostpath.gsub!("'", "'\\\\''")
hostpath.gsub('/', '\\')
system("echo #{hostpath} >>#@nfs_path_file")
end

system("#@nfs_start_command .\\#@nfs_path_file")
sleep 2
end

def nfs_prune(valid_ids)
@ui.info I18n.t("vagrant_winnfsd.hosts.windows.nfs_prune")
@logger.info("Pruning invalid NFS entries...")
nfs_cleanup()
end

protected

def nfs_running?
system("#@nfs_check_command")
end

def nfs_cleanup()
if nfs_running?
system("#@nfs_stop_command")
end

if !nfs_running? && File.exist?(@nfs_path_file)
File.delete(@nfs_path_file)
end
end
end
end
end
59 changes: 59 additions & 0 deletions lib/vagrant-winnfsd/plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
begin
require 'vagrant'
rescue LoadError
raise "The Vagrant WinNFSd plugin must be run within Vagrant."
end

if Vagrant::VERSION < "1.4.0"
raise "The Vagrant AWS plugin is only compatible with Vagrant 1.4.0+"
end

module VagrantPlugins
module VagrantWinNFSd
class Plugin < Vagrant.plugin(2)
name 'WinNFSd'

description <<-DESC
This plugin adds NFS support on Windows for Vagrant.
DESC

action_hook(:init_i18n, :environment_load) { init_plugin }

config("vm") do |env|
require_relative "config"
Config
end

synced_folder("nfs") do
require_relative "synced_folder"
SyncedFolder
end

host("windows") do
require_relative "host"
Host
end

def self.init_plugin
I18n.load_path << File.expand_path('locales/en.yml', VagrantWinNFSd.source_root)
I18n.reload!

rule_name = "VagrantWinNFSd"
program = VagrantWinNFSd.get_path_for_file("winnfsd.exe")
rule_exist = "netsh advfirewall firewall show rule name=\"%s\">nul"

unless system(sprintf(rule_exist, rule_name))
rule = "netsh advfirewall firewall add rule name=\"%s\" dir=\"%s\" action=allow protocol=any program=\"%s\" profile=any>nul"
in_rule = sprintf(rule, rule_name, 'in', program)
out_rule = sprintf(rule, rule_name, 'out', program)

if !system(in_rule) || !system(out_rule)
puts I18n.t("vagrant_winnfsd.firewall.error")
puts "#{in_rule}\n"
puts "#{out_rule}\n"
end
end
end
end
end
end
48 changes: 48 additions & 0 deletions lib/vagrant-winnfsd/synced_folder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'vagrant'
require Vagrant.source_root.join("plugins/synced_folders/nfs/synced_folder")

module VagrantPlugins
module VagrantWinNFSd
class SyncedFolder < VagrantPlugins::SyncedFolderNFS::SyncedFolder
def enable(machine, folders, nfsopts)
raise Vagrant::Errors::NFSNoHostIP if !nfsopts[:nfs_host_ip]
raise Vagrant::Errors::NFSNoGuestIP if !nfsopts[:nfs_machine_ip]

machine_ip = nfsopts[:nfs_machine_ip]
machine_ip = [machine_ip] if !machine_ip.is_a?(Array)

# Prepare the folder, this means setting up various options
# and such on the folder itself.
folders.each { |id, opts| prepare_folder(machine, opts) }

# Export the folders
machine.ui.info I18n.t("vagrant.actions.vm.nfs.exporting")
machine.env.host.nfs_export(machine.id, machine_ip, folders)

# Mount
machine.ui.info I18n.t("vagrant.actions.vm.nfs.mounting")

# Only mount folders that have a guest path specified.
mount_folders = {}
folders.each do |id, opts|
if Vagrant::Util::Platform.windows?
unless opts[:mount_options]
mount_opts = ["vers=#{opts[:nfs_version]}"]
mount_opts << "udp" if opts[:nfs_udp]
mount_opts << "nolock"

opts[:mount_options] = mount_opts
end

opts[:hostpath] = '/' + opts[:hostpath].gsub(':', '').gsub('\\', '/')
end
mount_folders[id] = opts.dup if opts[:guestpath]
end

# Mount them!
machine.guest.capability(
:mount_nfs_folder, nfsopts[:nfs_host_ip], mount_folders)
end
end
end
end
5 changes: 5 additions & 0 deletions lib/vagrant-winnfsd/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module VagrantPlugins
module VagrantWinNFSd
VERSION = '1.0.0'
end
end
13 changes: 13 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
en:
vagrant_winnfsd:
hosts:
windows:
nfs_export: |-
Preparing to edit nfs mounting file.
nfs_prune: |-
Pruning invalid NFS exports.
firewall:
error: |-
It seems that you don't have the prevelegs to change the firewall rules. NFS will not work without that firewall
changes. Run Vagrant as administartor or execute the following comands as administartor:
Loading

0 comments on commit 51c071b

Please sign in to comment.