Permalink
Browse files

Further cleanup

  • Loading branch information...
1 parent d301d12 commit 1e492dd909a0d60c9f64e4b435bf334caa1630ce @jedi4ever committed Jul 20, 2011
View
@@ -7,36 +7,13 @@ require 'virtualbox'
require 'veewee'
-#Setup some base variables to use
-veewee_dir= File.expand_path(File.join(File.dirname(__FILE__),".."))
-definition_dir= File.expand_path(File.join(".", "definitions"))
-lib_dir= File.expand_path(File.join(veewee_dir, "lib"))
-box_dir= File.expand_path(File.join(veewee_dir, "boxes"))
-template_dir=File.expand_path(File.join(veewee_dir, "templates"))
-
-#vbox_dir=File.expand_path(File.join(veewee_dir, "tmp"))
-tmp_dir=File.expand_path(File.join(veewee_dir, "tmp"))
-
-iso_dir=File.expand_path(File.join(veewee_dir, "iso"))
-
-#needs to be moved to the config files to be allowed override
-#ENV['VBOX_USER_HOME']=vbox_dir
-
-#Load Veewee::Session libraries
-Dir.glob(File.join(lib_dir, '**','*.rb')).each {|f|
- require f }
-
-#Initialize
-Veewee::Session.setenv({:veewee_dir => veewee_dir, :definition_dir => definition_dir,
- :template_dir => template_dir, :iso_dir => iso_dir, :box_dir => box_dir, :tmp_dir => tmp_dir})
-
-
class VeeweeCLI < Thor
- desc "init [NAME] [TEMPLATE]", "initializes a box from a template"
+ desc "define [NAME] [TEMPLATE]", "initializes a box from a template"
method_options :force => :boolean
- def init(boxname=nil, template=nil)
+ def define(boxname=nil, template=nil)
+
if (boxname.nil?)
puts "please provide a boxname"
exit
@@ -56,7 +33,9 @@ class VeeweeCLI < Thor
method_options :force => :boolean
def build(boxname)
puts "Building box #{boxname}"
- Veewee::Session.build(boxname)
+ vs=Veewee::Session.new(options)
+ vd=vs.get_definition(boxname)
+ vs.build(boxname,vd)
end
desc "export [NAME]", "export the box"
@@ -1,5 +1,8 @@
require 'veewee/provider/virtualbox/build'
require 'veewee/provider/virtualbox/destroy'
+require 'veewee/provider/virtualbox/ssh'
+require 'veewee/provider/virtualbox/console_type'
+
require 'veewee/provider/core/iso'
require 'virtualbox'
@@ -43,13 +46,13 @@ def add_ssh_nat_mapping
vm.save
end
- def self.list_ostypes
- puts
- puts "Available os types:"
- VirtualBox::Global.global.lib.virtualbox.guest_os_types.collect { |os|
- puts "#{os.id}: #{os.description}"
- }
- end
+# def self.list_ostypes
+# puts
+# puts "Available os types:"
+# VirtualBox::Global.global.lib.virtualbox.guest_os_types.collect { |os|
+# puts "#{os.id}: #{os.description}"
+# }
+# end
end
end
@@ -27,10 +27,9 @@ def build
#Suppress those annoying virtualbox messages
suppress_messages
-
+
#Check iso file
verify_iso(@definition.iso_file)
-
vm=VirtualBox::VM.find(@boxname)
@@ -72,106 +71,103 @@ def build
#checksums=calculate_checksums(@definition,boxname)
checksums=[ "XXX"]
- transaction("0-initial-#{checksums[0]}",checksums) do
+ # transaction("0-initial-#{checksums[0]}",checksums) do
- #Create the Virtualmachine and set all the memory and other stuff
- create_vm
- add_shared_folder
+ #Create the Virtualmachine and set all the memory and other stuff
+ create_vm
+ add_shared_folder
- #Create a disk with the same name as the boxname
- create_disk
+ #Create a disk with the same name as the boxname
+ create_disk
- #These command actually call the commandline of Virtualbox, I hope to use the virtualbox-ruby library in the future
- add_ide_controller
- add_sata_controller
- attach_disk
- mount_isofile
- add_ssh_nat_mapping
- create_floppy
+ #These command actually call the commandline of Virtualbox, I hope to use the virtualbox-ruby library in the future
+ add_ide_controller
+ add_sata_controller
+ attach_disk
+ mount_isofile
+ add_ssh_nat_mapping
+ create_floppy
- #Starting machine
+ #Starting machine
- if (options["nogui"]==true)
- start_vm("vrdp")
- else
- start_vm("gui")
- end
+ if (options["nogui"]==true)
+ start_vm("vrdp")
+ else
+ start_vm("gui")
+ end
- #waiting for it to boot
- puts "Waiting for the machine to boot"
- sleep @definition.boot_wait.to_i
-
- send_sequence(@definition.boot_cmd_sequence)
-
- kickstartfile=@definition.kickstart_file
- if kickstartfile.nil? || kickstartfile.length == 0
- puts "Skipping webserver as no kickstartfile was specified"
- else
- puts "Starting a webserver on port #{@definition.kickstart_port}"
- #:kickstart_port => "7122", :kickstart_ip => self.local_ip, :kickstart_timeout => 1000,:kickstart_file => "preseed.cfg",
- if kickstartfile.is_a? String
- Veewee::Util::Web.wait_for_request(kickstartfile,{:port => @definition.kickstart_port,
- :host => @definition.kickstart_ip, :timeout => @definition.kickstart_timeout,
- :web_dir => File.join(@environment.definition_dir,@boxname)})
- end
- if kickstartfile.is_a? Array
- kickstartfiles=kickstartfile
- kickstartfiles.each do |kickfile|
- Veewee::Util::Web.wait_for_request(kickfile,{:port => @definition.kickstart_port,
- :host => @definition.kickstart_ip, :timeout => @definition.kickstart_timeout,
- :web_dir => File.join(@environment.definition_dir,@boxname)})
- end
+ #waiting for it to boot
+ puts "Waiting for the machine to boot"
+ sleep @definition.boot_wait.to_i
+
+ send_sequence(@definition.boot_cmd_sequence)
+
+ kickstartfile=@definition.kickstart_file
+ if kickstartfile.nil? || kickstartfile.length == 0
+ puts "Skipping webserver as no kickstartfile was specified"
+ else
+ puts "Starting a webserver on port #{@definition.kickstart_port}"
+ #:kickstart_port => "7122", :kickstart_ip => self.local_ip, :kickstart_timeout => 1000,:kickstart_file => "preseed.cfg",
+ if kickstartfile.is_a? String
+ Veewee::Util::Web.wait_for_request(kickstartfile,{:port => @definition.kickstart_port,
+ :host => @definition.kickstart_ip, :timeout => @definition.kickstart_timeout,
+ :web_dir => File.join(@environment.definition_dir,@boxname)})
+ end
+ if kickstartfile.is_a? Array
+ kickstartfiles=kickstartfile
+ kickstartfiles.each do |kickfile|
+ Veewee::Util::Web.wait_for_request(kickfile,{:port => @definition.kickstart_port,
+ :host => @definition.kickstart_ip, :timeout => @definition.kickstart_timeout,
+ :web_dir => File.join(@environment.definition_dir,@boxname)})
end
end
+ end
+
+
+
+
+ Veewee::Util::Ssh.when_ssh_login_works("localhost",ssh_options) do
+ #Transfer version of Virtualbox to $HOME/.vbox_version
+ versionfile=Tempfile.open("vbox.version")
+ versionfile.puts "#{VirtualBox::Global.global.lib.virtualbox.version.split('_')[0]}"
+ versionfile.rewind
+ begin
+ Veewee::Util::Ssh.transfer_file("localhost",versionfile.path,".vbox_version", ssh_options)
+ rescue RuntimeError
+ puts "error transfering file, possible not enough permissions to write?"
+ exit
+ end
+ puts ""
+ versionfile.close
+ versionfile.delete
+ end
+
+ # end #initial Transaction
+ counter=1
+ @definition.postinstall_files.each do |postinstall_file|
+
+ filename=File.join(@environment.definition_dir,@boxname,postinstall_file)
+ #transaction(boxname,"#{counter}-#{postinstall_file}-#{checksums[counter]}",checksums) do
Veewee::Util::Ssh.when_ssh_login_works("localhost",ssh_options) do
- #Transfer version of Virtualbox to $HOME/.vbox_version
- versionfile=Tempfile.open("vbox.version")
- versionfile.puts "#{VirtualBox::Global.global.lib.virtualbox.version.split('_')[0]}"
- versionfile.rewind
begin
- Veewee::Util::Ssh.transfer_file("localhost",versionfile.path,".vbox_version", ssh_options)
+ Veewee::Util::Ssh.transfer_file("localhost",filename,File.basename(filename),ssh_options)
rescue RuntimeError
puts "error transfering file, possible not enough permissions to write?"
exit
end
- puts ""
- versionfile.close
- versionfile.delete
+ command=@definition.sudo_cmd
+ newcommand=command.gsub(/%p/,"#{@definition.ssh_password}")
+ newcommand.gsub!(/%u/,"#{@definition.ssh_user}")
+ newcommand.gsub!(/%f/,"#{postinstall_file}")
+ puts "***#{newcommand}"
+ Veewee::Util::Ssh.execute("localhost","#{newcommand}",ssh_options)
end
- return
- exit #DEBUGGING
-
- end #initial Transaction
-
-
- counter=1
- @definition[:postinstall_files].each do |postinstall_file|
-
- filename=File.join(environment.definition_dir,boxname,postinstall_file)
-
- transaction(boxname,"#{counter}-#{postinstall_file}-#{checksums[counter]}",checksums) do
-
- Veewee::Ssh.when_ssh_login_works("localhost",ssh_options) do
- begin
- Veewee::Ssh.transfer_file("localhost",filename,File.basename(filename),ssh_options)
- rescue RuntimeError
- puts "error transfering file, possible not enough permissions to write?"
- exit
- end
- command=@definition[:sudo_cmd]
- newcommand=command.gsub(/%p/,"#{definition[:ssh_password]}")
- newcommand.gsub!(/%u/,"#{definition[:ssh_user]}")
- newcommand.gsub!(/%f/,"#{postinstall_file}")
- puts "***#{newcommand}"
- Veewee::Ssh.execute("localhost","#{newcommand}",ssh_options)
- end
-
- end
+ #end Other Transactions
counter+=1
end
@@ -0,0 +1,11 @@
+require 'veewee/provider/virtualbox/util/scancode'
+
+module Veewee
+ module Provider
+ module Virtualbox
+ def console_type(command)
+ send_sequence(command)
+ end
+end #Module
+end #Module
+end #Module
@@ -16,12 +16,14 @@ def export_vagrant
#We need to shutdown first
if vm.running?
puts "Vagrant requires the box to be shutdown, before it can export"
- puts "Sudo also needs to work for user #{definition[:ssh_user]}"
+ puts "Sudo also needs to work for user #{@definition.ssh_user}"
puts "Performing a clean shutdown now."
- ssh_options={ :user => definition[:ssh_user], :port => definition[:ssh_host_port], :password => definition[:ssh_password],
- :timeout => definition[:ssh_timeout]}
+ ssh_options={ :user => definition[:ssh_user],
+ :port => @definition.ssh_host_port,
+ :password => @definition.ssh_password,
+ :timeout => @definition.ssh_timeout}
- Veewee::Ssh.execute("localhost","sudo #{definition[:shutdown_cmd]}",ssh_options)
+ Veewee::Ssh.execute("localhost","sudo #{@definition.shutdown_cmd}",ssh_options)
#Wait for state poweroff
while (vm.running?) do
@@ -0,0 +1,16 @@
+module Veewee
+ module Provider
+ module Virtualbox
+ def ssh(command)
+ ssh_options={
+ :user => @definition.ssh_user,
+ :port => @definition.ssh_host_port,
+ :password => @definition.ssh_password,
+ :timeout => @definition.ssh_login_timeout.to_i
+ }
+ result=Veewee::Util::Ssh.execute("localhost","#{command}",ssh_options)
+ return result
+ end
+ end #Module
+ end #Module
+end #Module
Oops, something went wrong.

0 comments on commit 1e492dd

Please sign in to comment.