gepetto 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,13 +7,14 @@ app_generators/gepetto/gepetto_generator.rb
7
7
  app_generators/gepetto/templates/Rakefile
8
8
  app_generators/gepetto/templates/config/fileserver.conf
9
9
  app_generators/gepetto/templates/config/puppet.conf
10
+ app_generators/gepetto/templates/config/qemu-ifup
10
11
  app_generators/gepetto/templates/manifests/classes/empty.pp
11
12
  app_generators/gepetto/templates/manifests/defaults.pp
12
13
  app_generators/gepetto/templates/manifests/nodes.pp
14
+ app_generators/gepetto/templates/manifests/sandbox-sample.pp
15
+ app_generators/gepetto/templates/manifests/sandbox.pp
13
16
  app_generators/gepetto/templates/manifests/site.pp
14
17
  app_generators/gepetto/templates/manifests/templates.pp
15
- app_generators/gepetto/templates/manifests/sandbox.pp
16
- app_generators/gepetto/templates/manifests/sandbox-sample.pp
17
18
  app_generators/gepetto/templates/script/module
18
19
  app_generators/gepetto/templates/script/puppetca
19
20
  app_generators/gepetto/templates/script/puppetmasterd
@@ -29,6 +29,7 @@ class GepettoGenerator < RubiGen::Base
29
29
  m.template_copy_each %w( empty.pp ), 'manifests/classes'
30
30
 
31
31
  m.template_copy_each %w( puppet.conf fileserver.conf ), 'config'
32
+ m.template_copy_each %w( qemu-ifup ), 'config', script_options
32
33
 
33
34
  m.template_copy_each %w( puppetmasterd puppetca puppetrun module ), 'script', script_options
34
35
 
@@ -0,0 +1,11 @@
1
+ #!/bin/sh -x
2
+
3
+ if [ "$USER" != "root" -o "$1" != "sudo" ]; then
4
+ exec sudo -p "Password for $0:" $0 sudo $1
5
+ fi
6
+
7
+ [ "$1" = "sudo" ] && shift
8
+
9
+ /sbin/ifconfig $1 172.20.0.1
10
+ iptables -t nat -A POSTROUTING -s 172.20.0.1/24 -o eth0 -j MASQUERADE
11
+ sysctl -w net.ipv4.ip_forward=1
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{gepetto}
5
- s.version = "0.0.10"
5
+ s.version = "0.0.11"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Alban Peignier"]
9
- s.date = %q{2010-02-01}
9
+ s.date = %q{2010-02-05}
10
10
  s.default_executable = %q{gepetto}
11
11
  s.description = %q{A helper suite for Puppet projects to create, manage and help daily development
12
12
 
@@ -14,7 +14,7 @@ More information about Puppet: http://reductivelabs.com/trac/puppet/}
14
14
  s.email = ["alban.peignier@free.fr"]
15
15
  s.executables = ["gepetto"]
16
16
  s.extra_rdoc_files = ["History.txt", "Manifest.txt"]
17
- s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "app_generators/gepetto/USAGE", "app_generators/gepetto/gepetto_generator.rb", "app_generators/gepetto/templates/Rakefile", "app_generators/gepetto/templates/config/fileserver.conf", "app_generators/gepetto/templates/config/puppet.conf", "app_generators/gepetto/templates/manifests/classes/empty.pp", "app_generators/gepetto/templates/manifests/defaults.pp", "app_generators/gepetto/templates/manifests/nodes.pp", "app_generators/gepetto/templates/manifests/site.pp", "app_generators/gepetto/templates/manifests/templates.pp", "app_generators/gepetto/templates/manifests/sandbox.pp", "app_generators/gepetto/templates/manifests/sandbox-sample.pp", "app_generators/gepetto/templates/script/module", "app_generators/gepetto/templates/script/puppetca", "app_generators/gepetto/templates/script/puppetmasterd", "app_generators/gepetto/templates/script/puppetrun", "bin/gepetto", "gepetto.gemspec", "lib/gepetto.rb", "lib/gepetto/tasks.rb", "puppet_generators/module/USAGE", "puppet_generators/module/module_generator.rb", "puppet_generators/module/templates/README", "puppet_generators/module/templates/manifests/init.pp", "script/destroy", "script/generate", "tasks/host.pp", "tasks/log.rake", "tasks/puppet.rake", "tasks/sandbox.pp", "tasks/sandbox.rake", "tasks/tmp.rake", "tasks/utils.rake"]
17
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "app_generators/gepetto/USAGE", "app_generators/gepetto/gepetto_generator.rb", "app_generators/gepetto/templates/Rakefile", "app_generators/gepetto/templates/config/fileserver.conf", "app_generators/gepetto/templates/config/puppet.conf", "app_generators/gepetto/templates/config/qemu-ifup", "app_generators/gepetto/templates/manifests/classes/empty.pp", "app_generators/gepetto/templates/manifests/defaults.pp", "app_generators/gepetto/templates/manifests/nodes.pp", "app_generators/gepetto/templates/manifests/sandbox-sample.pp", "app_generators/gepetto/templates/manifests/sandbox.pp", "app_generators/gepetto/templates/manifests/site.pp", "app_generators/gepetto/templates/manifests/templates.pp", "app_generators/gepetto/templates/script/module", "app_generators/gepetto/templates/script/puppetca", "app_generators/gepetto/templates/script/puppetmasterd", "app_generators/gepetto/templates/script/puppetrun", "bin/gepetto", "gepetto.gemspec", "lib/gepetto.rb", "lib/gepetto/tasks.rb", "puppet_generators/module/USAGE", "puppet_generators/module/module_generator.rb", "puppet_generators/module/templates/README", "puppet_generators/module/templates/manifests/init.pp", "script/destroy", "script/generate", "tasks/host.pp", "tasks/log.rake", "tasks/puppet.rake", "tasks/sandbox.pp", "tasks/sandbox.rake", "tasks/tmp.rake", "tasks/utils.rake"]
18
18
  s.homepage = %q{http://github.com/albanpeignier/gepetto/}
19
19
  s.rdoc_options = ["--main", "README.rdoc"]
20
20
  s.require_paths = ["lib"]
@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Gepetto
5
- VERSION = '0.0.10'
5
+ VERSION = '0.0.11'
6
6
  end
@@ -58,23 +58,10 @@ file { "/dev/net/tun":
58
58
  mode => 666
59
59
  }
60
60
 
61
- # provide a basic qemu-ifup
61
+ package { debootstrap: }
62
62
 
63
- file { "/etc/qemu-ifup":
64
- mode => 755,
65
- content => '#!/bin/sh -x
66
-
67
- if [ "$USER" != "root" -o "$1" != "sudo" ]; then
68
- exec sudo -p "Password for $0:" $0 sudo $1
69
- fi
70
-
71
- [ "$1" = "sudo" ] && shift
72
-
73
- /sbin/ifconfig $1 172.20.0.1
74
- iptables -t nat -A POSTROUTING -s 172.20.0.1/24 -o eth0 -j MASQUERADE
75
- sysctl -w net.ipv4.ip_forward=1
76
- ',
77
- require => Package[qemu]
63
+ if $operatingsystem == Debian {
64
+ package { [syslinux-common, extlinux]: }
65
+ } else {
66
+ package { syslinux: }
78
67
  }
79
-
80
- package { [debootstrap, grub]: }
@@ -24,10 +24,14 @@ exec { "inittab-no-tty-gettys":
24
24
  onlyif => "grep 'getty 38400 tty[23456]' /etc/inittab"
25
25
  }
26
26
 
27
- file { "/etc/hostname":
27
+ file { ["/etc/hostname", "/etc/mailname"]:
28
28
  content => "sandbox"
29
29
  }
30
30
 
31
+ file { "/etc/default/locale":
32
+ content => "LANG=en_US.UTF-8"
33
+ }
34
+
31
35
  # an host object doesn't find a provider
32
36
  file { "/etc/hosts":
33
37
  content => "127.0.0.1 localhost
@@ -88,6 +92,7 @@ pluginsync=false
88
92
  color=false
89
93
 
90
94
  [puppetd]
95
+ certname=sandbox
91
96
  report=true
92
97
  # run puppetd .. every day
93
98
  runinterval = 86400
@@ -95,7 +95,7 @@ class Sandbox < Rake::TaskLib
95
95
  task :image do
96
96
  sh "qemu-img create -f raw #{disk_image} #{disk_size}"
97
97
  # create the partition table
98
- sh "echo '63,' | /sbin/sfdisk --no-reread -uS -H16 -S63 #{disk_image}"
98
+ sh "echo '63,,L,*' | /sbin/sfdisk --no-reread -uS -H16 -S63 #{disk_image}"
99
99
  end
100
100
 
101
101
  task :fs do
@@ -104,9 +104,10 @@ class Sandbox < Rake::TaskLib
104
104
  sudo "losetup -o #{fs_offset} /dev/loop0 #{disk_image}"
105
105
 
106
106
  # because '/sbin/sfdisk -s /dev/loop0' returns a wrong value :
107
- extract_fs_block_size = "/sbin/sfdisk -l #{disk_image} 2> /dev/null | awk '/img1/ { gsub(\"\\+\", \"\", $5); print $5 }'"
107
+ linux_partition_info = `/sbin/sfdisk -l #{disk_image}`.scan(%r{#{disk_image}.*Linux}).first
108
+ extract_fs_block_size = linux_partition_info.split[5].to_i
108
109
 
109
- sudo "/sbin/mke2fs -jqF /dev/loop0 `#{extract_fs_block_size}`"
110
+ sudo "/sbin/mke2fs -jqF /dev/loop0 #{extract_fs_block_size}"
110
111
  ensure
111
112
  sudo "losetup -d /dev/loop0"
112
113
  end
@@ -137,35 +138,39 @@ class Sandbox < Rake::TaskLib
137
138
  end
138
139
  end
139
140
 
140
- task :grub do
141
+ task :syslinux do
142
+ extlinux_dir = "#{mount_point}/boot/extlinux"
143
+
141
144
  mount do
142
- chroot_sh "DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes grub"
145
+ sudo "mkdir -p #{extlinux_dir}" unless File.exists?(extlinux_dir)
146
+ Tempfile.open('extlinux_conf') do |f|
147
+ f.puts "DEFAULT linux"
148
+ f.puts "LABEL linux"
149
+ f.puts "SAY Now booting sandbox from syslinux ..."
150
+ f.puts "KERNEL /vmlinuz"
151
+ f.puts "APPEND ro root=/dev/hda1 initrd=/initrd.img"
152
+ f.close
153
+ sudo "cp #{f.path} #{extlinux_dir}/extlinux.conf"
154
+ end
143
155
 
144
- grub_dir = "#{mount_point}/boot/grub"
145
- chroot_sh "mkdir /boot/grub" unless File.exists?(grub_dir)
156
+ sudo "extlinux --install -H16 -S63 #{mount_point}/boot/extlinux"
157
+ end
158
+ sudo "dd if=/usr/lib/syslinux/mbr.bin of=#{disk_image} conv=notrunc"
159
+ end
146
160
 
147
- stage_files = Dir["#{mount_point}/usr/lib/grub/**/stage?", "#{mount_point}/usr/lib/grub/**/e2fs_stage1_5"]
148
- sudo "cp #{stage_files.join(' ')} #{grub_dir}"
161
+ task :ssh do
162
+ ssh_pubkey = Dir["#{ENV['HOME']}/.ssh/id_*pub"].first
163
+ ssh_dir = "#{mount_point}/root/.ssh"
149
164
 
150
- Tempfile.open('menu_lst') do |f|
151
- f.write(['default 0',
152
- 'timeout 0',
153
- 'title Linux',
154
- 'root (hd0,0)',
155
- 'kernel /vmlinuz root=/dev/hda1 ro',
156
- 'initrd /initrd.img'].join("\n"))
157
- f.close
158
- sudo "cp #{f.path} #{grub_dir}/menu.lst"
159
- end
165
+ mount do
166
+ sudo "mkdir #{ssh_dir}"
167
+ sudo "cp #{ssh_pubkey} #{ssh_dir}/authorized_keys"
160
168
  end
169
+ end
161
170
 
162
- Tempfile.open('grub_input') do |f|
163
- f.write(["device (hd0) #{disk_image}",
164
- "root (hd0,0)",
165
- "setup (hd0)",
166
- "quit"].join("\n"))
167
- f.close
168
- sudo "grub --device-map=/dev/null < #{f.path}"
171
+ task :update do
172
+ mount do
173
+ chroot_sh "apt-get update"
169
174
  end
170
175
  end
171
176
 
@@ -197,7 +202,7 @@ class Sandbox < Rake::TaskLib
197
202
  end
198
203
 
199
204
  desc "Create a fresh image for sandbox"
200
- task :create => [ 'clean', 'create:image', 'create:fs', 'create:system', 'create:kernel', 'create:grub', 'create:config', 'create:snapshot' ]
205
+ task :create => [ 'clean', 'create:image', 'create:fs', 'create:system', 'create:update', 'create:kernel', 'create:syslinux', 'create:config', 'create:ssh', 'create:snapshot' ]
201
206
 
202
207
  desc "Destroy sandbox images"
203
208
  task :destroy => 'clean' do
@@ -239,7 +244,7 @@ class Sandbox < Rake::TaskLib
239
244
  task :clean => 'puppet:clean' do
240
245
  # clean known_hosts
241
246
  known_hosts_file="#{ENV['HOME']}/.ssh/known_hosts"
242
- sh "sed -i '/#{hostname},#{ip_address}/ d' #{known_hosts_file}" if File.exists?(known_hosts_file)
247
+ sh "sed -i -e '/#{hostname} / d' -e '/#{ip_address} / d' #{known_hosts_file}" if File.exists?(known_hosts_file)
243
248
  end
244
249
 
245
250
  task :status do
@@ -274,8 +279,9 @@ class Sandbox < Rake::TaskLib
274
279
  :snapshot => ENV['SNAPSHOT'],
275
280
  :hda => disk_image,
276
281
  :nographic => false,
282
+ :"enable-kvm" => true,
277
283
  :m => memory_size,
278
- :net => ["nic", "tap,ifname=#{tap_device}"]
284
+ :net => ["nic", "tap,ifname=#{tap_device},script=config/qemu-ifup"]
279
285
  }.update(options)
280
286
 
281
287
  if options[:daemonize]
@@ -394,8 +400,9 @@ class DebianBoostraper
394
400
  def initialize(&block)
395
401
  default_attributes
396
402
 
397
- @include = %w{puppet ssh udev resolvconf}
398
- @exclude = %w{syslinux at exim mailx libstdc++2.10-glibc2.2 mbr setserial fdutils info ipchains iptables lilo pcmcia-cs ppp pppoe pppoeconf pppconfig telnet exim4 exim4-base exim4-config exim4-daemon-light pciutils modconf tasksel console-common console-tools console-data base-config man-db manpages}
403
+ # extlinux is provided by syslinux in lenny
404
+ @include = %w{puppet ssh udev resolvconf syslinux debian-archive-keyring}
405
+ @exclude = %w{at exim mailx libstdc++2.10-glibc2.2 mbr setserial fdutils info ipchains iptables lilo pcmcia-cs ppp pppoe pppoeconf pppconfig telnet exim4 exim4-base exim4-config exim4-daemon-light pciutils modconf tasksel console-common console-tools console-data base-config man-db manpages}
399
406
 
400
407
  yield self if block_given?
401
408
  end
@@ -404,6 +411,7 @@ class DebianBoostraper
404
411
  @version = 'lenny'
405
412
  @mirror = 'http://ftp.debian.org/debian'
406
413
  @architecture = Sandbox.default_architecture
414
+ @components = %w{main contrib non-free}
407
415
  end
408
416
 
409
417
  def bootstrap(root)
@@ -415,7 +423,8 @@ class DebianBoostraper
415
423
  {
416
424
  :arch => architecture,
417
425
  :exclude => @exclude,
418
- :include => @include
426
+ :include => @include,
427
+ :components => @components
419
428
  }
420
429
  end
421
430
 
@@ -16,7 +16,11 @@ namespace :tmp do
16
16
  namespace name do
17
17
  desc "Clears all files in #{tmp_directory}"
18
18
  task :clear do
19
- FileUtils.rm(Dir["#{tmp_directory}/[^.]*"])
19
+ files = Dir["#{tmp_directory}/**/*"].reject { |f| File.directory?(f) }
20
+ unless files.empty?
21
+ puts "* remove #{files.size} files in #{tmp_directory}"
22
+ FileUtils.rm files
23
+ end
20
24
  end
21
25
  end
22
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gepetto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alban Peignier
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-01 00:00:00 +01:00
12
+ date: 2010-02-05 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -85,13 +85,14 @@ files:
85
85
  - app_generators/gepetto/templates/Rakefile
86
86
  - app_generators/gepetto/templates/config/fileserver.conf
87
87
  - app_generators/gepetto/templates/config/puppet.conf
88
+ - app_generators/gepetto/templates/config/qemu-ifup
88
89
  - app_generators/gepetto/templates/manifests/classes/empty.pp
89
90
  - app_generators/gepetto/templates/manifests/defaults.pp
90
91
  - app_generators/gepetto/templates/manifests/nodes.pp
92
+ - app_generators/gepetto/templates/manifests/sandbox-sample.pp
93
+ - app_generators/gepetto/templates/manifests/sandbox.pp
91
94
  - app_generators/gepetto/templates/manifests/site.pp
92
95
  - app_generators/gepetto/templates/manifests/templates.pp
93
- - app_generators/gepetto/templates/manifests/sandbox.pp
94
- - app_generators/gepetto/templates/manifests/sandbox-sample.pp
95
96
  - app_generators/gepetto/templates/script/module
96
97
  - app_generators/gepetto/templates/script/puppetca
97
98
  - app_generators/gepetto/templates/script/puppetmasterd