From 4cec8b48d96173d8299b72daeca216adc57554cf Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 7 Jan 2014 21:01:03 -0800 Subject: [PATCH] hosts/freebsd: convert --- plugins/hosts/freebsd/cap/nfs.rb | 31 ++++++++++++++++++++++++++++ plugins/hosts/freebsd/host.rb | 35 ++------------------------------ plugins/hosts/freebsd/plugin.rb | 20 ++++++++++++++++-- templates/locales/en.yml | 7 +++---- 4 files changed, 54 insertions(+), 39 deletions(-) create mode 100644 plugins/hosts/freebsd/cap/nfs.rb diff --git a/plugins/hosts/freebsd/cap/nfs.rb b/plugins/hosts/freebsd/cap/nfs.rb new file mode 100644 index 000000000..bc61628ea --- /dev/null +++ b/plugins/hosts/freebsd/cap/nfs.rb @@ -0,0 +1,31 @@ +require "vagrant/util" +require "vagrant/util/retryable" + +require Vagrant.source_root.join("plugins", "hosts", "bsd", "cap", "nfs") + +module VagrantPlugins + module HostFreeBSD + module Cap + class NFS + def self.nfs_export(environment, ui, id, ips, folders) + folders.each do |folder_name, folder_values| + if folder_values[:hostpath] =~ /\s+/ + raise Vagrant::Errors::VagrantError, + _key: :freebsd_nfs_whitespace + end + end + + HostBSD::Cap::NFS.nfs_export(environment, ui, id, ips, folders) + end + + def self.nfs_exports_template(environment) + "nfs/exports_freebsd" + end + + def self.nfs_restart_command(environment) + "sudo /etc/rc.d/mountd onereload" + end + end + end + end +end diff --git a/plugins/hosts/freebsd/host.rb b/plugins/hosts/freebsd/host.rb index d10d84d47..7cb0502ec 100644 --- a/plugins/hosts/freebsd/host.rb +++ b/plugins/hosts/freebsd/host.rb @@ -1,43 +1,12 @@ require "vagrant" require 'vagrant/util/platform' -require Vagrant.source_root.join("plugins/hosts/bsd/host") - module VagrantPlugins module HostFreeBSD - class Host < VagrantPlugins::HostBSD::Host - class FreeBSDHostError < Vagrant::Errors::VagrantError - error_namespace("vagrant.hosts.freebsd") - end - - include Vagrant::Util - include Vagrant::Util::Retryable - - def self.match? + class Host < Vagrant.plugin("2", :host) + def self.detect?(env) Vagrant::Util::Platform.freebsd? end - - # Normal, mid-range precedence. - def self.precedence - 5 - end - - def nfs_export(id, ip, folders) - folders.each do |folder_name, folder_values| - if folder_values[:hostpath] =~ /\s+/ - raise FreeBSDHostError, :_key => :nfs_whitespace - end - end - - super - end - - def initialize(*args) - super - - @nfs_restart_command = "sudo /etc/rc.d/mountd onereload" - @nfs_exports_template = "nfs/exports_freebsd" - end end end end diff --git a/plugins/hosts/freebsd/plugin.rb b/plugins/hosts/freebsd/plugin.rb index c58cd5f90..4e966837b 100644 --- a/plugins/hosts/freebsd/plugin.rb +++ b/plugins/hosts/freebsd/plugin.rb @@ -6,10 +6,26 @@ module VagrantPlugins name "FreeBSD host" description "FreeBSD host support." - host("freebsd") do - require File.expand_path("../host", __FILE__) + host("freebsd", "bsd") do + require_relative "host" Host end + + host_capability("freebsd", "nfs_export") do + require_relative "cap/nfs" + Cap::NFS + end + + # BSD-specific helpers + host_capability("freebsd", "nfs_exports_template") do + require_relative "cap/nfs" + Cap::NFS + end + + host_capability("freebsd", "nfs_restart_command") do + require_relative "cap/nfs" + Cap::NFS + end end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 52579da36..eb4c6a7ed 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -379,6 +379,9 @@ en: Host port: %{host} Guest port: %{guest} Adapter: %{adapter} + freebsd_nfs_whitespace: |- + FreeBSD hosts do not support sharing directories with whitespace in + their path. Please adjust your path accordingly. gem_command_in_bundler: |- You cannot run the `vagrant plugin` command while in a bundler environment. This should generally never happen unless Vagrant is installed outside @@ -1345,10 +1348,6 @@ en: arch: nfs_export: prepare: "Preparing to edit /etc/exports. Administrator privileges will be required..." - freebsd: - nfs_whitespace: |- - FreeBSD hosts do not support sharing directories with whitespace in - their path. Please adjust your path accordingly. provisioners: chef: