Solaris capabilities

This commit is contained in:
Mitchell Hashimoto 2013-04-04 12:25:10 -07:00
parent 5e09577a76
commit 439499fc11
10 changed files with 151 additions and 86 deletions

View File

@ -0,0 +1,17 @@
module VagrantPlugins
module GuestSolaris
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
su_cmd = machine.config.solaris.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} uname -S #{name}")
end
end
end
end
end
end

View File

@ -0,0 +1,25 @@
module VagrantPlugins
module GuestSolaris
module Cap
class ConfigureNetworks
def self.configure_networks(machine, networks)
networks.each do |network|
device = "#{machine.config.solaris.device}#{network[:interface]}"
su_cmd = machine.config.solaris.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

View File

@ -0,0 +1,21 @@
module VagrantPlugins
module GuestSolaris
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.solaris.suexec_cmd} /usr/sbin/poweroff")
rescue IOError
# Ignore, this probably means connection closed because it
# shut down.
end
end
end
end
end
end

View File

@ -0,0 +1,28 @@
module VagrantPlugins
module GuestSolaris
module Cap
class MountVirtualBoxSharedFolder
def self.mount_virtualbox_shared_folder(machine, name, guestpath, options)
# These are just far easier to use than the full options syntax
owner = options[:owner]
group = options[:group]
# Create the shared folder
machine.communicate.execute("#{machine.config.solaris.suexec_cmd} mkdir -p #{guestpath}")
# We have to use this `id` command instead of `/usr/bin/id` since this
# one accepts the "-u" and "-g" flags.
id_cmd = "/usr/xpg4/bin/id"
# Mount the folder with the proper owner/group
mount_options = "-o uid=`#{id_cmd} -u #{owner}`,gid=`#{id_cmd} -g #{group}`"
mount_options += ",#{options[:extra]}" if options[:extra]
machine.communicate.execute("#{machine.config.solaris.suexec_cmd} /sbin/mount -F vboxfs #{mount_options} #{name} #{guestpath}")
# chown the folder to the proper owner/group
machine.communicate.execute("#{machine.config.solaris.suexec_cmd} chown `#{id_cmd} -u #{owner}`:`#{id_cmd} -g #{group}` #{guestpath}")
end
end
end
end
end

View File

@ -6,77 +6,9 @@ module VagrantPlugins
#
# Contributed by Blake Irvin <b.irvin@modcloth.com>
class Guest < Vagrant.plugin("2", :guest)
# Here for whenever it may be used.
class SolarisError < Vagrant::Errors::VagrantError
error_namespace("vagrant.guest.solaris")
end
def detect?(machine)
machine.communicate.test("grep 'Solaris' /etc/release")
end
def configure_networks(networks)
networks.each do |network|
device = "#{vm.config.solaris.device}#{network[:interface]}"
su_cmd = vm.config.solaris.suexec_cmd
ifconfig_cmd = "#{su_cmd} /sbin/ifconfig #{device}"
vm.communicate.execute("#{ifconfig_cmd} plumb")
if network[:type].to_sym == :static
vm.communicate.execute("#{ifconfig_cmd} inet #{network[:ip]} netmask #{network[:netmask]}")
vm.communicate.execute("#{ifconfig_cmd} up")
vm.communicate.execute("#{su_cmd} sh -c \"echo '#{network[:ip]}' > /etc/hostname.#{device}\"")
elsif network[:type].to_sym == :dhcp
vm.communicate.execute("#{ifconfig_cmd} dhcp start")
end
end
end
def change_host_name(name)
su_cmd = vm.config.solaris.suexec_cmd
# Only do this if the hostname is not already set
if !vm.communicate.test("#{su_cmd} hostname | grep '#{name}'")
vm.communicate.execute("#{su_cmd} sh -c \"echo '#{name}' > /etc/nodename\"")
vm.communicate.execute("#{su_cmd} uname -S #{name}")
end
end
# There should be an exception raised if the line
#
# vagrant::::profiles=Primary Administrator
#
# does not exist in /etc/user_attr. TODO
def halt
begin
vm.communicate.execute("#{vm.config.solaris.suexec_cmd} /usr/sbin/poweroff")
rescue IOError
# Ignore, this probably means connection closed because it
# shut down.
end
end
def mount_shared_folder(name, guestpath, options)
# These are just far easier to use than the full options syntax
owner = options[:owner]
group = options[:group]
# Create the shared folder
vm.communicate.execute("#{vm.config.solaris.suexec_cmd} mkdir -p #{guestpath}")
# We have to use this `id` command instead of `/usr/bin/id` since this
# one accepts the "-u" and "-g" flags.
id_cmd = "/usr/xpg4/bin/id"
# Mount the folder with the proper owner/group
mount_options = "-o uid=`#{id_cmd} -u #{owner}`,gid=`#{id_cmd} -g #{group}`"
mount_options += ",#{options[:extra]}" if options[:extra]
vm.communicate.execute("#{vm.config.solaris.suexec_cmd} /sbin/mount -F vboxfs #{mount_options} #{name} #{guestpath}")
# chown the folder to the proper owner/group
vm.communicate.execute("#{vm.config.solaris.suexec_cmd} chown `#{id_cmd} -u #{owner}`:`#{id_cmd} -g #{group}` #{guestpath}")
end
end
end
end

View File

@ -15,6 +15,26 @@ module VagrantPlugins
require File.expand_path("../guest", __FILE__)
Guest
end
guest_capability("solaris", "change_host_name") do
require_relative "cap/change_host_name"
Cap::ChangeHostName
end
guest_capability("solaris", "configure_networks") do
require_relative "cap/configure_networks"
Cap::ConfigureNetworks
end
guest_capability("solaris", "halt") do
require_relative "cap/halt"
Cap::Halt
end
guest_capability("solaris", "mount_virtualbox_shared_folder") do
require_relative "cap/mount_virtualbox_shared_folder"
Cap::MountVirtualBoxSharedFolder
end
end
end
end

View File

@ -0,0 +1,18 @@
module VagrantPlugins
module GuestSuse
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
machine.communicate.tap do |comm|
# Only do this if the hostname is not already set
if !comm.test("sudo hostname | grep '#{name}'")
comm.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network")
comm.sudo("hostname #{name}")
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
end
end
end
end
end
end
end

View File

@ -0,0 +1,11 @@
module VagrantPlugins
module GuestSuse
module Cap
class NetworkScriptsDir
def self.network_scripts_dir(machine)
"/etc/sysconfig/network/"
end
end
end
end
end

View File

@ -1,28 +1,11 @@
require "vagrant"
require Vagrant.source_root.join("plugins/guests/redhat/guest")
module VagrantPlugins
module GuestSuse
class Guest < VagrantPlugins::GuestRedHat::Guest
class Guest < Vagrant.plugin("2", :guest)
def detect?(machine)
machine.communicate.test("cat /etc/SuSE-release")
end
def network_scripts_dir
'/etc/sysconfig/network/'
end
def change_host_name(name)
vm.communicate.tap do |comm|
# Only do this if the hostname is not already set
if !comm.test("sudo hostname | grep '#{name}'")
comm.sudo("echo '#{name}' > /etc/HOSTNAME")
comm.sudo("hostname #{name}")
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
end
end
end
end
end
end

View File

@ -10,6 +10,16 @@ module VagrantPlugins
require File.expand_path("../guest", __FILE__)
Guest
end
guest_capability("suse", "change_host_name") do
require_relative "cap/change_host_name"
Cap::ChangeHostName
end
guest_capability("suse", "network_scripts_dir") do
require_relative "cap/network_scripts_dir"
Cap::NetworkScriptsDir
end
end
end
end