From 123e87c13c312767e53e14d1d3535f5b785d6392 Mon Sep 17 00:00:00 2001 From: Blake Irvin Date: Thu, 2 Sep 2010 15:44:22 -0700 Subject: [PATCH] Added a rough system class for Solaris - solaris.rb --- lib/vagrant/systems/linux.rb | 5 ++- lib/vagrant/systems/solaris.rb | 59 ++++++++++++++++++++++++++++++++++ templates/locales/en.yml | 2 ++ 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 lib/vagrant/systems/solaris.rb diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index 50d7833a5..b89fadf60 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -13,6 +13,8 @@ module Vagrant # generally, Vagrant tries to make almost every aspect of its execution # configurable, and this assists that goal. class LinuxConfig < Vagrant::Config::Base + Config.configures :linux, self + attr_accessor :halt_timeout attr_accessor :halt_check_interval @@ -22,9 +24,6 @@ module Vagrant end end - # Register config class - Config.configures :linux, LinuxConfig - #------------------------------------------------------------------- # Overridden methods #------------------------------------------------------------------- diff --git a/lib/vagrant/systems/solaris.rb b/lib/vagrant/systems/solaris.rb new file mode 100644 index 000000000..9ee45370f --- /dev/null +++ b/lib/vagrant/systems/solaris.rb @@ -0,0 +1,59 @@ +module Vagrant + module Systems + # A general Vagrant system implementation for "solaris". + # + # Contributed by Blake Irvin + class Solaris < Base + # A custom config class which will be made accessible via `config.solaris` + # This is not necessary for all system implementers, of course. However, + # generally, Vagrant tries to make almost every aspect of its execution + # configurable, and this assists that goal. + class SolarisConfig < Vagrant::Config::Base + Config.configures :solaris, self + + attr_accessor :halt_timeout + attr_accessor :halt_check_interval + + def initialize + @halt_timeout = 30 + @halt_check_interval = 1 + end + end + + # Here for whenever it may be used. + class SolarisError < Errors::VagrantError + error_namespace("vagrant.systems.solaris") + 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.env.ui.info "vagrant.systems.solaris.attempting_halt" + vm.ssh.execute do |ssh| + ssh.exec!("pfexec poweroff") + end + + # 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 + while vm.vm.state != :powered_off + count += 1 + + return if count >= vm.env.config.solaris.halt_timeout + sleep vm.env.config.solaris.halt_check_interval + end + end + + def mount_shared_folder(ssh, name, guestpath) + ssh.exec!("pfexec mkdir -p #{guestpath}") + # Using a custom mount method here; could use improvement. + ssh.exec!("pfexec mount -F vboxfs v-root #{guestpath}") + ssh.exec!("pfexec chown #{vm.env.config.ssh.username} #{guestpath}") + end + end + end +end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 44feb4a96..25c9d4c62 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -388,3 +388,5 @@ en: Otherwise, please report your distro and how to modify network interfaces to the Vagrant mailing list or IRC and we'll probably be glad to add it to the internal systems. + solaris: + attempting_halt: "Attempting graceful shutdown of solaris..."