Permalink
Browse files

rename Session to Environment

  • Loading branch information...
1 parent 1e492dd commit eb998e08b345aac7fe461fd624a0469a1dd88829 @jedi4ever committed Jul 24, 2011
Showing with 421 additions and 412 deletions.
  1. +2 −0 Gemfile.lock
  2. +1 −1 README.md
  3. +10 −10 Rakefile
  4. +4 −4 bin/veewee
  5. +1 −0 lib/veewee.rb
  6. +1 −1 lib/veewee/definition.rb
  7. +205 −0 lib/veewee/environment.rb
  8. +2 −2 lib/veewee/provider/virtualbox/util/snapshots.rb
  9. +4 −204 lib/veewee/session.rb
  10. +9 −9 lib/veewee/vagrant/command.rb
  11. +1 −1 templates/CentOS-4.8-i386/definition.rb
  12. +1 −1 templates/CentOS-5.6-i386-netboot/definition.rb
  13. +1 −1 templates/CentOS-5.6-i386/definition.rb
  14. +1 −1 templates/CentOS-5.6-x86_64-netboot/definition.rb
  15. +1 −1 templates/CentOS-6.0-i386-netboot/definition.rb
  16. +1 −1 templates/CentOS-6.0-i386/definition.rb
  17. +1 −1 templates/CentOS-6.0-x86_64-netboot/definition.rb
  18. +1 −1 templates/CentOS-6.0-x86_64/definition.rb
  19. +1 −1 templates/Debian-5.0.8-amd64-netboot/definition.rb
  20. +1 −1 templates/Debian-5.0.8-i386-netboot/definition.rb
  21. +1 −1 templates/Debian-6.0.2-amd64-netboot/definition.rb
  22. +1 −1 templates/Debian-6.0.2-i386-netboot/definition.rb
  23. +1 −1 templates/Fedora-14-amd64-netboot/definition.rb
  24. +1 −1 templates/Fedora-14-amd64/definition.rb
  25. +1 −1 templates/Fedora-14-i386-netboot/definition.rb
  26. +1 −1 templates/Fedora-14-i386/definition.rb
  27. +1 −1 templates/Fedora-15-i386-netboot/definition.rb
  28. +1 −1 templates/Fedora-15-i386/definition.rb
  29. +1 −1 templates/Sysrescuecd-2.0.0-experimental/definition.rb
  30. +1 −1 templates/archlinux-i386/definition.rb
  31. +1 −1 templates/archlinux-x86_64/definition.rb
  32. +1 −1 templates/freebsd-8.2-experimental/definition.rb
  33. +1 −1 templates/freebsd-8.2-pcbsd-i386-netboot/definition.rb
  34. +1 −1 templates/freebsd-8.2-pcbsd-i386/definition.rb
  35. +1 −1 templates/gentoo-latest-i386-experimental/definition.rb
  36. +1 −1 templates/openindiana-148-ai-x86/definition.rb
  37. +1 −1 templates/opensuse-11.4-i386-experimental/definition.rb
  38. +1 −1 templates/solaris-11-express-i386/definition.rb
  39. +1 −1 templates/ubuntu-10.04.2-amd64-netboot/definition.rb
  40. +1 −1 templates/ubuntu-10.04.2-server-amd64-alt/definition.rb
  41. +1 −1 templates/ubuntu-10.04.2-server-amd64/definition.rb
  42. +1 −1 templates/ubuntu-10.04.2-server-i386-netboot/definition.rb
  43. +1 −1 templates/ubuntu-10.04.2-server-i386/definition.rb
  44. +1 −1 templates/ubuntu-10.10-server-amd64-netboot/definition.rb
  45. +1 −1 templates/ubuntu-10.10-server-amd64/definition.rb
  46. +1 −1 templates/ubuntu-10.10-server-i386-netboot/definition.rb
  47. +1 −1 templates/ubuntu-10.10-server-i386/definition.rb
  48. +1 −1 templates/ubuntu-11.04-server-amd64/definition.rb
  49. +1 −1 templates/ubuntu-11.04-server-i386/definition.rb
  50. +1 −1 templates/ubuntu-8.04.4-server-amd64/definition.rb
  51. +1 −1 templates/ubuntu-8.04.4-server-i386/definition.rb
  52. +1 −1 templates/windows-2008R2-amd64/definition.rb
  53. +24 −23 test/build_test.rb
  54. +3 −3 test/definition_test.rb
  55. +1 −1 test/definitions/test_definition/definition.rb
  56. +66 −0 test/environment_test.rb
  57. +0 −66 test/session_test.rb
  58. +13 −13 trials/docu-vbox.txt
  59. +7 −7 trials/t.rb
  60. +26 −26 validation/features/steps/ssh_steps.rb
View
@@ -31,6 +31,8 @@ GEM
highline (1.6.2)
i18n (0.5.0)
json (1.5.3)
+ json_pure (1.4.6)
+ mario (0.0.6)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-ssh (2.1.4)
View
@@ -84,7 +84,7 @@ this is essentially making a copy based on the templates provided above.
## Optionally modify the definition.rb , postinstall.sh or preseed.cfg
- Veewee::Session.declare( {
+ Veewee::Environment.declare( {
:cpu_count => '1', :memory_size=> '256',
:disk_size => '10140', :disk_format => 'VDI',
:os_type_id => 'Ubuntu',
View
@@ -17,7 +17,7 @@ end
desc 'List templates'
task :templates do
- Veewee::Session.list_templates
+ Veewee::Environment.list_templates
end
desc 'Define box'
@@ -26,7 +26,7 @@ task :define, [:boxname,:template_name] do |t,args|
puts "needs two arguments: rake define['boxname','template_name']"
exit
end
- Veewee::Session.define(args.boxname,args.template_name)
+ Veewee::Environment.define(args.boxname,args.template_name)
end
desc 'Undefine box'
@@ -35,12 +35,12 @@ task :undefine, [:boxname] do |t,args|
puts "needs one arguments: rake undefine[\"yourname\"]"
exit
end
- Veewee::Session.undefine(args.boxname)
+ Veewee::Environment.undefine(args.boxname)
end
desc 'List Definitions'
task :definitions do
- Veewee::Session.list_definitions
+ Veewee::Environment.list_definitions
end
desc 'Build box'
@@ -49,12 +49,12 @@ task :build, [:boxname] do |t,args|
puts "needs one arguments: rake build['boxname']"
exit
end
- Veewee::Session.build(args.boxname)
+ Veewee::Environment.build(args.boxname)
end
desc 'List boxes'
task :boxes do
- Veewee::Session.list_boxes
+ Veewee::Environment.list_boxes
end
desc 'Export box'
@@ -63,20 +63,20 @@ task :export, [:boxname] do |t,args|
puts "needs one arguments: rake export['boxname']"
exit
end
- Veewee::Session.export_box(args.boxname)
+ Veewee::Environment.export_box(args.boxname)
end
desc 'Remove box'
task :remove_box, [:boxname] do |t,args|
- Veewee::Session.remove_box(args.boxname)
+ Veewee::Environment.remove_box(args.boxname)
end
desc 'List ostypes available'
task :list_ostypes do |t,args|
- Veewee::Session.list_ostypes
+ Veewee::Environment.list_ostypes
end
desc 'Clean all unfinished builds'
task :clean do
- Veewee::Session.clean
+ Veewee::Environment.clean
end
View
@@ -20,20 +20,20 @@ class VeeweeCLI < Thor
end
puts "Init a new box #{boxname}, starting from template #{template}"
- Veewee::Session.define(boxname,template)
+ Veewee::Environment.define(boxname,template)
end
desc "templates", "list the template available"
def templates
- Veewee::Session.list_templates
+ Veewee::Environment.list_templates
end
desc "build [NAME]", "build the box defined"
method_options :force => :boolean
def build(boxname)
puts "Building box #{boxname}"
- vs=Veewee::Session.new(options)
+ vs=Veewee::Environment.new(options)
vd=vs.get_definition(boxname)
vs.build(boxname,vd)
end
@@ -42,7 +42,7 @@ class VeeweeCLI < Thor
method_options :force => :boolean
def export(boxname)
if (!boxname.nil?)
- Veewee::Session.export_box(boxname)
+ Veewee::Environment.export_box(boxname)
end
end
View
@@ -1 +1,2 @@
+require 'veewee/environment'
require 'veewee/session'
View
@@ -49,7 +49,7 @@ def self.load(name,definition_dir)
puts "Error: definition for basebox '#{name}' does not exist."
exit
end
- return Veewee::Definition.new(Veewee::Session.get_loaded_definition)
+ return Veewee::Definition.new(Veewee::Environment.get_loaded_definition)
end
View
@@ -0,0 +1,205 @@
+require 'veewee/definition'
+require 'veewee/provider/virtualbox'
+require 'tempfile'
+
+require 'virtualbox'
+require 'virtualbox/abstract_model'
+require 'virtualbox/ext/byte_normalizer'
+
+module Veewee
+
+ class Environment
+
+ attr_accessor :environment_dir
+ attr_accessor :definition_dir
+ attr_accessor :iso_dir
+ attr_accessor :tmp_dir
+ attr_accessor :box_dir
+
+ attr_accessor :veewee_dir
+ attr_accessor :template_dir
+ attr_accessor :validation_dir
+
+ @loaded_definition=nil
+ def self.get_loaded_definition
+ @loaded_definition
+ end
+
+ def initialize(settings={})
+ @environment_dir=settings[:environment_dir]||Dir.pwd
+ @definition_dir=settings[:definition_dir]||File.join(@environment_dir,"definitions")
+ @iso_dir=settings[:iso_dir]||File.join(@environment_dir,"iso")
+ @box_dir=settings[:box_dir]||File.join(@environment_dir,"boxes")
+ @tmp_dir=settings[:tmp_dir]||File.join(@environment_dir,"tmp")
+ @validation_dir=settings[:validation_dir]||File.expand_path(File.join(File.dirname(__FILE__),"..","..", "validation"))
+ @template_dir=settings[:template_dir]||File.expand_path(File.join(File.dirname(__FILE__),"..","..", "templates"))
+ return self
+ end
+
+ def get_definition(name)
+ # This should be locked (it loads the declare in a class var and then reads it into this environment)
+ definition=Veewee::Definition.load(name,@definition_dir)
+ return definition
+ end
+
+ # For backwards compatible reasons
+ # Shoud not be called directly
+ def self.declare(options)
+ @loaded_definition=options
+ end
+
+ def self.get_provider(name)
+ Object.const_get("Veewee").const_get("Virtualbox")
+ end
+
+ def build(name,definition)
+ options={}
+ defaults={ :provider_type => "Virtualbox" }
+ options=defaults.merge(options)
+ box_provider=Veewee::Environment.get_provider(options[:provider_type]).new(name,definition,self)
+ box_provider.build
+
+ end
+
+ def destroy(name,definition)
+ options={}
+ defaults={ :provider_type => "Virtualbox" }
+ options=defaults.merge(options)
+ box_provider=Veewee::Environment.get_provider(options[:provider_type]).new(name,definition,self)
+ box_provider.destroy_vm
+ end
+
+ def ssh(name,definition,command)
+ options={}
+ defaults={ :provider_type => "Virtualbox" }
+ options=defaults.merge(options)
+ box_provider=Veewee::Environment.get_provider(options[:provider_type]).new(name,definition,self)
+ box_provider.ssh(command)
+ end
+
+ def console_type(name,definition,command)
+ options={}
+ defaults={ :provider_type => "Virtualbox" }
+ options=defaults.merge(options)
+ box_provider=Veewee::Environment.get_provider(options[:provider_type]).new(name,definition,self)
+ box_provider.console_type(command)
+ end
+
+
+ def list_templates( options = { :format => 'vagrant'})
+ require 'pp'
+ puts @template_dir
+ puts "The following templates are available:"
+ subdirs=Dir.glob("#{@template_dir}/*")
+ subdirs.each do |sub|
+ if File.directory?("#{sub}")
+ definition=Dir.glob("#{sub}/definition.rb")
+ if definition.length!=0
+ name=sub.sub(/#{@template_dir}\//,'')
+ if (options[:format]=='vagrant')
+ puts "vagrant basebox define '<boxname>' '#{name}'"
+ end
+ if (options[:format]=='veewee')
+ puts "veewee define '<boxname>' '#{name}'"
+ end
+ end
+ end
+ end
+ end
+
+ def list_definitions
+ puts "The following defined baseboxes exist:"
+ subdirs=Dir.glob("#{@definition_dir}/*")
+ subdirs.each do |sub|
+ puts "- "+File.basename(sub)
+ end
+ end
+
+
+
+ def define(boxname,template_name,options = {})
+ #Check if template_name exists
+
+ options = { "force" => false, "format" => "vagrant" }.merge(options)
+
+ if File.directory?(File.join(@template_dir,template_name))
+ else
+ puts "This template can not be found, use vagrant basebox templates to list all templates"
+ exit
+ end
+ if !File.exists?(@definition_dir)
+ FileUtils.mkdir(@definition_dir)
+ end
+
+ if File.directory?(File.join(@definition_dir,boxname))
+ if !options["force"]
+ puts "The definition for #{boxname} already exists. Use --force to overwrite"
+ exit
+ end
+ else
+ FileUtils.mkdir(File.join(@definition_dir,boxname))
+ end
+ FileUtils.cp_r(File.join(@template_dir,template_name,'.'),File.join(@definition_dir,boxname))
+ puts "The basebox '#{boxname}' has been succesfully created from the template ''#{template_name}'"
+ puts "You can now edit the definition files stored in definitions/#{boxname}"
+ puts "or build the box with:"
+ if (options["format"]=='vagrant')
+ puts "vagrant basebox build '#{boxname}'"
+ end
+ if (options["format"]=='veewee')
+ puts "veewee build '#{boxname}'"
+ end
+
+ end
+
+ def undefine(boxname)
+ name_dir=File.join(@definition_dir,boxname)
+ if File.directory?(name_dir)
+ #TODO: Needs to be more defensive!!
+ puts "Removing definition #{boxname}"
+ FileUtils.rm_rf(name_dir)
+ else
+ puts "Can not undefine , definition #{boxname} does not exist"
+ exit
+ end
+ end
+
+
+ def self.validate_box(boxname,options)
+ require 'cucumber'
+
+ require 'cucumber/rspec/disable_option_parser'
+ require 'cucumber/cli/main'
+
+ ENV['veewee_user']=options[:user]
+ feature_path=File.join(File.dirname(__FILE__),"..","..","validation","vagrant.feature")
+
+ features=Array.new
+ features[0]=feature_path
+
+
+ begin
+ # The dup is to keep ARGV intact, so that tools like ruby-debug can respawn.
+ failure = Cucumber::Cli::Main.execute(features.dup)
+ Kernel.exit(failure ? 1 : 0)
+ rescue SystemExit => e
+ Kernel.exit(e.status)
+ rescue Exception => e
+ STDERR.puts("#{e.message} (#{e.class})")
+ STDERR.puts(e.backtrace.join("\n"))
+ Kernel.exit(1)
+ end
+
+ 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 Class
+ end #End Module
@@ -45,7 +45,7 @@ def snapshot_version_exists(vmname,snapname)
def self.rollback_snapshot(vmname,snapname)
delete_flag=false
- @vboxcmd=Veewee::Session.determine_vboxcmd
+ @vboxcmd=Veewee::Environment.determine_vboxcmd
savestate_recover=false
if (state_vmachine(vmname)=="running")
@@ -90,7 +90,7 @@ def self.rollback_snapshot(vmname,snapname)
def self.list_snapshots(vmname)
- @vboxcmd=Veewee::Session.determine_vboxcmd
+ @vboxcmd=Veewee::Environment.determine_vboxcmd
snapshotresult=Veewee::Shell.execute("#{@vboxcmd} showvminfo --machinereadable '#{vmname}' |grep ^SnapshotName| cut -d '=' -f 2").stdout
snapshotlist=snapshotresult.gsub(/\"/,'').split(/\n/)
Oops, something went wrong.

0 comments on commit eb998e0

Please sign in to comment.