vagrant/plugins/guests/solaris/guest.rb

74 lines
2.8 KiB
Ruby
Raw Normal View History

require "vagrant"
module VagrantPlugins
module GuestSolaris
# A general Vagrant system implementation for "solaris".
#
# Contributed by Blake Irvin <b.irvin@modcloth.com>
2012-11-07 05:14:45 +00:00
class Guest < Vagrant.plugin("2", :guest)
# Here for whenever it may be used.
class SolarisError < Vagrant::Errors::VagrantError
error_namespace("vagrant.guest.solaris")
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}"
vm.communicate.execute("#{ifconfig_cmd} plumb")
2012-01-17 19:30:21 +00:00
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}\"")
2012-01-17 19:30:21 +00:00
elsif network[:type].to_sym == :dhcp
vm.communicate.execute("#{ifconfig_cmd} dhcp start")
2012-01-17 19:30:21 +00:00
end
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.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
vm.communicate.execute("#{vm.config.solaris.suexec_cmd} /usr/sbin/poweroff")
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}")
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"
# 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.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