require 'vbox/session' #Load Vbox::Session libraries lib_dir= File.expand_path(File.join(File.dirname(__FILE__),"..","..", "lib")) Dir.glob(File.join(lib_dir, '**','*.rb')).each {|f| require f } #Setup some base variables to use template_dir=File.expand_path(File.join(lib_dir,"..", "templates")) vbox_dir="." definition_dir= File.expand_path(File.join(vbox_dir, "definitions")) tmp_dir=File.expand_path(File.join(vbox_dir, "tmp")) iso_dir=File.expand_path(File.join(vbox_dir, "iso")) box_dir=File.expand_path(File.join(vbox_dir, "boxes")) validation_dir=File.expand_path(File.join(lib_dir, "..","validation")) #Initialize Vbox::Session.setenv({:vbox_dir => vbox_dir, :definition_dir => definition_dir, :template_dir => template_dir, :iso_dir => iso_dir, :box_dir => box_dir, :tmp_dir => tmp_dir, :validation_dir => validation_dir}) module Vbox class Command < Vagrant::Command::GroupBase register "vboxes","Commands to manage vboxes" desc "templates", "List the currently available basebox templates" def templates Vbox::Session.list_templates end desc "define BOXNAME TEMPLATE", "Define a new vbox starting from a template" method_option :force,:type => :boolean , :default => false, :aliases => "-f", :desc => "overwrite the definition" def define(boxname, template) Vbox::Session.define(boxname,template,options) end desc "undefine BOXNAME", "Removes the definition of a vbox " def undefine(boxname) Vbox::Session.undefine(boxname) end desc "build BOXNAME", "Build the box BOXNAME" method_option :force,:type => :boolean , :default => false, :aliases => "-f", :desc => "overwrite the vbox" method_option :nogui,:type => :boolean , :default => false, :aliases => "-n", :desc => "no gui" def build(boxname) Vbox::Session.build(boxname,options) end desc "ostypes", "List the available Operating System types" def ostypes Vbox::Session.list_ostypes end desc "destroy BOXNAME", "Destroys the virtualmachine that was build for a vbox" def destroy(boxname) Vbox::Session.destroy_vm(boxname) end desc "list", "Lists all defined vbox" def list Vbox::Session.list_definitions end desc "export [NAME]", "Exports the vbox to the vagrant box format" method_options :force => :boolean def export(boxname) if (!boxname.nil?) Vbox::Session.export_box(boxname) end end desc "validate [NAME]", "Validates a box against vagrant compliancy rules" method_option :user,:default => "vagrant", :aliases => "-u", :desc => "user to login with" def validate(boxname) if (!boxname.nil?) Vbox::Session.validate_box(boxname,options) end end end end