From 4d47dae5b96cc9d1590f3c6ca3f2c6af4e5af076 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 7 Jan 2014 21:11:59 -0800 Subject: [PATCH] many more hosts converted --- plugins/hosts/arch/plugin.rb | 5 ---- plugins/hosts/gentoo/cap/nfs.rb | 34 +++++++++++++++++++++ plugins/hosts/gentoo/host.rb | 35 ++-------------------- plugins/hosts/gentoo/plugin.rb | 17 +++++++++-- plugins/hosts/opensuse/cap/nfs.rb | 15 ++++++++++ plugins/hosts/opensuse/host.rb | 19 ++---------- plugins/hosts/opensuse/plugin.rb | 16 ++++++++-- plugins/hosts/redhat/cap/nfs.rb | 45 ++++++++++++++++++++++++++++ plugins/hosts/redhat/host.rb | 48 +++++------------------------- plugins/hosts/redhat/plugin.rb | 14 ++++++++- plugins/hosts/slackware/cap/nfs.rb | 15 ++++++++++ plugins/hosts/slackware/host.rb | 22 +++----------- plugins/hosts/slackware/plugin.rb | 14 ++++++++- 13 files changed, 181 insertions(+), 118 deletions(-) create mode 100644 plugins/hosts/gentoo/cap/nfs.rb create mode 100644 plugins/hosts/opensuse/cap/nfs.rb create mode 100644 plugins/hosts/redhat/cap/nfs.rb create mode 100644 plugins/hosts/slackware/cap/nfs.rb diff --git a/plugins/hosts/arch/plugin.rb b/plugins/hosts/arch/plugin.rb index 7485ec3be..8c71fa17f 100644 --- a/plugins/hosts/arch/plugin.rb +++ b/plugins/hosts/arch/plugin.rb @@ -18,11 +18,6 @@ module VagrantPlugins # Linux-specific helpers we need to determine paths that can # be overriden. - host_capability("arch", "nfs_apply_command") do - require_relative "cap/nfs" - Cap::NFS - end - host_capability("arch", "nfs_check_command") do require_relative "cap/nfs" Cap::NFS diff --git a/plugins/hosts/gentoo/cap/nfs.rb b/plugins/hosts/gentoo/cap/nfs.rb new file mode 100644 index 000000000..8f855ed98 --- /dev/null +++ b/plugins/hosts/gentoo/cap/nfs.rb @@ -0,0 +1,34 @@ +require "vagrant/util/subprocess" + +module VagrantPlugins + module HostGentoo + module Cap + class NFS + def self.nfs_check_command(env) + if systemd? + return "/usr/sbin/systemctl status nfsd" + else + return "/etc/init.d/nfs status" + end + end + + def self.nfs_start_command(env) + if systemd? + return "/usr/sbin/systemctl start nfsd rpc-mountd rpcbind" + else + return "/etc/init.d/nfs restart" + end + end + + protected + + # This tests to see if systemd is used on the system. This is used + # in newer versions of Arch, and requires a change in behavior. + def self.systemd? + result = Vagrant::Util::Subprocess.execute("ps", "-o", "comm=", "1") + return result.stdout.chomp == "systemd" + end + end + end + end +end diff --git a/plugins/hosts/gentoo/host.rb b/plugins/hosts/gentoo/host.rb index 7d9b73de2..eaac10d77 100644 --- a/plugins/hosts/gentoo/host.rb +++ b/plugins/hosts/gentoo/host.rb @@ -1,39 +1,10 @@ require "vagrant" -require "vagrant/util/subprocess" - -require Vagrant.source_root.join("plugins/hosts/linux/host") module VagrantPlugins module HostGentoo - class Host < VagrantPlugins::HostLinux::Host - def self.match? - return File.exists?("/etc/gentoo-release") - end - - # Normal, mid-range precedence. - def self.precedence - 5 - end - - def initialize(*args) - super - - @nfs_apply_command = "/usr/sbin/exportfs -r" - if systemd? - @nfs_check_command = "/usr/bin/systemctl status nfsd" - @nfs_start_command = "/usr/bin/systemctl start nfsd rpc-mountd rpcbind" - else - @nfs_check_command = "/etc/init.d/nfs status" - @nfs_start_command = "/etc/init.d/nfs restart" - end - end - - protected - - # Check for systemd presence from current processes. - def systemd? - result = Vagrant::Util::Subprocess.execute("ps", "-o", "comm=", "1") - return result.stdout.chomp == "systemd" + class Host < Vagrant.plugin("2", :host) + def self.detect?(env) + File.exists?("/etc/gentoo-release") end end end diff --git a/plugins/hosts/gentoo/plugin.rb b/plugins/hosts/gentoo/plugin.rb index c976081c5..966197080 100644 --- a/plugins/hosts/gentoo/plugin.rb +++ b/plugins/hosts/gentoo/plugin.rb @@ -6,10 +6,23 @@ module VagrantPlugins name "Gentoo host" description "Gentoo host support." - host("gentoo") do - require File.expand_path("../host", __FILE__) + host("gentoo", "linux") do + require_relative "host" Host end + + # Linux-specific helpers we need to determine paths that can + # be overriden. + host_capability("gentoo", "nfs_check_command") do + require_relative "cap/nfs" + Cap::NFS + end + + host_capability("gentoo", "nfs_start_command") do + require_relative "cap/nfs" + Cap::NFS + end + end end end diff --git a/plugins/hosts/opensuse/cap/nfs.rb b/plugins/hosts/opensuse/cap/nfs.rb new file mode 100644 index 000000000..829b47a84 --- /dev/null +++ b/plugins/hosts/opensuse/cap/nfs.rb @@ -0,0 +1,15 @@ +module VagrantPlugins + module HostOpenSUSE + module Cap + class NFS + def self.nfs_check_command(env) + "service nfsserver status" + end + + def self.nfs_start_command(env) + "service nfsserver start" + end + end + end + end +end diff --git a/plugins/hosts/opensuse/host.rb b/plugins/hosts/opensuse/host.rb index 4c564bb45..6333d75cc 100644 --- a/plugins/hosts/opensuse/host.rb +++ b/plugins/hosts/opensuse/host.rb @@ -2,12 +2,10 @@ require "pathname" require "vagrant" -require Vagrant.source_root.join("plugins/hosts/linux/host") - module VagrantPlugins module HostOpenSUSE - class Host < VagrantPlugins::HostLinux::Host - def self.match? + class Host < Vagrant.plugin("2", :host) + def self.detect?(env) release_file = Pathname.new("/etc/SuSE-release") if release_file.exist? @@ -18,19 +16,6 @@ module VagrantPlugins false end - - # Normal, mid-range precedence. - def self.precedence - 5 - end - - def initialize(*args) - super - - @nfs_apply_command = "/usr/sbin/exportfs -r" - @nfs_check_command = "service nfsserver status" - @nfs_start_command = "service nfsserver start" - end end end end diff --git a/plugins/hosts/opensuse/plugin.rb b/plugins/hosts/opensuse/plugin.rb index 4b0204ced..6ed81f8da 100644 --- a/plugins/hosts/opensuse/plugin.rb +++ b/plugins/hosts/opensuse/plugin.rb @@ -6,10 +6,22 @@ module VagrantPlugins name "OpenSUSE host" description "OpenSUSE host support." - host("opensuse") do - require File.expand_path("../host", __FILE__) + host("opensuse", "linux") do + require_relative "host" Host end + + # Linux-specific helpers we need to determine paths that can + # be overriden. + host_capability("opensuse", "nfs_check_command") do + require_relative "cap/nfs" + Cap::NFS + end + + host_capability("opensuse", "nfs_start_command") do + require_relative "cap/nfs" + Cap::NFS + end end end end diff --git a/plugins/hosts/redhat/cap/nfs.rb b/plugins/hosts/redhat/cap/nfs.rb new file mode 100644 index 000000000..4c11e2d07 --- /dev/null +++ b/plugins/hosts/redhat/cap/nfs.rb @@ -0,0 +1,45 @@ +require "pathname" + +module VagrantPlugins + module HostRedHat + module Cap + class NFS + def self.nfs_check_command(env) + "#{nfs_server_binary} status" + end + + def self.nfs_start_command(env) + "#{nfs_server_binary} start" + end + + protected + + def self.nfs_server_binary + nfs_server_binary = "/etc/init.d/nfs" + + # On Fedora 16+, systemd replaced init.d, so we have to use the + # proper NFS binary. This checks to see if we need to do that. + release_file = Pathname.new("/etc/redhat-release") + begin + release_file.open("r:ISO-8859-1:UTF-8") do |f| + fedora_match = /Fedora.* release ([0-9]+)/.match(f.gets) + if fedora_match + version_number = fedora_match[1].to_i + if version_number >= 16 + # "service nfs-server" will redirect properly to systemctl + # when "service nfs-server restart" is called. + nfs_server_binary = "/usr/sbin/service nfs-server" + end + end + end + rescue Errno::ENOENT + # File doesn't exist, not a big deal, assume we're on a + # lower version. + end + + nfs_server_binary + end + end + end + end +end diff --git a/plugins/hosts/redhat/host.rb b/plugins/hosts/redhat/host.rb index f6a92401a..70d21dc4d 100644 --- a/plugins/hosts/redhat/host.rb +++ b/plugins/hosts/redhat/host.rb @@ -2,12 +2,10 @@ require "pathname" require "vagrant" -require Vagrant.source_root.join("plugins/hosts/linux/host") - module VagrantPlugins module HostRedHat - class Host < VagrantPlugins::HostLinux::Host - def self.match? + class Host < Vagrant.plugin("2", :host) + def self.detect?(env) release_file = Pathname.new("/etc/redhat-release") if release_file.exist? @@ -15,47 +13,17 @@ module VagrantPlugins contents = f.gets return true if contents =~ /^Fedora/ # Fedora return true if contents =~ /^CentOS/ # CentOS - return true if contents =~ /^Enterprise Linux Enterprise Linux/ # Oracle Linux < 5.3 - return true if contents =~ /^Red Hat Enterprise Linux/ # Red Hat Enterprise Linux and Oracle Linux >= 5.3 + + # Oracle Linux < 5.3 + return true if contents =~ /^Enterprise Linux Enterprise Linux/ + + # Red Hat Enterprise Linux and Oracle Linux >= 5.3 + return true if contents =~ /^Red Hat Enterprise Linux/ end end false end - - # Normal, mid-range precedence. - def self.precedence - 5 - end - - def initialize(*args) - super - - nfs_server_binary = "/etc/init.d/nfs" - - # On Fedora 16+, systemd replaced init.d, so we have to use the - # proper NFS binary. This checks to see if we need to do that. - release_file = Pathname.new("/etc/redhat-release") - begin - release_file.open("r:ISO-8859-1:UTF-8") do |f| - fedora_match = /Fedora.* release ([0-9]+)/.match(f.gets) - if fedora_match - version_number = fedora_match[1].to_i - if version_number >= 16 - # "service nfs-server" will redirect properly to systemctl - # when "service nfs-server restart" is called. - nfs_server_binary = "/usr/sbin/service nfs-server" - end - end - end - rescue Errno::ENOENT - # File doesn't exist, not a big deal, assume we're on a - # lower version. - end - @nfs_apply_command = "/usr/sbin/exportfs -r" - @nfs_check_command = "#{nfs_server_binary} status" - @nfs_start_command = "#{nfs_server_binary} start" - end end end end diff --git a/plugins/hosts/redhat/plugin.rb b/plugins/hosts/redhat/plugin.rb index f35a2a7c8..8dae68705 100644 --- a/plugins/hosts/redhat/plugin.rb +++ b/plugins/hosts/redhat/plugin.rb @@ -6,10 +6,22 @@ module VagrantPlugins name "Red Hat host" description "Red Hat host support." - host("redhat") do + host("redhat", "linux") do require File.expand_path("../host", __FILE__) Host end + + # Linux-specific helpers we need to determine paths that can + # be overriden. + host_capability("redhat", "nfs_check_command") do + require_relative "cap/nfs" + Cap::NFS + end + + host_capability("redhat", "nfs_start_command") do + require_relative "cap/nfs" + Cap::NFS + end end end end diff --git a/plugins/hosts/slackware/cap/nfs.rb b/plugins/hosts/slackware/cap/nfs.rb new file mode 100644 index 000000000..e7f21a094 --- /dev/null +++ b/plugins/hosts/slackware/cap/nfs.rb @@ -0,0 +1,15 @@ +module VagrantPlugins + module HostSlackware + module Cap + class NFS + def self.nfs_check_command(env) + "pidof nfsd >/dev/null" + end + + def self.nfs_start_command(env) + "/etc/rc.d/rc.nfsd start" + end + end + end + end +end diff --git a/plugins/hosts/slackware/host.rb b/plugins/hosts/slackware/host.rb index 65345280b..a5d430eb8 100644 --- a/plugins/hosts/slackware/host.rb +++ b/plugins/hosts/slackware/host.rb @@ -1,25 +1,11 @@ require "vagrant" -require Vagrant.source_root.join("plugins/hosts/linux/host") - module VagrantPlugins module HostSlackware - class Host < VagrantPlugins::HostLinux::Host - def self.match? - return File.exists?("/etc/slackware-release") || Dir.glob("/usr/lib/setup/Plamo-*").length > 0 - end - - # Normal, mid-range precedence. - def self.precedence - 5 - end - - def initialize(*args) - super - - @nfs_apply_command = "/usr/sbin/exportfs -r" - @nfs_check_command = "pidof nfsd > /dev/null" - @nfs_start_command = "/etc/rc.d/rc.nfsd start" + class Host < Vagrant.plugin("2", :host) + def self.detect?(env) + return File.exists?("/etc/slackware-release") || + !Dir.glob("/usr/lib/setup/Plamo-*").empty? end end end diff --git a/plugins/hosts/slackware/plugin.rb b/plugins/hosts/slackware/plugin.rb index 8c5e1595b..1d8dc6248 100644 --- a/plugins/hosts/slackware/plugin.rb +++ b/plugins/hosts/slackware/plugin.rb @@ -6,10 +6,22 @@ module VagrantPlugins name "Slackware host" description "Slackware and derivertives host support." - host("slackware") do + host("slackware", "linux") do require File.expand_path("../host", __FILE__) Host end + + # Linux-specific helpers we need to determine paths that can + # be overriden. + host_capability("slackware", "nfs_check_command") do + require_relative "cap/nfs" + Cap::NFS + end + + host_capability("slackware", "nfs_start_command") do + require_relative "cap/nfs" + Cap::NFS + end end end end