Add SmartOS detection and mount plugins
This commit is contained in:
parent
df1cd25ba1
commit
a0fee69d04
|
@ -0,0 +1,17 @@
|
|||
module VagrantPlugins
|
||||
module GuestSmartos
|
||||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
su_cmd = machine.config.smartos.suexec_cmd
|
||||
|
||||
# Only do this if the hostname is not already set
|
||||
if !machine.communicate.test("#{su_cmd} hostname | grep '#{name}'")
|
||||
machine.communicate.execute("#{su_cmd} sh -c \"echo '#{name}' > /etc/nodename\"")
|
||||
machine.communicate.execute("#{su_cmd} hostname #{name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
module VagrantPlugins
|
||||
module GuestSmartos
|
||||
module Cap
|
||||
class ConfigureNetworks
|
||||
def self.configure_networks(machine, networks)
|
||||
networks.each do |network|
|
||||
device = "#{machine.config.smartos.device}#{network[:interface]}"
|
||||
su_cmd = machine.config.smartos.suexec_cmd
|
||||
ifconfig_cmd = "#{su_cmd} /sbin/ifconfig #{device}"
|
||||
|
||||
machine.communicate.execute("#{ifconfig_cmd} plumb")
|
||||
|
||||
if network[:type].to_sym == :static
|
||||
machine.communicate.execute("#{ifconfig_cmd} inet #{network[:ip]} netmask #{network[:netmask]}")
|
||||
machine.communicate.execute("#{ifconfig_cmd} up")
|
||||
machine.communicate.execute("#{su_cmd} sh -c \"echo '#{network[:ip]}' > /etc/hostname.#{device}\"")
|
||||
elsif network[:type].to_sym == :dhcp
|
||||
machine.communicate.execute("#{ifconfig_cmd} dhcp start")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
module VagrantPlugins
|
||||
module GuestSmartos
|
||||
module Cap
|
||||
class Halt
|
||||
def self.halt(machine)
|
||||
# There should be an exception raised if the line
|
||||
#
|
||||
# vagrant::::profiles=Primary Administrator
|
||||
#
|
||||
# does not exist in /etc/user_attr. TODO
|
||||
begin
|
||||
machine.communicate.execute(
|
||||
"#{machine.config.smartos.suexec_cmd} /usr/sbin/shutdown -y -i5 -g0")
|
||||
rescue IOError
|
||||
# Ignore, this probably means connection closed because it
|
||||
# shut down.
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
module VagrantPlugins
|
||||
module GuestSmartos
|
||||
module Cap
|
||||
class MountNFS
|
||||
def self.mount_nfs_folder(machine, ip, folders)
|
||||
sudo = machine.config.smartos.suexec_cmd
|
||||
|
||||
folders.each do |name, opts|
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("#{sudo} mkdir -p #{opts[:guestpath]}", {:shell => "sh"})
|
||||
comm.execute("#{sudo} /usr/sbin/mount -F nfs '#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'", {:shell => "sh"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
module VagrantPlugins
|
||||
module GuestSmartos
|
||||
module Cap
|
||||
class RSync
|
||||
def self.rsync_installed(machine)
|
||||
machine.communicate.test("which rsync")
|
||||
end
|
||||
|
||||
def self.rsync_pre(machine, folder_opts)
|
||||
username = machine.ssh_info[:username]
|
||||
sudo = machine.config.smartos.suexec_cmd
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("#{sudo} mkdir -p '#{folder_opts[:guestpath]}'")
|
||||
comm.execute("#{sudo} chown -R #{username} '#{folder_opts[:guestpath]}'")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,18 @@
|
|||
module VagrantPlugins
|
||||
module GuestSmartos
|
||||
class Config < Vagrant.plugin("2", :config)
|
||||
attr_accessor :halt_timeout
|
||||
attr_accessor :halt_check_interval
|
||||
# This sets the command to use to execute items as a superuser. sudo is default
|
||||
attr_accessor :suexec_cmd
|
||||
attr_accessor :device
|
||||
|
||||
def initialize
|
||||
@halt_timeout = 30
|
||||
@halt_check_interval = 1
|
||||
@suexec_cmd = 'pfexec'
|
||||
@device = "e1000g"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestSmartos
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
def detect?(machine)
|
||||
machine.communicate.test("cat /etc/release | grep -i SmartOS")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,50 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestSmartos
|
||||
class Plugin < Vagrant.plugin("2")
|
||||
name "SmartOS guest."
|
||||
description "SmartOS guest support."
|
||||
|
||||
config("smartos") do
|
||||
require File.expand_path("../config", __FILE__)
|
||||
Config
|
||||
end
|
||||
|
||||
guest("smartos") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
Guest
|
||||
end
|
||||
|
||||
guest_capability("smartos", "change_host_name") do
|
||||
require_relative "cap/change_host_name"
|
||||
Cap::ChangeHostName
|
||||
end
|
||||
|
||||
guest_capability("smartos", "configure_networks") do
|
||||
require_relative "cap/configure_networks"
|
||||
Cap::ConfigureNetworks
|
||||
end
|
||||
|
||||
guest_capability("smartos", "halt") do
|
||||
require_relative "cap/halt"
|
||||
Cap::Halt
|
||||
end
|
||||
|
||||
guest_capability("smartos", "mount_nfs_folder") do
|
||||
require_relative "cap/mount_nfs"
|
||||
Cap::MountNFS
|
||||
end
|
||||
|
||||
guest_capability("smartos", "rsync_installed") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("smartos", "rsync_pre") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue