Merge lp:~zulcss/vmbuilder/vmbuilder-ec2-rewrite into lp:vmbuilder/trunk

Proposed by Chuck Short
Status: Rejected
Rejected by: Soren Hansen
Proposed branch: lp:~zulcss/vmbuilder/vmbuilder-ec2-rewrite
Merge into: lp:vmbuilder/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~zulcss/vmbuilder/vmbuilder-ec2-rewrite
Reviewer Review Type Date Requested Status
Soren Hansen Needs Fixing
Review via email: mp+6536@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Chuck Short (zulcss) wrote :

New ec2 crack with suggested changes.

Revision history for this message
Soren Hansen (soren) wrote :
Download full text (9.1 KiB)

On Wed, May 13, 2009 at 05:35:14PM -0000, Chuck Short wrote:
> Chuck Short has proposed merging lp:~zulcss/vmbuilder/vmbuilder-ec2-rewrite into lp:vmbuilder.
>
> Requested reviews:
> Soren Hansen (soren)
>
> New ec2 crack with suggested changes.
> --
> https://code.launchpad.net/~zulcss/vmbuilder/vmbuilder-ec2-rewrite/+merge/6536
> You are requested to review the proposed merge of lp:~zulcss/vmbuilder/vmbuilder-ec2-rewrite into lp:vmbuilder.

> === modified file 'VMBuilder/plugins/ec2/__init__.py'
> --- VMBuilder/plugins/ec2/__init__.py 2009-05-04 08:32:46 +0000
> +++ VMBuilder/plugins/ec2/__init__.py 2009-05-13 15:20:12 +0000
> @@ -17,8 +17,9 @@
> # You should have received a copy of the GNU General Public License
> # along with this program. If not, see <http://www.gnu.org/licenses/>.
> #
> -from VMBuilder import register_plugin, Plugin, VMBuilderUserError
> +from VMBuilder import register_plugin, Plugin, VMBuilderUserError, VMBuilderException
> from VMBuilder.util import run_cmd
> +import VMBuilder
> import logging
> import os
>
> @@ -37,12 +38,23 @@
> group.add_option('--ec2-secret-key', metavar='SECRET_ID', help='AWS secret access key.')
> group.add_option('--ec2-kernel','--ec2-aki', metavar='AKI', help='EC2 AKI (kernel) to use.')
> group.add_option('--ec2-ramdisk','--ec2-ari', metavar='ARI', help='EC2 ARI (ramdisk) to use.')
> + group.add_option('--ec2-version',metavar='EC2_VER', help='Specifity the EC2 image version.')
> + group.add_option('--ec2-landscape',action='store_true', help='Install landscape client support')
> self.vm.register_setting_group(group)
>
> def preflight_check(self):
> if not self.vm.ec2:
> return True
>
> + try:
> + run_cmd('ec2-ami-tools-version')
> + except VMBuilderException, e:
> + raise VMBuilderUserError('You need to have the Amazon EC2 AMI tools installed')
> +

This part is fine.

> + modname = 'VMBuilder.plugins.ubuntu.%s' % (self.vm.suite, )
> + mod = __import__(modname, fromlist=[self.vm.suite])
> + self.suite = getattr(mod, self.vm.suite.capitalize())(self.vm)
> +

This part isn't. Ideally, the EC2 plugin shouldn't know which distro it's
deploying. I realise this is going to be difficult at this point (given the
landscape integration and all that), but there's absolutely no reason to have
the EC2 plugin load the suite module from the Ubuntu plugin.

As I said when we discussed this: Split out that stuff from the Ubuntu plugin's
preflight_check, and put it into a function by itself, which can be called
whenever something needs the suite. For instance, you can replace each call in
the Ubuntu plugin to self.suite to a call to self.suite() which will take care
of the initialisation. At any rate, this does not belong in the EC2 plugin.

> + 'screen-profiles']

I didn't answer my question about whether screen-profiles overrides the screen
command by default?

> - self.vm.ppa += ['ubuntu-ec2']
> + self.vm.ppa += ['ubuntu--on-ec2']

Two dashes? Really?

>
> def post_install(self):
> if not self.vm....

Read more...

review: Needs Fixing

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'VMBuilder/plugins/ec2/__init__.py'
2--- VMBuilder/plugins/ec2/__init__.py 2009-05-04 08:32:46 +0000
3+++ VMBuilder/plugins/ec2/__init__.py 2009-05-13 15:20:12 +0000
4@@ -17,8 +17,9 @@
5 # You should have received a copy of the GNU General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7 #
8-from VMBuilder import register_plugin, Plugin, VMBuilderUserError
9+from VMBuilder import register_plugin, Plugin, VMBuilderUserError, VMBuilderException
10 from VMBuilder.util import run_cmd
11+import VMBuilder
12 import logging
13 import os
14
15@@ -37,12 +38,23 @@
16 group.add_option('--ec2-secret-key', metavar='SECRET_ID', help='AWS secret access key.')
17 group.add_option('--ec2-kernel','--ec2-aki', metavar='AKI', help='EC2 AKI (kernel) to use.')
18 group.add_option('--ec2-ramdisk','--ec2-ari', metavar='ARI', help='EC2 ARI (ramdisk) to use.')
19+ group.add_option('--ec2-version',metavar='EC2_VER', help='Specifity the EC2 image version.')
20+ group.add_option('--ec2-landscape',action='store_true', help='Install landscape client support')
21 self.vm.register_setting_group(group)
22
23 def preflight_check(self):
24 if not self.vm.ec2:
25 return True
26
27+ try:
28+ run_cmd('ec2-ami-tools-version')
29+ except VMBuilderException, e:
30+ raise VMBuilderUserError('You need to have the Amazon EC2 AMI tools installed')
31+
32+ modname = 'VMBuilder.plugins.ubuntu.%s' % (self.vm.suite, )
33+ mod = __import__(modname, fromlist=[self.vm.suite])
34+ self.suite = getattr(mod, self.vm.suite.capitalize())(self.vm)
35+
36 if not self.vm.hypervisor.name == 'Xen':
37 raise VMBuilderUserError('When building for EC2 you must use the xen hypervisor.')
38
39@@ -66,17 +78,13 @@
40
41 if not self.vm.ec2_kernel:
42 logging.debug('No ec2-aki choosen setting to default. Use --ec2-kernel to change this')
43- if self.vm.arch == 'amd64':
44- self.vm.ec2_kernel = 'aki-d314f0ba'
45- else:
46- self.vm.ec2_kernel = 'aki-af14f0c6'
47+ self.vm.ec2_kernel = self.suite.ec2_kernel_info[self.vm.arch]
48+ logging.debug('%s - to be used for AKI.' %(self.vm.ec2_kernel))
49
50 if not self.vm.ec2_ramdisk:
51 logging.debug('No ec2-ari choosen setting to default. Use --ec2-ramdisk to change this.')
52- if self.vm.arch == 'amd64':
53- self.vm.ec2_ramdisk = 'ari-d014f0b9'
54- else:
55- self.vm.ec2_ramdisk = 'ari-ac14f0c5'
56+ self.vm.ec2_ramdisk = self.suite.ec2_ramdisk_info[self.vm.arch]
57+ logging.debug('%s - to be used for ARI.' %(self.vm.ec2_ramdisk))
58
59 if not self.vm.ec2_bucket:
60 raise VMBuilderUserError('When building for EC2 you must provide an S3 bucket to hold the AMI')
61@@ -86,30 +94,52 @@
62
63 if not self.vm.ec2_secret_key:
64 raise VMBuilderUserError('When building for EC2 you must provide your AWS secret access key.')
65+ if not self.vm.ec2_version:
66+ raise VMBuilderUserError('When building for EC2 you must provide version info.')
67
68
69 if not self.vm.addpkg:
70 self.vm.addpkg = []
71
72- self.vm.addpkg += ['openssh-server']
73- self.vm.addpkg += ['ec2-init']
74- self.vm.addpkg += ['openssh-server']
75- self.vm.addpkg += ['ec2-modules']
76- self.vm.addpkg += ['server^']
77- self.vm.addpkg += ['standard^']
78+ self.vm.addpkg += ['ec2-init',
79+ 'openssh-server',
80+ 'ec2-modules',
81+ 'standard^',
82+ 'ec2-ami-tools',
83+ 'update-motd',
84+ 'screen',
85+ 'screen-profiles']
86+
87+ if self.vm.ec2_landscape:
88+ logging.info('Installing landscape support')
89+ self.vm.addpkg += ['landscape-common','landscape-client']
90
91 if not self.vm.ppa:
92 self.vm.ppa = []
93
94- self.vm.ppa += ['ubuntu-ec2']
95+ self.vm.ppa += ['ubuntu--on-ec2']
96
97 def post_install(self):
98 if not self.vm.ec2:
99 return
100
101 logging.info("Running ec2 postinstall")
102- self.install_from_template('/etc/event.d/xvc0', 'upstart')
103- self.run_in_target('passwd', '-l', self.vm.user)
104+ self.install_from_template('/etc/ec2_version', 'ec2_version', { 'version' : self.vm.ec2_version } )
105+ self.install_from_template('/etc/ssh/sshd_config', 'sshd_config')
106+ self.install_from_template('/etc/sudoers', 'sudoers')
107+
108+ if self.vm.suite == 'hardy':
109+ self.install_from_template('/etc/update-motd.d/51_update-motd', '51_update-motd-hardy')
110+ else:
111+ self.install_from_template('/etc/update-motd.d/51_update-motd', '51_update-motd')
112+ self.run_in_target('chmod', '755', '/etc/update-motd.d/51_update-motd')
113+
114+ if self.vm.ec2_landscape:
115+ self.install_from_template('/etc/default/landscape-client', 'landscape_client')
116+
117+ self.suite.install_ec2()
118+ self.run_in_target('update-rc.d', '-f', 'hwclock.sh', 'remove')
119+ self.run_in_target('chpasswd', '-e', stdin='%s!\n' (self.vm.user))
120
121 def deploy(self):
122 if not self.vm.ec2:
123
124=== added file 'VMBuilder/plugins/ec2/templates/51_update-motd-hardy.tmpl'
125--- VMBuilder/plugins/ec2/templates/51_update-motd-hardy.tmpl 1970-01-01 00:00:00 +0000
126+++ VMBuilder/plugins/ec2/templates/51_update-motd-hardy.tmpl 2009-05-12 19:38:49 +0000
127@@ -0,0 +1,10 @@
128+#!/bin/sh
129+
130+echo "---------------------------------------------------------------------"
131+echo "At the moment, only the core of the system is installed. To tune the "
132+echo "system to your needs, you can choose to install one or more "
133+echo "predefined collections of software by running the following "
134+echo "command: "
135+echo " "
136+echo " sudo tasksel "
137+echo "---------------------------------------------------------------------"
138
139=== added file 'VMBuilder/plugins/ec2/templates/51_update-motd.tmpl'
140--- VMBuilder/plugins/ec2/templates/51_update-motd.tmpl 1970-01-01 00:00:00 +0000
141+++ VMBuilder/plugins/ec2/templates/51_update-motd.tmpl 2009-05-12 19:38:49 +0000
142@@ -0,0 +1,10 @@
143+#!/bin/sh
144+
145+echo "---------------------------------------------------------------------"
146+echo "At the moment, only the core of the system is installed. To tune the "
147+echo "system to your needs, you can choose to install one or more "
148+echo "predefined collections of software by running the following "
149+echo "command: "
150+echo " "
151+echo " sudo tasksel --section server "
152+echo "---------------------------------------------------------------------"
153
154=== added file 'VMBuilder/plugins/ec2/templates/ec2_version.tmpl'
155--- VMBuilder/plugins/ec2/templates/ec2_version.tmpl 1970-01-01 00:00:00 +0000
156+++ VMBuilder/plugins/ec2/templates/ec2_version.tmpl 2009-05-12 19:25:52 +0000
157@@ -0,0 +1,1 @@
158+$version
159
160=== added file 'VMBuilder/plugins/ec2/templates/sshd_config.tmpl'
161--- VMBuilder/plugins/ec2/templates/sshd_config.tmpl 1970-01-01 00:00:00 +0000
162+++ VMBuilder/plugins/ec2/templates/sshd_config.tmpl 2009-05-12 19:38:49 +0000
163@@ -0,0 +1,77 @@
164+# Package generated configuration file
165+# See the sshd(8) manpage for details
166+
167+# What ports, IPs and protocols we listen for
168+Port 22
169+# Use these options to restrict which interfaces/protocols sshd will bind to
170+#ListenAddress ::
171+#ListenAddress 0.0.0.0
172+Protocol 2
173+# HostKeys for protocol version 2
174+HostKey /etc/ssh/ssh_host_rsa_key
175+HostKey /etc/ssh/ssh_host_dsa_key
176+#Privilege Separation is turned on for security
177+UsePrivilegeSeparation yes
178+
179+# Lifetime and size of ephemeral version 1 server key
180+KeyRegenerationInterval 3600
181+ServerKeyBits 768
182+
183+# Logging
184+SyslogFacility AUTH
185+LogLevel INFO
186+
187+# Authentication:
188+LoginGraceTime 120
189+PermitRootLogin yes
190+StrictModes yes
191+
192+RSAAuthentication yes
193+PubkeyAuthentication yes
194+#AuthorizedKeysFile %h/.ssh/authorized_keys
195+
196+# Don't read the user's ~/.rhosts and ~/.shosts files
197+IgnoreRhosts yes
198+# For this to work you will also need host keys in /etc/ssh_known_hosts
199+RhostsRSAAuthentication no
200+# similar for protocol version 2
201+HostbasedAuthentication no
202+# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
203+#IgnoreUserKnownHosts yes
204+
205+# To enable empty passwords, change to yes (NOT RECOMMENDED)
206+PermitEmptyPasswords no
207+
208+# Change to yes to enable challenge-response passwords (beware issues with
209+# some PAM modules and threads)
210+ChallengeResponseAuthentication no
211+
212+# Change to no to disable tunnelled clear text passwords
213+PasswordAuthentication no
214+
215+# Kerberos options
216+#KerberosAuthentication no
217+#KerberosGetAFSToken no
218+#KerberosOrLocalPasswd yes
219+#KerberosTicketCleanup yes
220+
221+# GSSAPI options
222+#GSSAPIAuthentication no
223+#GSSAPICleanupCredentials yes
224+
225+X11Forwarding yes
226+X11DisplayOffset 10
227+PrintMotd no
228+PrintLastLog yes
229+TCPKeepAlive yes
230+#UseLogin no
231+
232+#MaxStartups 10:30:60
233+#Banner /etc/issue.net
234+
235+# Allow client to pass locale environment variables
236+AcceptEnv LANG LC_*
237+
238+Subsystem sftp /usr/lib/openssh/sftp-server
239+
240+UsePAM yes
241
242=== added file 'VMBuilder/plugins/ec2/templates/sudoers.tmpl'
243--- VMBuilder/plugins/ec2/templates/sudoers.tmpl 1970-01-01 00:00:00 +0000
244+++ VMBuilder/plugins/ec2/templates/sudoers.tmpl 2009-05-12 19:38:49 +0000
245@@ -0,0 +1,23 @@
246+# /etc/sudoers
247+#
248+# This file MUST be edited with the 'visudo' command as root.
249+#
250+# See the man page for details on how to write a sudoers file.
251+#
252+
253+Defaults env_reset
254+
255+# Uncomment to allow members of group sudo to not need a password
256+# %sudo ALL=NOPASSWD: ALL
257+
258+# Host alias specification
259+
260+# User alias specification
261+
262+# Cmnd alias specification
263+
264+# User privilege specification
265+root ALL=(ALL) ALL
266+ubuntu ALL=(ALL) NOPASSWD:ALL
267+
268+# Members of the admin group may gain root privileges
269
270=== removed file 'VMBuilder/plugins/ec2/templates/upstart.tmpl'
271--- VMBuilder/plugins/ec2/templates/upstart.tmpl 2008-11-11 18:28:57 +0000
272+++ VMBuilder/plugins/ec2/templates/upstart.tmpl 1970-01-01 00:00:00 +0000
273@@ -1,16 +0,0 @@
274-# tty1 - getty
275-#
276-# This service maintains a getty on tty1 from the point the system is
277-# started until it is shut down again.
278-
279-start on stopped rc2
280-start on stopped rc3
281-start on stopped rc4
282-start on stopped rc5
283-
284-stop on runlevel 0
285-stop on runlevel 1
286-stop on runlevel 6
287-
288-respawn
289-exec /sbin/getty 38400 xvc0
290
291=== modified file 'VMBuilder/plugins/ubuntu/dapper.py'
292--- VMBuilder/plugins/ubuntu/dapper.py 2009-05-07 21:00:20 +0000
293+++ VMBuilder/plugins/ubuntu/dapper.py 2009-05-13 15:24:34 +0000
294@@ -94,6 +94,9 @@
295 logging.debug("Copy host settings")
296 self.copy_settings()
297
298+ logging.debug("Setting timezone to UTC")
299+ self.set_utc_timezone()
300+
301 logging.debug("Making sure system is up-to-date")
302 self.update()
303
304@@ -136,8 +139,15 @@
305 else:
306 self.run_in_target('chpasswd', '-e', stdin='root:!\n')
307
308+ if self.vm.lock:
309+ logging.info('Locking %s' %(self.vm.user))
310+ self.run_in_target('chpasswd', '-e', stdin=('%s:!\n' %(self.vm.user)))
311+
312 def create_initial_user(self):
313- self.run_in_target('adduser', '--disabled-password', '--gecos', self.vm.name, self.vm.user)
314+ if self.vm.id:
315+ self.run_in_target('adduser', '--disabled-password', '--uid', self.vm.id, '--gecos', self.vm.name, self.vm.user)
316+ else:
317+ self.run_in_target('adduser', '--disabled-password', '--gecos', self.vm.name, self.vm.user)
318 self.run_in_target('addgroup', '--system', 'admin')
319 self.run_in_target('adduser', self.vm.user, 'admin')
320
321@@ -318,3 +328,8 @@
322
323 def install_vmbuilder_log(self, logfile, rootdir):
324 shutil.copy(logfile, '%s/var/log/vmbuilder-install.log' % (rootdir,))
325+
326+ def set_utc_timezone(self):
327+ if self.vm.set_utc:
328+ self.run_in_target('rm', '-f', '/etc/localtime')
329+ self.run_in_target('cp', '-a', '/usr/share/zoneinfo/UTC', '/etc/localtime')
330
331=== modified file 'VMBuilder/plugins/ubuntu/distro.py'
332--- VMBuilder/plugins/ubuntu/distro.py 2009-05-06 07:15:11 +0000
333+++ VMBuilder/plugins/ubuntu/distro.py 2009-05-13 15:24:34 +0000
334@@ -63,6 +63,7 @@
335 group.add_option('--components', metavar='COMPS', help='A comma seperated list of distro components to include (e.g. main,universe).')
336 group.add_option('--ppa', metavar='PPA', action='append', help='Add ppa belonging to PPA to the vm\'s sources.list.')
337 group.add_option('--lang', metavar='LANG', default=self.get_locale(), help='Set the locale to LANG [default: %default]')
338+ group.add_option('--set-utc', action='store_true', help='Set the clock to UTC')
339 self.vm.register_setting_group(group)
340
341 group = self.vm.setting_group('Settings for the initial user')
342@@ -70,6 +71,8 @@
343 group.add_option('--name', default='Ubuntu', help='Full name of initial user [default: %default]')
344 group.add_option('--pass', default='ubuntu', help='Password of initial user [default: %default]')
345 group.add_option('--rootpass', help='Initial root password (WARNING: this has strong security implications).')
346+ group.add_option('--id', help='Initial UID and GID values.')
347+ group.add_option('--lock' action='store_true', help='Lock the initial user [default %default]')
348 self.vm.register_setting_group(group)
349
350 group = self.vm.setting_group('Other options')
351
352=== modified file 'VMBuilder/plugins/ubuntu/hardy.py'
353--- VMBuilder/plugins/ubuntu/hardy.py 2008-11-06 15:36:18 +0000
354+++ VMBuilder/plugins/ubuntu/hardy.py 2009-05-13 17:13:26 +0000
355@@ -22,6 +22,20 @@
356
357 class Hardy(Gutsy):
358 virtio_net = True
359+ ec2_kernel_info = { 'i386' : 'aki-6e709707', 'amd64' : 'aki-6f709706' }
360+ ec2_ramdisk_info = { 'i386' : 'ari-6c709705', 'amd64' : 'ari-61709708' }
361+
362+ def install_ec2(self):
363+ if not self.vm.ec2:
364+ return False
365+
366+ if self.vm.addpkg:
367+ self.vm.addpkg = []
368+
369+ self.vm.addpkg += ['libc6-xen', 'ibc6-i686-']
370+ self.install_from_template('/etc/event.d/xvc0', 'upstart', { 'console' : 'xvc0' })
371+ self.install_from_template('/etc/ld.so.conf.d/libc6-xen.conf', 'xen-ld-so-conf')
372+ self.run_in_target('update-rc.d', '-f', 'hwclockfirst.sh', 'remove')
373
374 def xen_kernel_path(self):
375 return '/boot/vmlinuz-2.6.24-19-xen'
376
377=== modified file 'VMBuilder/plugins/ubuntu/intrepid.py'
378--- VMBuilder/plugins/ubuntu/intrepid.py 2009-02-17 14:39:16 +0000
379+++ VMBuilder/plugins/ubuntu/intrepid.py 2009-05-13 12:37:45 +0000
380@@ -29,6 +29,17 @@
381 'lpia' : ['lpia', 'lpiacompat'] }
382 default_flavour = { 'i386' : 'virtual', 'amd64' : 'virtual', 'lpia' : 'lpia' }
383 xen_kernel_flavour = 'virtual'
384+ ec2_kernel_info = { 'i386' : 'aki-714daa18', 'amd64' : 'aki-4f4daa26' }
385+ ec2_ramdisk_info = { 'i386': 'ari-7e4daa17', 'amd64' : 'ari-4c4daa25' }
386+
387+ def install_ec2(self):
388+ if not self.vm.ec2:
389+ return False
390+
391+ if not self.vm.addpkg:
392+ self.vm.addpkg = []
393+
394+ self.vm.addpkg += ['policykit', '^server']
395
396 def mangle_grub_menu_lst(self):
397 bootdev = disk.bootpart(self.vm.disks)
398
399=== modified file 'VMBuilder/plugins/ubuntu/jaunty.py'
400--- VMBuilder/plugins/ubuntu/jaunty.py 2009-05-07 21:00:20 +0000
401+++ VMBuilder/plugins/ubuntu/jaunty.py 2009-05-13 12:39:10 +0000
402@@ -25,6 +25,17 @@
403
404 class Jaunty(Intrepid):
405 xen_kernel_flavour = 'server'
406+ ec2_kernel_info = { 'i386' : 'aki-c553b4ac', 'amd64' : 'aki-d653b4bf' }
407+ ec2_ramdisk_info = { 'i386' : 'ari-c253b4ab', 'amd64' : 'ari-d753b4be' }
408+
409+ def install_ec2(self):
410+ if not self.vm.ec2:
411+ return False
412+
413+ if self.vm.addpkg:
414+ self.vm.addpkg = []
415+
416+ self.vm.addpkg = ['^server']
417
418 def mangle_grub_menu_lst(self):
419 bootdev = disk.bootpart(self.vm.disks)

Subscribers

People subscribed via source and target branches