2012-05-23 22:57:43 +00:00
|
|
|
require "vagrant"
|
|
|
|
|
2012-04-19 04:03:03 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestSolaris
|
2010-09-02 22:44:22 +00:00
|
|
|
# A general Vagrant system implementation for "solaris".
|
|
|
|
#
|
|
|
|
# Contributed by Blake Irvin <b.irvin@modcloth.com>
|
2012-04-19 04:03:03 +00:00
|
|
|
class Guest < Vagrant::Guest::Base
|
2010-09-02 22:44:22 +00:00
|
|
|
# Here for whenever it may be used.
|
2012-04-19 04:03:03 +00:00
|
|
|
class SolarisError < Vagrant::Errors::VagrantError
|
2011-12-16 05:07:43 +00:00
|
|
|
error_namespace("vagrant.guest.solaris")
|
2010-09-02 22:44:22 +00:00
|
|
|
end
|
|
|
|
|
2012-01-17 19:30:21 +00:00
|
|
|
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}"
|
2011-10-20 20:36:44 +00:00
|
|
|
|
2012-01-17 19:30:21 +00:00
|
|
|
vm.channel.execute("#{ifconfig_cmd} plumb")
|
|
|
|
|
|
|
|
if network[:type].to_sym == :static
|
|
|
|
vm.channel.execute("#{ifconfig_cmd} inet #{network[:ip]} netmask #{network[:netmask]}")
|
|
|
|
vm.channel.execute("#{ifconfig_cmd} up")
|
|
|
|
vm.channel.execute("#{su_cmd} sh -c \"echo '#{network[:ip]}' > /etc/hostname.#{device}\"")
|
|
|
|
elsif network[:type].to_sym == :dhcp
|
|
|
|
vm.channel.execute("#{ifconfig_cmd} dhcp start")
|
|
|
|
end
|
2011-10-20 20:36:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def change_host_name(name)
|
2011-12-10 21:44:45 +00:00
|
|
|
su_cmd = vm.config.solaris.suexec_cmd
|
2012-01-07 04:03:56 +00:00
|
|
|
|
|
|
|
# Only do this if the hostname is not already set
|
|
|
|
if !vm.channel.test("#{su_cmd} hostname | grep '#{name}'")
|
|
|
|
vm.channel.execute("#{su_cmd} sh -c \"echo '#{name}' > /etc/nodename\"")
|
|
|
|
vm.channel.execute("#{su_cmd} uname -S #{name}")
|
2011-10-20 20:36:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-02 22:44:22 +00:00
|
|
|
# There should be an exception raised if the line
|
|
|
|
#
|
|
|
|
# vagrant::::profiles=Primary Administrator
|
|
|
|
#
|
|
|
|
# does not exist in /etc/user_attr. TODO
|
|
|
|
def halt
|
2012-01-07 04:03:56 +00:00
|
|
|
# Wait until the VM's state is actually powered off. If this doesn't
|
|
|
|
# occur within a reasonable amount of time (15 seconds by default),
|
|
|
|
# then simply return and allow Vagrant to kill the machine.
|
|
|
|
count = 0
|
|
|
|
last_error = nil
|
|
|
|
while vm.state != :poweroff
|
|
|
|
begin
|
|
|
|
vm.channel.execute("#{vm.config.solaris.suexec_cmd} /usr/sbin/poweroff")
|
|
|
|
rescue IOError => e
|
|
|
|
# Save the last error; if it's not shutdown in a reasonable amount
|
|
|
|
# of attempts we will re-raise the error so it's not hidden for
|
|
|
|
# all time
|
|
|
|
last_error = e
|
|
|
|
end
|
|
|
|
|
|
|
|
count += 1
|
|
|
|
if count >= vm.config.solaris.halt_timeout
|
|
|
|
# Check for last error and re-raise it
|
|
|
|
if last_error != nil
|
|
|
|
raise last_error
|
|
|
|
else
|
|
|
|
# Otherwise, just return
|
|
|
|
return
|
2011-10-20 20:36:44 +00:00
|
|
|
end
|
2012-01-07 04:03:56 +00:00
|
|
|
end
|
2010-09-02 22:44:22 +00:00
|
|
|
|
2012-01-07 04:03:56 +00:00
|
|
|
# Still opportunities remaining; sleep and loop
|
|
|
|
sleep vm.config.solaris.halt_check_interval
|
|
|
|
end # while
|
2010-09-02 22:44:22 +00:00
|
|
|
end
|
|
|
|
|
2012-01-12 07:14:04 +00:00
|
|
|
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]
|
|
|
|
|
2011-07-06 06:59:31 +00:00
|
|
|
# Create the shared folder
|
2012-01-07 04:03:56 +00:00
|
|
|
vm.channel.execute("#{vm.config.solaris.suexec_cmd} mkdir -p #{guestpath}")
|
2011-07-06 06:59:31 +00:00
|
|
|
|
2012-01-26 17:56:06 +00:00
|
|
|
# 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"
|
|
|
|
|
2011-07-06 06:59:31 +00:00
|
|
|
# Mount the folder with the proper owner/group
|
2012-01-26 17:56:06 +00:00
|
|
|
mount_options = "-o uid=`#{id_cmd} -u #{owner}`,gid=`#{id_cmd} -g #{group}`"
|
2012-01-12 07:23:05 +00:00
|
|
|
mount_options += ",#{options[:extra]}" if options[:extra]
|
|
|
|
vm.channel.execute("#{vm.config.solaris.suexec_cmd} /sbin/mount -F vboxfs #{mount_options} #{name} #{guestpath}")
|
2011-07-06 06:59:31 +00:00
|
|
|
|
|
|
|
# chown the folder to the proper owner/group
|
2012-01-26 17:56:06 +00:00
|
|
|
vm.channel.execute("#{vm.config.solaris.suexec_cmd} chown `#{id_cmd} -u #{owner}`:`#{id_cmd} -g #{group}` #{guestpath}")
|
2010-09-02 22:44:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|