diff --git a/plugins/guests/smartos/cap/change_host_name.rb b/plugins/guests/smartos/cap/change_host_name.rb new file mode 100644 index 000000000..9c5e6977c --- /dev/null +++ b/plugins/guests/smartos/cap/change_host_name.rb @@ -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 diff --git a/plugins/guests/smartos/cap/configure_networks.rb b/plugins/guests/smartos/cap/configure_networks.rb new file mode 100644 index 000000000..2e660c3d9 --- /dev/null +++ b/plugins/guests/smartos/cap/configure_networks.rb @@ -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 + diff --git a/plugins/guests/smartos/cap/halt.rb b/plugins/guests/smartos/cap/halt.rb new file mode 100644 index 000000000..c0178e388 --- /dev/null +++ b/plugins/guests/smartos/cap/halt.rb @@ -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 diff --git a/plugins/guests/smartos/cap/mount_nfs.rb b/plugins/guests/smartos/cap/mount_nfs.rb new file mode 100644 index 000000000..14fa0bdfa --- /dev/null +++ b/plugins/guests/smartos/cap/mount_nfs.rb @@ -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 + diff --git a/plugins/guests/smartos/cap/rsync.rb b/plugins/guests/smartos/cap/rsync.rb new file mode 100644 index 000000000..0217c4dcc --- /dev/null +++ b/plugins/guests/smartos/cap/rsync.rb @@ -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 diff --git a/plugins/guests/smartos/config.rb b/plugins/guests/smartos/config.rb new file mode 100644 index 000000000..65e9f8ea2 --- /dev/null +++ b/plugins/guests/smartos/config.rb @@ -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 diff --git a/plugins/guests/smartos/guest.rb b/plugins/guests/smartos/guest.rb new file mode 100644 index 000000000..1d2a18f02 --- /dev/null +++ b/plugins/guests/smartos/guest.rb @@ -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 diff --git a/plugins/guests/smartos/plugin.rb b/plugins/guests/smartos/plugin.rb new file mode 100644 index 000000000..f99f7e498 --- /dev/null +++ b/plugins/guests/smartos/plugin.rb @@ -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