Browse files

removed the dependency on vagrant ostypes, and introduced a mapping f…

…ile between ostypes as defined in each virtualization type
  • Loading branch information...
1 parent 32cc05d commit 1c14310bcc06054f6edf8418aa7a43804ac5585b @jedi4ever committed Sep 27, 2011
View
4 lib/vagrant_init.rb
@@ -1,9 +1,9 @@
begin
require 'vagrant'
- require 'veewee/vagrant/command'
+ require 'veewee/command/vagrant'
rescue LoadError
require 'rubygems'
- require 'veewee/vagrant/command'
+ require 'veewee/command/vagrant'
require 'veewee/command/kvm'
end
View
6 lib/veewee/builder/virtualbox/builder.rb
@@ -39,12 +39,6 @@ def build(definition_name,box_name,options)
# w00t, we have succesfully reach this point
# so we let user know , the vm is ready to be exported
- env.ui.info "#{box_name} was build succesfully. "
- env.ui.info ""
- env.ui.info "Now you can: "
- env.ui.info "- verify your box by running : vagrant basebox validate #{box_name}"
- env.ui.info "- export your vm to a .box fileby running : vagrant basebox export #{box_name}"
-
end
end #End Class
View
25 lib/veewee/builder/virtualbox/helper/create.rb
@@ -47,21 +47,6 @@ def get_vm_location
return location
end
-def verify_ostype(definition)
-
- #Verifying the os.id with the :os_type_id specified
- matchfound=false
- VirtualBox::Global.global.lib.virtualbox.guest_os_types.collect { |os|
- if definition.os_type_id == os.id
- matchfound=true
- end
- }
- unless matchfound
- env.ui.error "The ostype: #{definition.os_type_id} is not available in your Virtualbox version"
- exit -1
- end
-
-end
def suppress_messages
#Setting this annoying messages to register
@@ -177,13 +162,19 @@ def attach_floppy(definition)
end
end
+ def vbox_os_type_id(veewee_type_id)
+ type=env.config.ostypes[veewee_type_id][:vbox]
+ env.logger.info("Using VBOX os_type_id #{type}")
+ return type
+ end
+
def create_vm(definition)
- command="#{@vboxcmd} createvm --name '#{name}' --ostype '#{definition.os_type_id}' --register"
+ command="#{@vboxcmd} createvm --name '#{name}' --ostype '#{vbox_os_type_id(definition.os_type_id)}' --register"
#Exec and system stop the execution here
Veewee::Util::Shell.execute("#{command}")
- env.ui.info "Creating vm #{name} : #{definition.memory_size}M - #{definition.cpu_count} CPU - #{definition.os_type_id}"
+ env.ui.info "Creating vm #{name} : #{definition.memory_size}M - #{definition.cpu_count} CPU - #{vbox_os_type_id(definition.os_type_id)}"
#setting cpu's
command="#{@vboxcmd} modifyvm '#{name}' --cpus #{definition.cpu_count}"
View
16 lib/veewee/builder/vmfusion/helper/create.rb
@@ -24,19 +24,9 @@ def create_disk(definition)
def fusion_os_type(type_id)
env.logger.info "Translating #{type_id} into fusion type"
- types={
- "ArchLinux" => "Linux",
- "ArchLinux_64" => "Linux",
- "RedHat"=> "centos",
- "RedHat_64"=>"centos-64",
- "RedHat"=>"centos",
- "Ubuntu_64"=>"ubuntu-64",
- "Ubuntu"=>"ubuntu",
- "Fedora"=>"fedora",
- "Fedora_64"=>"Fedora_64",
- }
- env.logger.info "Found fusion type #{types[type_id]}"
- return types[type_id]
+ fusiontype=env.config.ostypes[type_id][:fusion]
+ env.logger.info "Found fusion type #{fusiontype}"
+ return fusiontype
end
def create_vm(definition)
View
8 lib/veewee/command/kvm.rb
@@ -48,6 +48,14 @@ def undefine(definition_name)
end
end
+ desc "ostypes", "List the available Operating System types"
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ def ostypes
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+ venv.list_ostypes
+ end
+
desc "templates", "List the currently available templates"
method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
def templates
View
106 lib/veewee/command/vagrant.rb
@@ -0,0 +1,106 @@
+require 'veewee'
+
+module Veewee
+ module Vagrant
+ class Command < ::Vagrant::Command::GroupBase
+
+ register "basebox", "Commands to manage baseboxes"
+ desc "build [TEMPLATE_NAME] [BOX_NAME]", "Build box"
+ method_option :force,:type => :boolean , :default => false, :aliases => "-f", :desc => "force the build"
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ method_option :nogui,:type => :boolean , :default => false, :aliases => "-n", :desc => "no gui"
+ method_option :auto,:type => :boolean , :default => false, :aliases => "-a", :desc => "auto answers"
+ def build(definition_name,box_name=nil)
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+ venv.config.builders["virtualbox"].build(definition_name,box_name,options)
+ end
+
+ desc "destroy [BOXNAME]", "Destroys the virtualmachine that was build"
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ def destroy(box_name)
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+ venv.config.builders["virtualbox"].get_box(box_name).destroy
+ end
+
+ desc "define [BOXNAME] [TEMPLATE]", "Define a new basebox starting from a template"
+ method_option :force,:type => :boolean , :default => false, :aliases => "-f", :desc => "overwrite the definition"
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ def define(definition_name, template_name)
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+
+ venv.define(definition_name,template_name,options)
+ env.ui "The basebox '#{definition_name}' has been succesfully created from the template '#{template_name}'"
+ env.ui "You can now edit the definition files stored in definitions/#{definition_name} or build the box with:"
+ env.ui "vagrant basebox build '#{definition_name}'"
+ end
+
+ desc "undefine [BOXNAME]", "Removes the definition of a basebox "
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ def undefine(definition_name)
+ env.ui "Removing definition #{definition_name}"
+ begin
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+ venv.undefine(definition_name,options)
+ env.ui "Definition #{definition_name} succesfully removed"
+ rescue Error => ex
+ env.ui "#{ex}"
+ exit -1
+ end
+ end
+
+ desc "templates", "List the currently available templates"
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ def templates
+ env.ui.info "The following templates are available:"
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+
+ venv.get_template_paths.keys.each do |name|
+ env.ui.info "vagrant basebox define '<box_name>' '#{name}'"
+ end
+ end
+
+ desc "list", "Lists all defined boxes"
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ def list
+ env.ui.info "The following local definitions are available:"
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+
+ venv.get_definition_paths.keys.each do |name|
+ env.ui.info "- #{name}"
+ end
+ end
+
+ desc "ostypes", "List the available Operating System types"
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ def ostypes
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+ venv.list_ostypes
+ end
+
+ desc "validate [NAME]", "Validates a box against vagrant compliancy rules"
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ def validate(box_name)
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+
+ venv.config.builders["virtualbox"].validate_vagrant(box_name,options)
+ end
+
+ desc "export [NAME]", "Exports the basebox to the vagrant box format"
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ def export(box_name)
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+ venv.config.builders["virtualbox"].export_vagrant(box_name,options)
+ end
+
+ end
+end
+end
View
8 lib/veewee/command/virtualbox.rb
@@ -45,6 +45,14 @@ def undefine(definition_name)
exit -1
end
end
+
+ desc "ostypes", "List the available Operating System types"
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ def ostypes
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+ venv.list_ostypes
+ end
desc "templates", "List the currently available templates"
method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
View
17 lib/veewee/command/vmfusion.rb
@@ -11,7 +11,14 @@ class Vmfusion< Veewee::Command::GroupBase
def build(definition_name,box_name=nil)
venv=Veewee::Environment.new(options)
venv.ui=env.ui
- venv.config.builders["vmfusion"].build(definition_name,box_name,options)
+ venv.config.builders["vmfusion"].build(definition_name,box_name,options)
+
+# venv.ui.info "#{box_name} was build succesfully. "
+# venv.ui.info ""
+# venv.ui.info "Now you can: "
+# venv.ui.info "- verify your box by running : veewee fusion validate #{definition_name}"
+# venv.ui.info "- export your vm to a .box fileby running : veewee fusion export #{definition_name}"
+
end
desc "destroy [BOXNAME]", "Destroys the virtualmachine that was build"
@@ -48,6 +55,14 @@ def undefine(definition_name)
end
end
+ desc "ostypes", "List the available Operating System types"
+ method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
+ def ostypes
+ venv=Veewee::Environment.new(options)
+ venv.ui=env.ui
+ venv.list_ostypes
+ end
+
desc "export [NAME]", "Exports the basebox to the ova format"
method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
def export(box_name)
View
6 lib/veewee/config.rb
@@ -16,6 +16,7 @@ class Config
attr_accessor :builders
attr_accessor :definitions
attr_accessor :templates
+ attr_reader :ostypes
def initialize(options)
@env=options[:env]
@@ -25,6 +26,11 @@ def initialize(options)
@definitions=Hash.new
@templates=Hash.new
+ # Read ostypes
+ yamlfile=File.join(File.dirname(__FILE__),"config","ostypes.yml")
+ env.logger.info "Reading ostype yamlfile #{yamlfile}"
+ @ostypes=YAML.load_file(yamlfile)
+
# Initialize with defaults
@veewee=::Veewee::Config::Veewee.new(self)
View
165 lib/veewee/config/ostypes.yml
@@ -0,0 +1,165 @@
+---
+Other:
+ :fusion: other
+ :kvm:
+ :vbox: Other
+Other:
+ :fusion: other-64
+ :kvm:
+ :vbox: Other
+FreeBSD:
+ :fusion: freeBSD
+ :kvm:
+ :vbox: FreeBSD
+FreeBSD_64:
+ :fusion: FreeBSD_64
+ :kvm:
+ :vbox: FreeBSD-64
+Oracle:
+ :fusion: oraclelinux
+ :kvm:
+ :vbox: Oracle
+Oracle_64:
+ :fusion: oraclelinux-64
+ :kvm:
+ :vbox: Oracle_64
+Debian:
+ :fusion: debian5
+ :kvm:
+ :vbox: Debian
+Debian_64:
+ :fusion: debian5-64
+ :kvm:
+ :vbox: Debian_64
+Gentoo:
+ :fusion: other26xlinux
+ :kvm:
+ :vbox: Gentoo
+Gentoo_64:
+ :fusion: other26xlinux-64
+ :kvm:
+ :vbox: Gentoo_64
+Linux22:
+ :fusion: linux
+ :kvm:
+ :vbox: Linux22
+Linux24:
+ :fusion: other24xlinux
+ :kvm:
+ :vbox: Linux24
+Linux24_64:
+ :fusion: other24xlinux-64
+ :kvm:
+ :vbox: Linux24_64
+Linux26:
+ :fusion: other26xlinux
+ :kvm:
+ :vbox: Linux26
+Linux26_64:
+ :fusion: other26xlinux-64
+ :kvm:
+ :vbox: Linux26_64
+RedHat:
+ :fusion: RedHat
+ :kvm:
+ :vbox: RedHat
+RedHat_64:
+ :fusion: RedHat_64
+ :kvm:
+ :vbox: RedHat_64
+Centos:
+ :fusion: centos
+ :kvm:
+ :vbox: RedHat
+Centos_64:
+ :fusion: centos-64
+ :kvm:
+ :vbox: RedHat_64
+ArchLinux:
+ :fusion: other26xlinux
+ :kvm:
+ :vbox: ArchLinux
+ArchLinux_64:
+ :fusion: other26xlinux-64
+ :kvm:
+ :vbox: ArchLinux_64
+OpenSUSE:
+ :fusion: opensuse
+ :kvm:
+ :vbox: OpenSUSE
+OpenSUSE_64:
+ :fusion: opensuse-64
+ :kvm:
+ :vbox: OpenSUSE_64
+SUSE:
+ :fusion: suse
+ :kvm:
+ :vbox: OpenSUSE
+SUSE_64:
+ :fusion: suse-64
+ :kvm:
+ :vbox: OpenSUSE_64
+Fedora:
+ :fusion: fedora
+ :kvm:
+ :vbox: Fedora
+Fedora_64:
+ :fusion: fedora-64
+ :kvm:
+ :vbox: Fedora_64
+Ubuntu:
+ :fusion: ubuntu
+ :kvm:
+ :vbox: Ubuntu
+Ubuntu_64:
+ :fusion: ubuntu-64
+ :kvm:
+ :vbox: Ubuntu_64
+Linux:
+ :fusion: linux
+ :kvm:
+ :vbox: Linux
+Solaris:
+ :fusion: solaris10
+ :kvm:
+ :vbox: Solaris
+Solaris_64:
+ :fusion: solaris10-64
+ :kvm:
+ :vbox: Solaris_64
+Solaris9:
+ :fusion: solaris
+ :kvm:
+ :vbox: Solaris
+Solaris7:
+ :fusion: solaris7
+ :kvm:
+ :vbox: Solaris
+Solaris8:
+ :fusion: solaris8
+ :kvm:
+ :vbox: Solaris
+OpenSolaris:
+ :fusion: solaris10
+ :kvm:
+ :vbox: OpenSolaris
+OpenSolaris_64:
+ :fusion: solaris-64
+ :kvm:
+ :vbox: OpenSolaris_64
+OpenBSD:
+ :fusion: other
+ :kvm:
+ :vbox: OpenBSD
+OpenBSD_64:
+ :fusion: other-64
+ :kvm:
+ :vbox: OpenBSD_64
+NetBSD:
+ :fusion: other
+ :kvm:
+ :vbox: NetBSD
+NetBSD_64:
+ :fusion: other-64
+ :kvm:
+ :vbox: NetBSD_64
View
15 lib/veewee/definition.rb
@@ -70,7 +70,9 @@ def declare(options)
options.each do |key, value|
instance_variable_set("@#{key}".to_sym, options[key])
env.logger.info("definition") { " - #{key} : #{options[key]}" }
- end
+ end
+ verify_ostype
+
end
# Loading a definition
@@ -105,13 +107,22 @@ def self.load(name,env)
rescue NameError => ex
env.ui.error("NameError reading definition from file #{definition_file} #{ex}")
rescue Exception => ex
- env.ui.error("Error reading definition from file #{definition_file}#{ex}")
+ env.ui.error("Error in the definition from file #{definition_file}\n#{ex}")
+ exit -1
end
else
env.logger.info "#{definition_file} not found"
end
veewee_definition
end
+
+ def verify_ostype
+
+ unless env.config.ostypes.has_key?(@os_type_id)
+ raise "The ostype: #{@os_type_id} is not available"
+ end
+
+ end
end #End Class
View
9 lib/veewee/environment.rb
@@ -125,12 +125,9 @@ def get_template_paths
def list_ostypes
@ui.info "The following are possible os_types you can use in your definition.rb files"
-
- require 'virtualbox'
- os_types=VirtualBox::Global.global.lib.virtualbox.guest_os_types
-
- os_types.each { |os|
- @ui.info "#{os.id}: #{os.description}"
+
+ config.ostypes.each { |key,value|
+ @ui.info "#{key}"
}
end

0 comments on commit 1c14310

Please sign in to comment.