[Pkg-escience-soc2009] [SCM] Tool for creating VM images. branch, master, updated. b713a1aac6d21782ebdc05997deb62cf1b320595
David Wendt
kmeisthax at Lappy-486.A
Sat Jul 11 03:07:41 UTC 2009
The following commit has been merged in the master branch:
commit 641582ea3ee00f6df451088f5104e091988df446
Author: David Wendt <kmeisthax at Lappy-486.A>
Date: Fri Jul 10 22:56:12 2009 -0400
A bunch of changes:
Moved a lot of Ubuntu specific preflight/postinstall cruft to the distro plugin where it belongs. Stuff like the EC2_init installation, adding the PPA, installing a specific sudoers file... That's all been moved to ubuntu/distro.py.
As a consequence, I've moved over 3 templates from ec2 to ubuntu, in an ec2 subdirectory so that they don't conflict with the rest of ubuntu's templates. (EC2 is supposed to install a different sudoers, for example)
What remains for EC2's preflight/postinstall is obvious sanity checks, disabling the hwclock, and installing /etc/ec2_version in the AMI.
Renamed option --no-amazon-tools to --ec2-no-amazon-tools (and same for no-euca-tools) for consistency.
VMbuilder EC2 no longer fatally crashes if you don't have the proper tools to deploy an image if you aren't trying to deploy an image. It will, however, warn you that you should have them installed. As far as I know you only need them for bundling or uploading, and we shouldn't crash if we aren't using the tools.
TODO: Write Debian preflight/postinstall for EC2.
diff --git a/VMBuilder/plugins/debian/distro.py b/VMBuilder/plugins/debian/distro.py
index 3b934f8..69529f5 100644
--- a/VMBuilder/plugins/debian/distro.py
+++ b/VMBuilder/plugins/debian/distro.py
@@ -137,6 +137,10 @@ class Debian(Distro):
msg = "locale-gen does not recognize your locale '%s'" % self.vm.lang
raise VMBuilderUserError(msg)
+ if hasattr(self.vm, "ec2") and self.vm.ec2:
+ self.get_ec2_kernel()
+ self.get_ec2_ramdisk()
+
def install(self, destdir):
self.destdir = destdir
self.suite.install(destdir)
@@ -174,12 +178,13 @@ EOT''')
#Specifically, etch is called 'oldstable' in the 3rd field, to get the suite you need
#excavate it from the 2nd field.
- if sline[1].strip().count(self.vm.suite) > 0:
+ if sline[1].strip().count(self.vm.suite) > 0: def disable_hwclock_access(self):
+ return self.suite.disable_hwclock_access()
#Fix for Debian handling of kernel version names
#It's x.y.z+w, not x.y.z.w
vt = sline[1].strip().split('.')
- deb_vt = vt[2].split('+')
- vt = [vt[0], vt[1], deb_vt[0], deb_vt[1]]
+ deb_vt = vt[2].split('+')
+ vt = [vt[0], vt[1], deb_vt[0], deb_vt[1]]
for i in range(4):
if int(vt[i]) > int(version[i]):
@@ -202,5 +207,19 @@ EOT''')
path = '/boot/initrd.img-%s-%s' % (self.xen_kernel_version(), self.suite.xen_kernel_flavour)
return path
+ def get_ec2_kernel(self):
+ if self.suite.ec2_kernel_info:
+ return self.suite.ec2_kernel_info[self.vm.arch]
+ else:
+ raise VMBuilderUserError('EC2 is not supported for the suite selected')
+
+ def get_ec2_ramdisk(self):
+ if self.suite.ec2_ramdisk_info:
+ return self.suite.ec2_ramdisk_info[self.vm.arch]
+ else:
+ raise VMBuilderUserError('EC2 is not supported for the suite selected')
+
+ def disable_hwclock_access(self):
+ return self.suite.disable_hwclock_access()
register_distro(Debian)
diff --git a/VMBuilder/plugins/debian/etch.py b/VMBuilder/plugins/debian/etch.py
index 03faa60..a73fa73 100644
--- a/VMBuilder/plugins/debian/etch.py
+++ b/VMBuilder/plugins/debian/etch.py
@@ -360,3 +360,10 @@ class Etch(suite.Suite):
#TODO: Change to Debian appropriate MOTD
#self.install_from_template('/etc/update-motd.d/51_update-motd', '51_update-motd-hardy')
#self.run_in_target('chmod', '755', '/etc/update-motd.d/51_update-motd')
+
+ def disable_hwclock_access(self):
+ #Selflessly stolen from dapper.py.
+ #Needed for EC2 usage.
+ fp = open('%s/etc/default/rcS' % self.destdir, 'a')
+ fp.write('HWCLOCKACCESS=no')
+ fp.close()
diff --git a/VMBuilder/plugins/ec2/__init__.py b/VMBuilder/plugins/ec2/__init__.py
index 6dc1b6f..619900d 100644
--- a/VMBuilder/plugins/ec2/__init__.py
+++ b/VMBuilder/plugins/ec2/__init__.py
@@ -45,15 +45,15 @@ class EC2(Plugin):
group.add_option('--ec2-bundle', action='store_true', help='Bundle the instance')
group.add_option('--ec2-upload', action='store_true', help='Upload the instance')
group.add_option('--ec2-register', action='store_true', help='Register the instance')
- group.add_option('--no-amazon-tools', action='store_true', help='Do not use Amazon\'s EC2 AMI tools.')
- group.add_option('--no-euca-tools', action='store_true', help='Do not use Eucalyptus\' EC2 AMI tools.')
+ group.add_option('--ec2-no-amazon-tools', action='store_true', help='Do not use Amazon\'s EC2 AMI tools.')
+ group.add_option('--ec2-no-euca-tools', action='store_true', help='Do not use Eucalyptus\' EC2 AMI tools.')
self.vm.register_setting_group(group)
def preflight_check(self):
if not getattr(self.vm, 'ec2', False):
return True
- if self.vm.no_amazon_tools:
+ if self.vm.ec2_no_amazon_tools:
logging.info("Not using Amazon ec2-tools.")
awsec2_installed = False
else:
@@ -64,7 +64,7 @@ class EC2(Plugin):
else:
awsec2_installed = True
- if self.vm.no_euca_tools:
+ if self.vm.ec2_no_euca_tools:
logging.info("Not using Eucalyptus euca2ools.")
euca_installed = False
else:
@@ -80,9 +80,14 @@ class EC2(Plugin):
elif awsec2_installed:
self.ec2_tools_prefix = "ec2-"
else:
- raise VMBuilderUserError('You do not have a suitable AMI tools suite installed.')
+ if self.vm.ec2_bundle or self.vm.ec2_upload:
+ raise VMBuilderUserError('When bundling or uploading for EC2 you must have ec2-tools or euca2ools installed.')
+ else:
+ logging.warn('You do not have a suitable AMI tools suite installed, however, the current operation does not require it.')
+ self.ec2_tools_prefix = None
- logging.info("EC2 tools prefix: %s" % self.ec2_tools_prefix)
+ if self.ec2_tools_prefix:
+ logging.info("Using EC2 tools prefix: %s" % self.ec2_tools_prefix)
if not self.vm.hypervisor.name == 'Xen':
raise VMBuilderUserError('When building for EC2 you must use the xen hypervisor.')
@@ -127,25 +132,6 @@ class EC2(Plugin):
if not self.vm.ec2_version:
raise VMBuilderUserError('When building for EC2 you must provide version info.')
- if not self.vm.addpkg:
- self.vm.addpkg = []
-
- self.vm.addpkg += ['ec2-init',
- 'openssh-server',
- 'ec2-modules',
- 'standard^',
- 'ec2-ami-tools',
- 'update-motd']
-
- if self.vm.ec2_landscape:
- logging.info('Installing landscape support')
- self.vm.addpkg += ['landscape-client']
-
- if not self.vm.ppa:
- self.vm.ppa = []
-
- self.vm.ppa += ['ubuntu-on-ec2/ppa']
-
def post_install(self):
if not getattr(self.vm, 'ec2', False):
return
@@ -153,11 +139,6 @@ class EC2(Plugin):
logging.info("Running ec2 postinstall")
self.install_from_template('/etc/ec2_version', 'ec2_version', { 'version' : self.vm.ec2_version } )
- self.install_from_template('/etc/ssh/sshd_config', 'sshd_config')
- self.install_from_template('/etc/sudoers', 'sudoers')
-
- if self.vm.ec2_landscape:
- self.install_from_template('/etc/default/landscape-client', 'landscape_client')
self.vm.distro.disable_hwclock_access()
diff --git a/VMBuilder/plugins/ubuntu/distro.py b/VMBuilder/plugins/ubuntu/distro.py
index 6e7d9f1..1cde521 100644
--- a/VMBuilder/plugins/ubuntu/distro.py
+++ b/VMBuilder/plugins/ubuntu/distro.py
@@ -136,10 +136,29 @@ class Ubuntu(Distro):
msg = "locale-gen does not recognize your locale '%s'" % self.vm.lang
raise VMBuilderUserError(msg)
- if self.vm.ec2:
+ if hasattr(self.vm, "ec2") and self.vm.ec2:
self.get_ec2_kernel()
self.get_ec2_ramdisk()
+ if not self.vm.addpkg:
+ self.vm.addpkg = []
+
+ self.vm.addpkg += ['ec2-init',
+ 'openssh-server',
+ 'ec2-modules',
+ 'standard^',
+ 'ec2-ami-tools',
+ 'update-motd']
+
+ if self.vm.ec2_landscape:
+ logging.info('Installing landscape support')
+ self.vm.addpkg += ['landscape-client']
+
+ if not hasattr(self.vm, "ppa") or not self.vm.ppa:
+ self.vm.ppa = []
+
+ self.vm.ppa += ['ubuntu-on-ec2/ppa']
+
def install(self, destdir):
self.destdir = destdir
self.suite.install(destdir)
@@ -212,4 +231,14 @@ EOT''')
def disable_hwclock_access(self):
return self.suite.disable_hwclock_access()
+ def post_install(self):
+ #Ubuntu postinstalll for EC2 functionality.
+ #These particular packages are stored in the ec2 directory.
+ if hasattr(self.vm, "ec2") and self.vm.ec2:
+ self.install_from_template('/etc/ssh/sshd_config', 'ec2/sshd_config')
+ self.install_from_template('/etc/sudoers', 'ec2/sudoers')
+
+ if self.vm.ec2_landscape:
+ self.install_from_template('/etc/default/landscape-client', 'ec2/landscape_client')
+
register_distro(Ubuntu)
diff --git a/VMBuilder/plugins/ubuntu/hardy.py b/VMBuilder/plugins/ubuntu/hardy.py
index f5181d6..7da2e9f 100644
--- a/VMBuilder/plugins/ubuntu/hardy.py
+++ b/VMBuilder/plugins/ubuntu/hardy.py
@@ -37,15 +37,15 @@ class Hardy(Gutsy):
self.run_in_target('chmod', '755', '/etc/update-motd.d/51_update-motd')
def xen_kernel_path(self):
- rcmd = run_cmd('chroot', self.destdir, 'dpkg', '-S', 'xen')
- temp = rcmd[0].split(": ")
- xen_kernel = temp[0].split("linux-image-")
- path = '/boot/vmlinuz-%s' %xen_kernel
- return path
+ rcmd = run_cmd('chroot', self.destdir, 'dpkg', '-S', 'xen')
+ temp = rcmd[0].split(": ")
+ xen_kernel = temp[0].split("linux-image-")
+ path = '/boot/vmlinuz-%s' %xen_kernel
+ return path
def xen_ramdisk_path(self):
- rcmd = run_cmd('chroot', self.destdir, 'dpkg', '-S', 'xen')
- temp = rcmd[0].split(": ")
- xen_ramdisk = temp[0].split("linux-image-")
- path = '/boot/initrd.img-%s' %xen_ramdisk
- return path
+ rcmd = run_cmd('chroot', self.destdir, 'dpkg', '-S', 'xen')
+ temp = rcmd[0].split(": ")
+ xen_ramdisk = temp[0].split("linux-image-")
+ path = '/boot/initrd.img-%s' %xen_ramdisk
+ return path
diff --git a/VMBuilder/plugins/ec2/templates/landscape_client.tmpl b/VMBuilder/plugins/ubuntu/templates/ec2/landscape_client.tmpl
similarity index 100%
rename from VMBuilder/plugins/ec2/templates/landscape_client.tmpl
rename to VMBuilder/plugins/ubuntu/templates/ec2/landscape_client.tmpl
diff --git a/VMBuilder/plugins/ec2/templates/sshd_config.tmpl b/VMBuilder/plugins/ubuntu/templates/ec2/sshd_config.tmpl
similarity index 100%
rename from VMBuilder/plugins/ec2/templates/sshd_config.tmpl
rename to VMBuilder/plugins/ubuntu/templates/ec2/sshd_config.tmpl
diff --git a/VMBuilder/plugins/ec2/templates/sudoers.tmpl b/VMBuilder/plugins/ubuntu/templates/ec2/sudoers.tmpl
similarity index 100%
rename from VMBuilder/plugins/ec2/templates/sudoers.tmpl
rename to VMBuilder/plugins/ubuntu/templates/ec2/sudoers.tmpl
--
Tool for creating VM images.
More information about the Pkg-escience-soc2009
mailing list