Skip to content

Commit

Permalink
removed the dependency on vagrant ostypes, and introduced a mapping f…
Browse files Browse the repository at this point in the history
…ile between ostypes as defined in each virtualization type
  • Loading branch information
jedi4ever committed Sep 27, 2011
1 parent 32cc05d commit 1c14310
Show file tree
Hide file tree
Showing 12 changed files with 338 additions and 47 deletions.
4 changes: 2 additions & 2 deletions lib/vagrant_init.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions lib/veewee/builder/virtualbox/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 8 additions & 17 deletions lib/veewee/builder/virtualbox/helper/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
16 changes: 3 additions & 13 deletions lib/veewee/builder/vmfusion/helper/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions lib/veewee/command/kvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
106 changes: 106 additions & 0 deletions lib/veewee/command/vagrant.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions lib/veewee/command/virtualbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 16 additions & 1 deletion lib/veewee/command/vmfusion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions lib/veewee/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Config
attr_accessor :builders
attr_accessor :definitions
attr_accessor :templates
attr_reader :ostypes

def initialize(options)
@env=options[:env]
Expand All @@ -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)

Expand Down
Loading

0 comments on commit 1c14310

Please sign in to comment.