Permalink
Browse files

Almost working

  • Loading branch information...
jedi4ever committed Nov 11, 2010
1 parent fe0db3f commit ff2c1177b4d8e28403c600a6ff6b67386c7d8944
View
@@ -1,3 +1,5 @@
+.DS_Store
gems/*
iso/*
tmp/*
+definitions/*
View
126 Rakefile
@@ -1,44 +1,94 @@
-base_dir= File.dirname(__FILE__)
-box_definition_dir= File.dirname(__FILE__)+"/"+"definitions"
+ENV['GEM_PATH']=File.dirname(__FILE__)
+ENV['GEM_HOME']=File.dirname(__FILE__)
-desc 'Default: list option'
-task :default => [:test]
+def check_environment
+ begin
+ require 'vagrant'
+ rescue LoadError
+ puts "you need to install depedencies: gem instal vagrant"
+ exit
+ end
+
+ begin
+ require 'net/ssh'
+ require 'virtualbox'
+ require 'webrick'
+ rescue LoadError
+ puts "hmm you had vagrant installed but are missing the net-ssh or virtualbox gem: gem instal virtualbox net-ssh"
+ exit
+ end
+end
+
+#See if all gems and so are installed
+check_environment
+
+#Setup some base variables to use
+veewee_dir= File.dirname(__FILE__)
+definition_dir= File.expand_path(File.join(veewee_dir, "definitions"))
+lib_dir= File.expand_path(File.join(veewee_dir, "lib"))
+template_dir=File.expand_path(File.join(veewee_dir, "templates"))
+vbox_dir=File.expand_path(File.join(veewee_dir, "tmp"))
+iso_dir=File.expand_path(File.join(veewee_dir, "iso"))
+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})
+
+desc 'Default: list templates'
+task :default => [:templates]
+
+desc 'List templates'
+task :templates do
+ Veewee::Session.list_templates
+end
+
+desc 'Define box'
+task :define, [:boxname,:template_name] do |t,args|
+ if args.to_hash.size!=2
+ puts "needs two arguments: rake define['boxname','template_name']"
+ exit
+ end
+ Veewee::Session.define(args.boxname,args.template_name)
+end
+
+desc 'Undefine box'
+task :undefine, [:boxname] do |t,args|
+ if args.to_hash.size!=1
+ puts "needs one arguments: rake undefine[\"yourname\"]"
+ exit
+ end
+ Veewee::Session.undefine(args.boxname)
+end
+
+desc 'List Definitions'
+task :definitions do
+ Veewee::Session.list_definitions
+end
desc 'Build box'
-task :build, [:box] do |t,args|
- box=args.box
- if File.directory?("#{box_definition_dir}/#{box}")
- if run_box.length!=0
- puts "Executing #{run_box}"
- require("#{run_box}")
- end
- end
-
-end
-
-desc 'Test box'
-task :test, [:box] do |t,args|
- system("puppet apply -v --debug --modulepath=#{base_dir}/modules recipe/site.pp")
-end
-
-desc 'List Boxes'
-task :list do
-
- subdirs=Dir.glob("#{box_definition_dir}/*")
- subdirs.each do |sub|
- if File.directory?("#{sub}")
- run_box=Dir.glob("#{sub}/run.rb")
- clean_box=Dir.glob("#{sub}/clean.rb")
- if run_box.length!=0
- name=sub.sub(/#{box_dir}\//,'')
- puts "rake run['#{name}']"
- end
- if clean_box.length!=0
- name=sub.sub(/#{box_dir}\//,'')
- puts "rake clean['#{name}']"
- end
- end
- end
+task :build, [:boxname] do |t,args|
+ if args.to_hash.size!=1
+ puts "needs one arguments: rake build['boxname']"
+ exit
+ end
+ Veewee::Session.build(args.boxname)
+end
+
+desc 'List boxes'
+task :boxes do
+ Veewee::Session.list_boxes
+end
+desc 'Remove box'
+task :remove_box, [:boxname] do |t,args|
+ Veewee::Session.remove_box(args.boxname)
end
+desc 'Clean all unfinished builds'
+task :clean do
+ Veewee::Session.clean
+end
View
@@ -1,12 +0,0 @@
-# quit unless our script gets two command line arguments
-unless ARGV.length == 2
- puts "Dude, not the right number of arguments."
- puts "Usage: ruby MyScript.rb InputFile.csv SortedOutputFile.csv\n"
-
-
- # our input file should be the first command line arg
- input_file = ARGV[0]
- #
- # # our output file should be the second command line arg
- output_file = ARGV[1]
-end
View
@@ -1,79 +0,0 @@
-def send_sequence(vboxcmd,vname,sequence)
- cmd="";
- sequence.each { |s|
- keycodes=string_to_keycode(s)
- puts keycodes
- # VBox seems to have issues with sending the scancodes as one big
- # .join()-ed string. It seems to get them out or order or ignore some.
- # A workaround is to send the scancodes one-by-one.
- codes=""
- for keycode in keycodes.split(' ') do
- codes=codes+send_keycode(vboxcmd,vname,keycode)
- end
- cmd=cmd+codes+" sleep 1;"
- }
- return cmd;
-end
-
-def send_keycode(vboxcmd,vname,keycode)
-
- return "#{vboxcmd} controlvm '#{vname}' keyboardputscancode #{keycode} ;"
-end
-
-def string_to_keycode(thestring)
-
- #http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
-
- k=Hash.new
- k['1'] = '02' ; k['2'] = '03' ; k['3'] = '04'; k['4']= '05' ;k['5']='06'; k['6'] = '07' ; k['7'] = '08'; k['8'] = '09'; k['9']= '0a'; k['0']='0b'; k['-'] = '0c'; k['='] = '0d' ;
- k['Tab'] = '0f'; k['q'] = '10' ; k['w'] = '11' ; k['e'] = '12'; k['r'] = '13' ; k['t'] = '14' ; k['y'] = '15'; k['u']= '16' ; k['i']='17'; k['o'] = '18' ; k['p'] = '19' ; k['[']='1a'; k[']']='1b'
- k['Q'] = '2a 10 aa' ; k['W'] = '2a 11 aa' ; k['E'] = '2a 12 aa'; k['R'] = '2a 13 aa' ; k['t'] = '14' ; k['y'] = '15'; k['U']= '2a 16 aa' ; k['i']='17'; k['o'] = '18' ; k['p'] = '19' ;
-
- k['a'] = '1e'; k['s'] = '1f' ; k['d'] = '20' ; k['f'] = '21'; k['g'] = '22' ; k['h'] = '23' ; k['j'] = '24'; k['k']= '25' ; k['l']='26'; k[';'] = '27' ;k['"']='28';
- k['a'] = '1e'; k['S'] = '2a 1f aa' ; k['d'] = '20' ; k['f'] = '21'; k['g'] = '22' ; k['h'] = '23' ; k['j'] = '24'; k['k']= '25' ; k['l']='26'; k[';'] = '27' ;k['"']='28';
-
- k['z'] = '2c'; k['x'] = '2d' ; k['c'] = '2e' ; k['v'] = '2f'; k['b'] = '30' ; k['n'] = '31' ; k['m'] = '32'; k[',']= '33' ; k['.']='34'; k['/'] = '35' ;k[':'] = '2a 27 aa'
- k['_'] = '2a 0c aa';
-
- special=Hash.new;
- special['<Enter>'] = '1c';
- special['<Backspace>'] = '0e';
- special['<Spacebar>'] = '39';
- special['<Return>'] = '1c'
- special['<Esc>'] = '01';
-
- keycodes=''
- thestring.gsub!(/ /,"<Spacebar>")
-
- until thestring.length == 0
- nospecial=true;
- special.keys.each { |key|
- if thestring.start_with?(key)
- #take thestring
- #check if it starts with a special key + pop special string
- keycodes=keycodes+special[key]+' ';
- thestring=thestring.slice(key.length,thestring.length-key.length)
- nospecial=false;
- break;
- end
- }
- if nospecial
- keycodes=keycodes+k[thestring.slice(0,1)]+' ';
- thestring=thestring.slice(1,thestring.length-1)
- end
- #else take the character + pop 1 character
- end
-
- return keycodes
-end
-
-
-module Puppet::Parser::Functions
- newfunction(:sendkeystrokes, :type => :rvalue) do |args|
- vboxcmd= args[0]
- vname = args[1]
- keystrokes = args[2]
- cmd=send_sequence(vboxcmd,vname,keystrokes)
- return cmd
- end
-end
View
@@ -1,140 +0,0 @@
-ENV['GEM_PATH']=File.dirname(__FILE__)
-ENV['GEM_HOME']=File.dirname(__FILE__)
-ENV['VBOX_USER_HOME']=File.dirname(__FILE__)+"/tmp"
-#PATH=$GEM_HOME/bin:$PATH
-
-require 'webrick'
-include WEBrick
-
-exit
-
-class Veewee
-
- #:vostype -> this is the virtualbox type
- #
- def self.contract(options={:vcpu => '1', :vmemory=> '348', :vdisksize => '10140', :isodst => "", :isosrc => "", :isomd5 => "", :bootwait => "30",
- :vostype => "Ubuntu", :bootcmd => "", :kickport => "", :kickip => "", :vmname => "ubuntu", :hostsshport => "2222", :guestsshport => "22"})
- puts "it works"
-
- #Download iso file is not existing
-
- #Verify the md5
- if [ options[:isomd5] != ""]
- puts "we go an isomd5"
- verify_md5(options[:isodst],options[:isomd5])
- end
-
- #Check if exists (remove if wanted)
- #Create VM unless exits
- #Add IDE unless exists
- #Add SATA unless exists
- #Create Disk unless exists
- #Add Disk to SATA unless already linked
- #Add ISO to IDE unless already mounted
- #Boot VM unless already booted
- #Wait some time
- #Send some keystrokes unless ssh exists
- #Wait for SSH to become alive
- #Login to the box with username, password
- #sudo install a minimal chef thing (rvm?)
- #or example a script as root to care of the minimal fixing
- #If installed and checks are running
- #export the box
-
- end
-
- def self.verify_md5(filename,checksum)
- puts "verifying md5 sum"
- end
-
- def self.checkiso_exists(filename)
- puts "verifying if iso exists"
- puts "potentional ask it to download iso, if ask"
- end
-
- def self.install_gems
- #install vagrant gem
- #install md5sum? gem
- #install virtualbox gem
- end
-
- def self.find_vbox_cmd
- #vboxheadless="VBoxHeadless"
- return "VBoxManage"
- end
-
- def self.create_vm(options)
- #command => "${vboxcmd} createvm --name ${vmname} --ostype ${vostype} --register",
- #unless => "${vboxcmd} list vms|grep ${vname}"
- end
-
- def self.create_disk(options)
- #command => "${vboxcmd} createhd --filename '${vname}.vdi' --size ${vdisksize}",
- #unless => "${vboxcmd} showhdinfo '${vname}.vdi'"
- end
-
- def self.create_ide(vmname)
- #command => "${vboxcmd} storagectl '${vname}' --name 'IDE Controller' --add ide",
- #unless => "${vboxcmd} showvminfo '${vname}' | grep 'IDE Controller' "
- end
-
- def self.attach_disk(vmname)
- #command => "${vboxcmd} storageattach '${vname}' --storagectl 'SATA Controller' --port 0 --device 0 --type hdd --medium '${vname}.vdi'",
- end
-
- def self.mount_iso(vmname,isofile)
- #command => "${vboxcmd} storageattach '${vname}' --storagectl 'IDE Controller' --type dvddrive --port 1 --device 0 --medium '${isodst}' ";
- end
-
- def self.create_sata
- #command => "${vboxcmd} storagectl '${vname}' --name 'SATA Controller' --add sata",
- #unless => "${vboxcmd} showvminfo '${vname}' | grep 'SATA Controller' ";
- end
-
- def self.suppress
- # command => "${vboxcmd} setextradata global 'GUI/RegistrationData' 'triesLeft=0';
- # ${vboxcmd} setextradata global 'GUI/UpdateDate' '1 d, 2009-09-20';
- # ${vboxcmd} setextradata global 'GUI/SuppressMessages' 'confirmInputCapture,remindAboutAutoCapture,remindAboutMouseIntegrationOff';
-
- end
-
- def self.set_ssh_port
- # exec {
- # "set ssh port":
- # command => "${vboxcmd} modifyvm '${vname}' --natpf1 'guestssh,tcp,,${hostsshport},,${guestsshport}'",
- # unless => "${vboxcmd} showvminfo '${vname}'|grep State|grep running"
- # }
- end
-
- def self.wait_for_http(filename,options => {:port => 7777})
- end
-
- def self.wait_for_ssh
- end
-
-end
-
-Veewee.contract
-
-exit
-
-
-
-class FileServlet < WEBrick::HTTPServlet::AbstractServlet
- def do_GET(request,response)
- response['Content-Type']='text/plain'
- response.status = 200
- displayfile=File.open("/Users/patrick/vagrantbox/files/preseed.cfg",'r')
- content=displayfile.read()
- response.body=content
- sleep 4
- @@s.shutdown
- end
-end
-
-@@s= HTTPServer.new(:Port => 7125)
-@@s.mount("/preseed.cfg", FileServlet)
-trap("INT"){@@s.shutdown}
-@@s.start
-
-
Oops, something went wrong.

0 comments on commit ff2c117

Please sign in to comment.