veewee 0.3.0.alpha8 → 0.3.0.alpha9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/Gemfile +5 -0
  2. data/Rakefile +41 -1
  3. data/bin/veewee +1 -1
  4. data/doc/kvm.md +9 -1
  5. data/doc/vagrant.md +5 -5
  6. data/lib/veewee/command/vagrant/basebox.rb +2 -0
  7. data/lib/veewee/command/vagrant/build.rb +3 -0
  8. data/lib/veewee/command/vagrant/export.rb +10 -0
  9. data/lib/veewee/command/vagrant/screenshot.rb +45 -0
  10. data/lib/veewee/command/virtualbox.rb +13 -0
  11. data/lib/veewee/config.rb +2 -2
  12. data/lib/veewee/provider/core/box/build.rb +29 -16
  13. data/lib/veewee/provider/core/box/exec.rb +4 -4
  14. data/lib/veewee/provider/core/box/floppy.rb +1 -1
  15. data/lib/veewee/provider/core/helper/iso.rb +14 -10
  16. data/lib/veewee/provider/core/helper/ssh.rb +6 -5
  17. data/lib/veewee/provider/core/helper/tcp.rb +5 -3
  18. data/lib/veewee/provider/kvm/box/destroy.rb +1 -1
  19. data/lib/veewee/provider/parallels/box/destroy.rb +1 -2
  20. data/lib/veewee/provider/virtualbox/box.rb +1 -0
  21. data/lib/veewee/provider/virtualbox/box/build.rb +1 -1
  22. data/lib/veewee/provider/virtualbox/box/destroy.rb +1 -3
  23. data/lib/veewee/provider/virtualbox/box/export_vagrant.rb +3 -2
  24. data/lib/veewee/provider/virtualbox/box/helper/console_type.rb +5 -5
  25. data/lib/veewee/provider/virtualbox/box/helper/natinterface.rb +1 -1
  26. data/lib/veewee/provider/virtualbox/box/screenshot.rb +24 -0
  27. data/lib/veewee/provider/virtualbox/box/up.rb +2 -3
  28. data/lib/veewee/provider/vmfusion/box/destroy.rb +1 -2
  29. data/lib/veewee/provider/vmfusion/box/helper/vnc.rb +1 -1
  30. data/lib/veewee/templates.rb +1 -1
  31. data/lib/veewee/version.rb +1 -1
  32. data/templates/CentOS-4.8-i386/definition.rb +1 -1
  33. data/templates/CentOS-5.5-i386-netboot/definition.rb +1 -1
  34. data/templates/CentOS-5.5-x86_64-netboot/definition.rb +1 -1
  35. data/templates/CentOS-5.7-i386-netboot/definition.rb +1 -1
  36. data/templates/CentOS-5.7-i386-netboot/ks.cfg +2 -0
  37. data/templates/CentOS-5.7-x86_64-netboot/definition.rb +1 -1
  38. data/templates/CentOS-5.7-x86_64-netboot/ks.cfg +3 -1
  39. data/templates/CentOS-5.8-i386-netboot/definition.rb +16 -0
  40. data/templates/CentOS-5.8-i386-netboot/ks.cfg +47 -0
  41. data/templates/CentOS-5.8-i386-netboot/postinstall.sh +53 -0
  42. data/templates/CentOS-5.8-i386/definition.rb +16 -0
  43. data/templates/CentOS-5.8-i386/ks.cfg +47 -0
  44. data/templates/CentOS-5.8-i386/postinstall.sh +53 -0
  45. data/templates/CentOS-5.8-x86_64-netboot/definition.rb +16 -0
  46. data/templates/CentOS-5.8-x86_64-netboot/ks.cfg +47 -0
  47. data/templates/CentOS-5.8-x86_64-netboot/postinstall.sh +53 -0
  48. data/templates/CentOS-5.8-x86_64/definition.rb +16 -0
  49. data/templates/CentOS-5.8-x86_64/ks.cfg +47 -0
  50. data/templates/CentOS-5.8-x86_64/postinstall.sh +60 -0
  51. data/templates/Debian-6.0.4-i386-netboot/ruby.sh +1 -1
  52. data/templates/Fedora-16-i386/definition.rb +1 -1
  53. data/templates/Fedora-16-x86_64/definition.rb +1 -1
  54. data/templates/archlinux-x86_64/definition.rb +1 -1
  55. data/templates/ubuntu-11.04-server-amd64/ruby.sh +4 -4
  56. data/templates/ubuntu-11.04-server-i386/postinstall.sh +12 -12
  57. data/templates/ubuntu-12.04-server-amd64-packages/definition.rb +3 -3
  58. data/templates/ubuntu-12.04-server-amd64/definition.rb +3 -3
  59. data/templates/ubuntu-12.04-server-i386/definition.rb +37 -0
  60. data/templates/ubuntu-12.04-server-i386/postinstall.sh +93 -0
  61. data/templates/ubuntu-12.04-server-i386/preseed.cfg +87 -0
  62. data/templates/windows-2008R2-amd64/definition.rb +1 -1
  63. metadata +20 -3
data/Gemfile CHANGED
@@ -1,3 +1,8 @@
1
+ #if RUBY_VERSION =~ /1.9/
2
+ #Encoding.default_external = Encoding::UTF_8
3
+ #Encoding.default_internal = Encoding::UTF_8
4
+ #end
5
+
1
6
  source "http://rubygems.org"
2
7
 
3
8
  #gem "veewee", :path => "."
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ Rake::TestTask.new do |t|
25
25
  end
26
26
 
27
27
  desc 'Verify ISO'
28
- task :iso, [:box_name] do |t,args|
28
+ task :iso, [:template_name] do |t,args|
29
29
  require 'net/http'
30
30
  #if args.to_hash.size!=1
31
31
  #puts "needs one arguments: rake iso [\"yourname\"]"
@@ -63,3 +63,43 @@ task :iso, [:box_name] do |t,args|
63
63
  end
64
64
  end
65
65
  end
66
+
67
+ desc 'Autobuilds all templates and runs validation.'
68
+ task :autotest, [:pattern] do |t,args|
69
+
70
+ # We overrule all timeouts for tcp and ssh
71
+ #ENV['VEEWEE_TIMEOUT']='600'
72
+
73
+ ve=Veewee::Environment.new()
74
+ ve.templates.each do |name,template|
75
+
76
+ # If pattern was given, only take the ones that match the pattern
77
+ unless args[:pattern].nil?
78
+ next unless name.match(args[:pattern])
79
+ end
80
+
81
+ begin
82
+ ve.definitions.define("auto",name, { 'force' => true})
83
+ vd=ve.definitions["auto"]
84
+ box=ve.providers["virtualbox"].get_box("auto")
85
+ puts "AUTO: Building #{name}"
86
+ box.build({"auto" => true,"force" => true, 'nogui' => true })
87
+ puts "AUTO: Validating #{name}"
88
+ box.validate_vagrant
89
+ puts "AUTO: Success #{name}"
90
+ box.destroy
91
+ rescue Exception => ex
92
+ puts "AUTO: Template #{name} failed - #{ex}"
93
+ if box.running?
94
+ begin
95
+ screenshot="screenshot-auto-#{name}.png"
96
+ puts "AUTO: Taking snapshot #{screenshot}"
97
+ box.screenshot(screenshot)
98
+ rescue Veewee::Error => ex
99
+ puts "AUTO: Error taking screenshot"
100
+ end
101
+ end
102
+ end
103
+
104
+ end
105
+ end
data/bin/veewee CHANGED
@@ -18,5 +18,5 @@ begin
18
18
  ::Veewee::CLI.start(ARGV,:env => env)
19
19
 
20
20
  rescue Veewee::Error => e
21
- puts "#{e}"
21
+ env.ui.error "#{e}"
22
22
  end
data/doc/kvm.md CHANGED
@@ -1,2 +1,10 @@
1
- Coming Soon
1
+ NOTE:Virtualbox doesn't like KVM to be enabled
2
2
 
3
+ check with
4
+
5
+ kvm_ok
6
+
7
+ Remove modules:
8
+
9
+ rmmod kvm_intel
10
+ rmmod kvm
data/doc/vagrant.md CHANGED
@@ -2,11 +2,11 @@
2
2
  Let's define a Ubuntu 10.10 server i386 basebox called myunbuntubox
3
3
  this is essentially making a copy based on the templates provided above.
4
4
 
5
- $ veewee vbox basebox define 'myubuntubox' 'ubuntu-10.10-server-i386'
5
+ $ veewee vbox define 'myubuntubox' 'ubuntu-10.10-server-i386'
6
6
  The basebox 'myubuntubox' has been succesfully created from the template ''ubuntu-10.10-server-i386'
7
7
  You can now edit the definition files stored in definitions/myubuntubox
8
8
  or build the box with:
9
- veewee vbox basebox build 'myubuntubox'
9
+ veewee vbox build 'myubuntubox'
10
10
 
11
11
  -> This copies over the templates/ubuntu-10.10-server-i386 to definition/myubuntubox
12
12
 
@@ -47,7 +47,7 @@ If you need to change values in the templates, be sure to run the rake undefine,
47
47
  ## Getting the cdrom file in place
48
48
  Put your isofile inside the 'currentdir'/iso directory or if you don't run
49
49
 
50
- $ veewee vbox basebox build 'myubuntubox'
50
+ $ veewee vbox build 'myubuntubox'
51
51
 
52
52
  - the build assumes your iso files are in 'currentdir'/iso
53
53
  - if it can not find it will suggest to download the iso for you
@@ -55,7 +55,7 @@ Put your isofile inside the 'currentdir'/iso directory or if you don't run
55
55
 
56
56
  ## Build the new box:
57
57
 
58
- $ veewee vbox basebox build 'myubuntubox'
58
+ $ veewee vbox build 'myubuntubox'
59
59
 
60
60
  - This will create a machine + disk according to the definition.rb
61
61
  - Note: :os_type_id = The internal Name Virtualbox uses for that Distribution
@@ -108,7 +108,7 @@ If you don't use rvm, be sure to execute vagrant through bundle exec
108
108
 
109
109
  Start of an existing one
110
110
 
111
- $ veewee vbox basebox define 'mynewos' 'ubuntu...'
111
+ $ veewee vbox define 'mynewos' 'ubuntu...'
112
112
 
113
113
  - Do changes in the currentdir/definitions/mynewos
114
114
  - When it builds ok, move the definition/mynewos to a sensible directory under templates
@@ -12,6 +12,7 @@ require 'veewee/command/vagrant/define'
12
12
  require 'veewee/command/vagrant/undefine'
13
13
  require 'veewee/command/vagrant/validate'
14
14
  require 'veewee/command/vagrant/export'
15
+ require 'veewee/command/vagrant/screenshot'
15
16
 
16
17
 
17
18
  module Veewee
@@ -36,6 +37,7 @@ module Veewee
36
37
  @subcommands.register(:undefine) { Veewee::Command::Vagrant::Undefine }
37
38
  @subcommands.register(:export) { Veewee::Command::Vagrant::Export }
38
39
  @subcommands.register(:validate) { Veewee::Command::Vagrant::Validate }
40
+ @subcommands.register(:screenshot) { Veewee::Command::Vagrant::Screenshot }
39
41
 
40
42
  end
41
43
 
@@ -40,6 +40,9 @@ module Veewee
40
40
  options['postinstall_list'] = e
41
41
  end
42
42
 
43
+ opts.on("--[no-]md5","force to check iso file md5 sum") do |v|
44
+ options['md5check'] = v
45
+ end
43
46
 
44
47
  end
45
48
 
@@ -6,6 +6,8 @@ module Veewee
6
6
  class Export < ::Vagrant::Command::Base
7
7
  def execute
8
8
  options = {}
9
+ options['include'] = []
10
+ options['vagrantfile'] = []
9
11
 
10
12
  opts = OptionParser.new do |opts|
11
13
  opts.banner = "Exports basebox to the vagrant box format"
@@ -20,6 +22,14 @@ module Veewee
20
22
  options['force'] = f
21
23
  end
22
24
 
25
+ opts.on( "--vagrantfile [FILE]", "vagrantfile") do |f|
26
+ options['vagrantfile'] = f
27
+ end
28
+
29
+ opts.on("-i", "--include [FILE]", "include") do |f|
30
+ options['include'] << f
31
+ end
32
+
23
33
  end
24
34
 
25
35
  # Parse the options
@@ -0,0 +1,45 @@
1
+ require 'optparse'
2
+
3
+ module Veewee
4
+ module Command
5
+ module Vagrant
6
+ class Screenshot < ::Vagrant::Command::Base
7
+ def execute
8
+ options = {}
9
+
10
+ opts = OptionParser.new do |opts|
11
+ opts.banner = "Grab a screenshot of a running basebox"
12
+ opts.separator ""
13
+ opts.separator "Usage: vagrant basebox screenshot <boxname> <pngfile>"
14
+
15
+ opts.on("-d", "--debug", "enable debugging") do |d|
16
+ options['debug'] = d
17
+ end
18
+
19
+ opts.on("-f", "--force", "force overwrite") do |f|
20
+ options['force'] = f
21
+ end
22
+
23
+ end
24
+
25
+ # Parse the options
26
+ argv = parse_options(opts)
27
+ return if !argv
28
+ raise ::Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 2
29
+
30
+ begin
31
+ venv=Veewee::Environment.new(options)
32
+ venv.ui=@env.ui
33
+ box_name=argv[0]
34
+ pngfilename=argv[1]
35
+ venv.providers["virtualbox"].get_box(box_name).screenshot(pngfilename)
36
+ rescue Veewee::Error => ex
37
+ venv.ui.error(ex,:prefix => false)
38
+ exit -1
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -126,6 +126,19 @@ module Veewee
126
126
  end
127
127
  end
128
128
 
129
+ desc "screenshot [NAME] [PNGFILENAME]", "Takes a screenshot of the box"
130
+ def screenshot(box_name,pngfilename)
131
+ begin
132
+ venv=Veewee::Environment.new(options)
133
+ venv.ui = ::Veewee::UI::Shell.new(venv, shell)
134
+
135
+ venv.providers["virtualbox"].get_box(box_name).screenshot(pngfilename,options)
136
+ rescue Veewee::Error => ex
137
+ venv.ui.error(ex, :prefix => false)
138
+ exit -1
139
+ end
140
+ end
141
+
129
142
 
130
143
  end
131
144
 
data/lib/veewee/config.rb CHANGED
@@ -48,11 +48,11 @@ module Veewee
48
48
  env.ui.error "Some method got an error in the configfile - Sorry"
49
49
  env.ui.error $!
50
50
  env.ui.error e.message
51
- exit -1
51
+ raise Veewee::Error "Some method got an error in the configfile - Sorry"
52
52
  rescue Error => e
53
53
  env.ui.error "Error processing configfile - Sorry"
54
54
  env.ui.error e.message
55
- exit -1
55
+ raise Veewee::Error "Error processing configfile - Sorry"
56
56
  end
57
57
  return self
58
58
  end
@@ -75,8 +75,11 @@ module Veewee
75
75
  end
76
76
 
77
77
  self.transfer_buildinfo(options)
78
- self.handle_postinstall(options)
79
78
 
79
+ # Filtering post install files based upon --postinstall-include and --postinstall--exclude
80
+ definition.postinstall_files=filter_postinstall_files(options)
81
+
82
+ self.handle_postinstall(options)
80
83
 
81
84
  ui.success "The box #{name} was built succesfully!"
82
85
  ui.info "You can now login to the box with:"
@@ -158,8 +161,6 @@ module Veewee
158
161
  # It requires a definition to find all the necessary information
159
162
  def handle_kickstart(options)
160
163
 
161
- # Filtering post install files based upon --postinstall-include and --postinstall--exclude
162
- definition.postinstall_files=filter_postinstall_files(options)
163
164
  # Handling the kickstart by web
164
165
  kickstartfiles=definition.kickstart_file
165
166
 
@@ -191,32 +192,44 @@ module Veewee
191
192
  # This function handles all the post-install scripts
192
193
  # It requires a box(to login to) and a definition(listing the postinstall files)
193
194
  def handle_postinstall(options)
194
- is_pre_postinstall_file = !definition.pre_postinstall_file.nil? && !definition.pre_postinstall_file.length != 0
195
- transfered = false
195
+
196
+ # Transfer all postinstall files
196
197
  definition.postinstall_files.each do |postinstall_file|
197
198
  # Filenames of postinstall_files are relative to their definition
198
199
  filename=File.join(definition.path,postinstall_file)
199
- unless File.basename(postinstall_file)=~/^_/
200
- self.scp(filename,File.basename(filename))
201
- self.exec("chmod +x \"#{File.basename(filename)}\"")
202
- if is_pre_postinstall_file
200
+ self.scp(filename,File.basename(filename))
201
+ self.exec("chmod +x \"#{File.basename(filename)}\"")
202
+ end
203
+
204
+ # Prepare a pre_poinstall file if needed (not nil , or not empty)
205
+ unless definition.pre_postinstall_file.to_s.empty?
206
+ pre_filename=File.join(definition.path, definition.pre_postinstall_file)
207
+ self.scp(pre_filename,File.basename(pre_filename))
208
+ self.exec("chmod +x \"#{File.basename(pre_filename)}\"")
209
+ # Inject the call to the real script by executing the first argument (it will be the postinstall script file name to be executed)
210
+ self.exec("execute=\"\\n# We must execute the script passed as the first argument\\n\\$1\" && printf \"%b\\n\" \"$execute\" >> #{File.basename(pre_filename)}")
211
+ end
212
+
213
+ # Now iterate over the postinstall files
214
+ definition.postinstall_files.each do |postinstall_file|
215
+ # Filenames of postinstall_files are relative to their definition
216
+ filename=File.join(definition.path,postinstall_file)
217
+
218
+ unless File.basename(postinstall_file).start_with?("_")
219
+
220
+ unless definition.pre_postinstall_file.to_s.empty?
203
221
  # Filename of pre_postinstall_file are relative to their definition
204
222
  pre_filename=File.join(definition.path, definition.pre_postinstall_file)
205
223
  # Upload the pre postinstall script if not already transfered
206
- if !transfered
207
- self.scp(pre_filename,File.basename(pre_filename))
208
- transfered = true
209
- self.exec("chmod +x \"#{File.basename(pre_filename)}\"")
210
- # Inject the call to the real script by executing the first argument (it will be the postinstall script file name to be executed)
211
- self.exec("execute=\"\\n# We must execute the script passed as the first argument\\n\\$1\" && printf \"%b\\n\" \"$execute\" >> #{File.basename(pre_filename)}")
212
- end
213
224
  command = "./" + File.basename(pre_filename)
214
225
  command = sudo(command) + " ./"+File.basename(filename)
215
226
  else
216
227
  command = "./"+File.basename(filename)
217
228
  command = sudo(command)
218
229
  end
230
+
219
231
  self.exec(command)
232
+
220
233
  else
221
234
  env.logger.info "Skipping postinstallfile #{postinstall_file}"
222
235
  end
@@ -18,13 +18,13 @@ module Veewee
18
18
  result=self.ssh_execute(self.ip_address,command,new_options)
19
19
  return result
20
20
  rescue RuntimeError => ex
21
- ui.error("Error executing command #{command} : #{ex}",:prefix => false)
22
- raise Veewee::SshError, ex
21
+ error= "Error executing command #{command} : #{ex}"
22
+ error+="\n"+ex
23
+ raise Veewee::SshError, error
23
24
  end
24
25
  end
25
26
  rescue Net::SSH::AuthenticationFailed => ex
26
- ui.error("Authentication failure",:prefix => false)
27
- raise Veewee::SshError, ex
27
+ raise Veewee::SshError, "Authentication failure\n"+ex
28
28
  end
29
29
 
30
30
  end
@@ -20,7 +20,7 @@ module Veewee
20
20
  env.logger.info "Removing previous floppy file"
21
21
  FileUtils.rm(floppy_file)
22
22
  end
23
- command="java -jar #{javacode_dir}/dir2floppy.jar '#{temp_dir}' '#{floppy_file}'"
23
+ command="java -jar #{javacode_dir}/dir2floppy.jar \"#{temp_dir}\" \"#{floppy_file}\""
24
24
  shell_exec("#{command}")
25
25
  end
26
26
  end
@@ -37,7 +37,7 @@ module Veewee
37
37
  :progress_proc => lambda {|s|
38
38
  pbar.set s if pbar
39
39
  }) { |src|
40
- # We assume large 10K files, so this is tempfile object
40
+ # We assume large 10K files, so this is tempfile object
41
41
  env.logger.info "#{src.class}"
42
42
  ui.info "Moving #{src.path} to #{localfile}"
43
43
  # Force the close of the src stream to release handle before moving
@@ -65,6 +65,17 @@ module Veewee
65
65
  return checksum.hexdigest
66
66
  end
67
67
 
68
+ def verify_md5sum(full_path)
69
+ filename = File.basename(full_path)
70
+ ui.info "Verifying md5 checksum : #{self.iso_md5}"
71
+ file_md5=hashsum(full_path)
72
+
73
+ unless file_md5==self.iso_md5
74
+ ui.error "The MD5 checksums for file #{filename } do not match: "
75
+ ui.error "- #{file_md5} (current) vs #{self.iso_md5} (specified)"
76
+ raise Veewee::Error, "The MD5 checksums for file #{filename } do not match: \n"+ "- #{file_md5} (current) vs #{self.iso_md5} (specified)"
77
+ end
78
+ end
68
79
 
69
80
  def verify_iso(options)
70
81
  filename=self.iso_file
@@ -123,19 +134,12 @@ module Veewee
123
134
  raise Veewee::Error, "The provided iso #{full_path} is not readable"
124
135
  end
125
136
 
126
- ui.info "Verifying md5 checksum : #{self.iso_md5}"
127
- file_md5=hashsum(full_path)
128
-
129
- unless file_md5==self.iso_md5
130
- ui.error "The MD5 checksums for file #{filename } do not match: "
131
- ui.error "- #{file_md5} (current) vs #{self.iso_md5} (specified)"
132
- raise Veewee::Error, "The MD5 checksums for file #{filename } do not match: \n"+ "- #{file_md5} (current) vs #{self.iso_md5} (specified)"
133
- end
134
-
135
137
  end
136
138
 
137
139
  end
138
140
 
141
+ verify_md5sum(full_path) if options["md5check"] && !self.iso_md5.nil?
142
+
139
143
  end
140
144
  end #Module
141
145
 
@@ -25,16 +25,18 @@ module Veewee
25
25
  defaults={ :port => '22', :timeout => 20000 }
26
26
 
27
27
  options=defaults.merge(options)
28
+ timeout = options[:timeout]
29
+ timeout=ENV['VEEWEE_TIMEOUT'].to_i unless ENV['VEEWEE_TIMEOUT'].nil?
28
30
 
29
- ui.info "Waiting for ssh login on #{ip} with user #{options[:user]} to sshd on port => #{options[:port]} to work, timeout=#{options[:timeout]} sec"
31
+ ui.info "Waiting for ssh login on #{ip} with user #{options[:user]} to sshd on port => #{options[:port]} to work, timeout=#{timeout} sec"
30
32
 
31
33
  begin
32
- Timeout::timeout(options[:timeout]) do
34
+ Timeout::timeout(timeout) do
33
35
  connected=false
34
36
  while !connected do
35
37
  begin
36
38
  env.ui.info ".",{:new_line => false , :prefix => false}
37
- Net::SSH.start(ip, options[:user], { :port => options[:port] , :password => options[:password], :paranoid => false , :timeout => options[:timeout] }) do |ssh|
39
+ Net::SSH.start(ip, options[:user], { :port => options[:port] , :password => options[:password], :paranoid => false , :timeout => timeout }) do |ssh|
38
40
 
39
41
  ui.info "\n", {:prefix => false}
40
42
  block.call(ip);
@@ -46,8 +48,7 @@ module Veewee
46
48
  end
47
49
  end
48
50
  rescue Timeout::Error
49
- ui.error "Ssh timeout #{options[:timeout]} sec has been reached."
50
- exit -1
51
+ raise Veewee::Error, "Ssh timeout #{timeout} sec has been reached."
51
52
  end
52
53
  ui.info ""
53
54
  return false