[Pkg-escience-soc2009] [SCM] Tool for creating VM images. branch, master, updated. d6dc1eb48dbf54cefdc99e47485024c0478c4163

David Wendt dcrkid at yahoo.com
Wed Jun 10 22:12:56 UTC 2009


The following commit has been merged in the master branch:
commit d6dc1eb48dbf54cefdc99e47485024c0478c4163
Merge: 5fc9757950d15e9be3439111cb731711106ab819 b6f14cc0bc987e3ae8d031ec2f25aa71e1faa165
Author: David Wendt <dcrkid at yahoo.com>
Date:   Tue Jun 9 21:10:55 2009 -0400

    Merging in EC2 builder patches. Edit conflicts fixed; nothing major.
    
    Merge branch 'vmbuilder_ec2_patches'
    
    Conflicts:
    
    	VMBuilder/plugins/cli/__init__.py
    	VMBuilder/plugins/ubuntu/dapper.py
    	VMBuilder/plugins/ubuntu/hardy.py
    	VMBuilder/plugins/ubuntu/jaunty.py
    	VMBuilder/vm.py
    	debian/control
    	debian/python-vm-builder-ec2.install
    	debian/python-vm-builder.install

diff --combined VMBuilder/plugins/cli/__init__.py
index 8601b08,5d3216c..503543e
--- a/VMBuilder/plugins/cli/__init__.py
+++ b/VMBuilder/plugins/cli/__init__.py
@@@ -1,6 -1,5 +1,6 @@@
  #    Uncomplicated VM Builder
  #    Copyright (C) 2007-2008 Canonical Ltd.
 +#    Copyright (C) 2009      Bernd Zeimetz <bzed at debian.org>
  #    
  #    See AUTHORS for list of contributors
  #
@@@ -24,13 -23,13 +24,13 @@@ import optpars
  import sys
  import textwrap
  import VMBuilder
 -import VMBuilder.hypervisor
 +from VMBuilder.disk import parse_size
  _ = gettext
  
  
  class CLI(VMBuilder.Frontend):
      arg = 'cli'
 -       
 +    
      def run(self):
          try:
              next = False
@@@ -44,15 -43,15 +44,15 @@@
  
              vm = VMBuilder.VM(conf)
              vm.register_setting('--version', action='callback', callback=self.versioninfo, callback_kwargs={ 'vm' : vm }, help='Show version information')
-             vm.register_setting('--rootsize', metavar='SIZE', default=4096, help='Size (in MB) of the root filesystem [default: %default]')
-             vm.register_setting('--optsize', metavar='SIZE', default=0, help='Size (in MB) of the /opt filesystem. If not set, no /opt filesystem will be added.')
-             vm.register_setting('--swapsize', metavar='SIZE', default=1024, help='Size (in MB) of the swap partition [default: %default]')
+             vm.register_setting('--rootsize', metavar='SIZE', type='int', default=4096, help='Size (in MB) of the root filesystem [default: %default]')
+             vm.register_setting('--optsize', metavar='SIZE', type='int', default=0, help='Size (in MB) of the /opt filesystem. If not set, no /opt filesystem will be added.')
+             vm.register_setting('--swapsize', metavar='SIZE', type='int', default=1024, help='Size (in MB) of the swap partition [default: %default]')
              vm.register_setting('--raw', metavar='PATH', type='string', help="Specify a file (or block device) to as first disk image.")
              vm.register_setting('--part', metavar='PATH', type='string', help="Allows to specify a partition table in PATH each line of partfile should specify (root first): \n    mountpoint size \none per line, separated by space, where size is in megabytes. You can have up to 4 virtual disks, a new disk starts on a line containing only '---'. ie: \n    root 2000 \n    /boot 512 \n    swap 1000 \n    --- \n    /var 8000 \n    /var/log 2000")
              self.set_usage(vm)
  
              vm.optparser.disable_interspersed_args()
 -            (foo, args) = vm.optparser.parse_args()
 +            args = vm.optparser.parse_args()[1]
              self.handle_args(vm, args)
              vm.optparser.enable_interspersed_args()
  
@@@ -86,14 -85,11 +86,14 @@@
  
      def set_disk_layout(self, vm):
          if not vm.part:
 +            vm.rootsize = parse_size(vm.rootsize)
 +            vm.swapsize = parse_size(vm.swapsize)
 +            vm.optsize = parse_size(vm.optsize)
              if vm.hypervisor.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE:
                  vm.add_filesystem(size='%dM' % vm.rootsize, type='ext3', mntpnt='/')
                  vm.add_filesystem(size='%dM' % vm.swapsize, type='swap', mntpnt=None)
                  if vm.optsize > 0:
 -                    vm.add_filesystem(size='%dM' % optsize, type='ext3', mntpnt='/opt')
 +                    vm.add_filesystem(size='%dM' % vm.optsize, type='ext3', mntpnt='/opt')
              else:
                  if vm.raw:
                      disk = vm.add_disk(filename=vm.raw, preallocated=True)
@@@ -161,38 -157,22 +161,38 @@@
                  disk.add_part(offset, int(pair[1]), 'ext3', pair[0])
              offset += int(pair[1])
  
 -class UVB(CLI):
 -    arg = 'ubuntu-vm-builder'
 +class VB(CLI):
 +    arg = 'vb'
 +    suites = []
 +    distro = ''
  
      def set_usage(self, vm):
          vm.optparser.set_usage('%prog hypervisor suite [options]')
          vm.optparser.arg_help = (('hypervisor', vm.hypervisor_help), ('suite', self.suite_help))
  
      def suite_help(self):
 -        return 'Suite. Valid options: %s' % " ".join(VMBuilder.plugins.ubuntu.distro.Ubuntu.suites)
 +        return 'Suite. Valid options: %s' % " ".join(self.suites)
  
      def handle_args(self, vm, args):
          if len(args) < 2:
              vm.optparser.error("You need to specify at least the hypervisor type and the suite")
          vm.set_hypervisor(args[0])
 -        vm.set_distro('ubuntu')
 +        vm.set_distro(self.distro)
          vm.suite = args[1]
   
 +class UVB(VB):
 +    arg = 'ubuntu-vm-builder'
 +    import VMBuilder.plugins.ubuntu as ubuntu
 +    suites = ubuntu.distro.Ubuntu.suites
 +    distro = 'ubuntu'
 +
 +class DVB(VB):
 +    arg = 'debian-vm-builder'
 +    import VMBuilder.plugins.debian as debian
 +    suites = debian.distro.Debian.suites
 +    distro = 'debian'
 +
 +
  VMBuilder.register_frontend(CLI)
  VMBuilder.register_frontend(UVB)
 +VMBuilder.register_frontend(DVB)
diff --combined VMBuilder/plugins/ec2/__init__.py
index 64f0ba8,24990a8..938b5c9
--- a/VMBuilder/plugins/ec2/__init__.py
+++ b/VMBuilder/plugins/ec2/__init__.py
@@@ -20,7 -20,6 +20,7 @@@
  from VMBuilder import register_plugin, Plugin, VMBuilderUserError
  from VMBuilder.util import run_cmd
  import logging
 +import os
  
  class EC2(Plugin):
      name = 'EC2 integration'
@@@ -37,6 -36,7 +37,7 @@@
          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.')
          self.vm.register_setting_group(group)
  
      def preflight_check(self):
@@@ -50,33 -50,55 +51,61 @@@
              raise VMBuilderUserError('When building for EC2 you must supply the name for the image.')
  
          if not self.vm.ec2_cert:
 -            raise VMBuilderUserError('When building for EC2 you must provide your PEM encoded public key certificate')
 +            if "EC2_CERT" in os.environ:
 +                self.vm.ec2_cert = os.environ["EC2_CERT"]
 +            else:
 +                raise VMBuilderUserError('When building for EC2 you must provide your PEM encoded public key certificate')
  
          if not self.vm.ec2_key:
 -            raise VMBuilderUserError('When building for EC2 you must provide your PEM encoded private key file')
 +            if "EC2_PRIVATE_KEY" in os.environ:
 +                self.vm.ec2_key = os.environ["EC2_PRIVATE_KEY"]
 +            else:
 +                raise VMBuilderUserError('When building for EC2 you must provide your PEM encoded private key file')
  
          if not self.vm.ec2_user:
              raise VMBuilderUserError('When building for EC2 you must provide your EC2 user ID (your AWS account number, not your AWS access key ID)')
  
          if not self.vm.ec2_kernel:
              logging.debug('No ec2-aki choosen setting to default. Use --ec2-kernel to change this')
-             if self.vm.arch == 'amd64':
-                 self.vm.ec2_kernel = 'aki-d314f0ba'
-             else:
-                 self.vm.ec2_kernel = 'aki-af14f0c6'
+ 	    if self.vm.suite == 'hardy':
+                if self.vm.arch == 'amd64':
+ 	          self.vm.ec2_kernel = 'aki-6f709706'
+ 	       else:
+ 	          self.vm.ec2_kernel = 'aki-6e709707'
+ 	    elif self.vm.suite == 'intrepid':
+ 	        if self.vm.arch == 'amd64':
+                    self.vm.ec2_kernel = 'aki-4f4daa26'
+ 	        else: 
+ 	           self.vm.ec2_kernel = 'aki-714daa18' 
+ 	    elif self.vm.suite == 'jaunty':
+                 if self.vm.arch == 'amd64':
+                     self.vm.ec2_kernel = 'aki-6507e00c'
+                 else:
+ 	            self.vm.ec2_kernel = 'aki-6407e00d'
+ 
+         logging.info('%s - AKI to be used.' %(self.vm.ec2_kernel))
+ 	logging.info('WARNING! You might be using an outdated AKI. Please check xxx')
  
          if not self.vm.ec2_ramdisk:
              logging.debug('No ec2-ari choosen setting to default. Use --ec2-ramdisk to change this.')
-             if self.vm.arch == 'amd64':
-                 self.vm.ec2_ramdisk = 'ari-d014f0b9'
-             else:
-                 self.vm.ec2_ramdisk = 'ari-ac14f0c5'
+ 	    if self.vm.suite == 'hardy':
+               if self.vm.arch == 'amd64':
+                  self.vm.ec2_ramdisk = 'ari-61709708'
+               else:
+                  self.vm.ec2_ramdisk = 'ari-6c709705'
+ 	    elif self.vm.suite == 'intrepid':
+                 if self.vm.arch == 'amd64':
+                    self.vm.ec2_ramdisk = 'ari-4c4daa25' 
+                 else:
+                    self.vm.ec2_ramdisk = 'ari-7e4daa17'
+ 	    elif self.vm.suite == 'jaunty':
+                 if self.vm.arch == 'amd64':
+ 	           self.vm.ec2_ramdisk = 'ari-6307e00a'
+                 else:
+ 	           self.vm.ec2_ramdisk = 'ari-6207e00b'
+ 
+ 	logging .info('%s - ARI to be used.'%(self.vm.ec2_ramdisk))
+ 	logging.info('WARNING! You might be using an outdated AKI. Please check xxx')
  
          if not self.vm.ec2_bucket:
              raise VMBuilderUserError('When building for EC2 you must provide an S3 bucket to hold the AMI')
@@@ -87,40 -109,37 +116,39 @@@
          if not self.vm.ec2_secret_key:
              raise VMBuilderUserError('When building for EC2 you must provide your AWS secret access key.')
  
- 
-         if not self.vm.addpkg:
-              self.vm.addpkg = []
- 
-         self.vm.addpkg += ['openssh-server']
-         self.vm.addpkg += ['ec2-init']
-         self.vm.addpkg += ['openssh-server']
-         self.vm.addpkg += ['ec2-modules']
-         self.vm.addpkg += ['server^']
-         self.vm.addpkg += ['standard^']
- 
-         if not self.vm.ppa:
-             self.vm.ppa = []
- 
-         self.vm.ppa += ['ubuntu-ec2']
+ 	logging.info('Installing common software')
+ 	self.install_common()
+ 	if self.vm.suite == 'hardy':
+              self.install_hardy()
+ 	elif self.vm.suite == 'intrepid':
+               self.install_intrepid()
+ 	elif self.vm.suite == 'jaunty':
+               self.install_jaunty()
  
      def post_install(self):
          if not self.vm.ec2:
              return
  
          logging.info("Running ec2 postinstall")
-         self.install_from_template('/etc/event.d/xvc0', 'upstart')
-         self.run_in_target('passwd', '-l', self.vm.user)
+ 	logging.info("Running common post install")
+ 	if self.vm.suite == 'hardy':
+ 	     self.postinstall_hardy()
+ 	elif self.vm.suite == 'intrepid':
+ 	     self.postinstall_intrepid()
+ 	elif self.vm.suite == 'jaunty':
+ 	     self.postinstall_jaunty()
+ 	self.postinstall_common()
  
      def deploy(self):
          if not self.vm.ec2:
              return False
  
 +        logging.info("Building EC2 bundle")
          bundle_cmdline = ['ec2-bundle-image', '--image', self.vm.filesystems[0].filename, '--cert', self.vm.ec2_cert, '--privatekey', self.vm.ec2_key, '--user', self.vm.ec2_user, '--prefix', self.vm.ec2_name, '-r', ['i386', 'x86_64'][self.vm.arch == 'amd64'], '-d', self.vm.workdir, '--kernel', self.vm.ec2_kernel, '--ramdisk', self.vm.ec2_ramdisk]
  
          run_cmd(*bundle_cmdline)
  
 +        logging.info("Uploading EC2 bundle")
          upload_cmdline = ['ec2-upload-bundle', '--retry', '--manifest', '%s/%s.manifest.xml' % (self.vm.workdir, self.vm.ec2_name), '--bucket', self.vm.ec2_bucket, '--access-key', self.vm.ec2_access_key, '--secret-key', self.vm.ec2_secret_key]
          run_cmd(*upload_cmdline)
  
@@@ -130,4 -149,111 +158,111 @@@
  
          return True
  
+     def install_common(self):
+         if not self.vm.ec2:
+             return False
+ 
+ 	if not self.vm.addpkg:
+ 	    self.vm.addpkg = []
+ 
+ 	logging.info('Installing common software.')
+ 	self.vm.addpkg += ['openssh-server', 
+                            'ec2-init', 
+                            'standard^',
+ 		           'ec2-ami-tools',
+                            'update-motd',
+                            'curl',
+                            'screen',
+                            'screen-profiles']
+ 
+ 	if not self.vm.ppa:
+ 	    self.vm.ppa = []
+ 
+         self.vm.ppa += ['ubuntu-on-ec2']
+ 
+     def install_hardy(self):
+ 	if not self.vm.ec2:
+ 	    return False
+ 
+ 	logging.info('Installing software for hardy.')
+ 	self.vm.addpkg += ['ruby',
+ 			   'libc6-xen',
+ 			   'ec2-modules',
+ 			   'libopenssl-ruby',
+ 			   'landscape-common',
+ 			   'landscape-client']
+ 
+ 
+     def postinstall_hardy(self):
+ 	if not self.vm.ec2:
+ 	    return False
+ 
+ 	logging.info('Running post-install for hardy')
+ 	# work around for libc6/xen bug in hardy.
+ 	self.install_from_template('/etc/ld.so.conf.d/libc6-xen.conf', 'xen-ld-so-conf')
+ 	self.run_in_target('apt-get', 'remove', '-y', 'libc6-i686')
+ 
+ 	self.install_from_template('/etc/update-motd.d/51_update-motd', '51_update-motd-hardy')
+ 	self.install_from_template('/etc/event.d/xvc0', 'xvc0')
+ 	self.run_in_target('update-rc.d', '-f', 'hwclockfirst.sh', 'remove')
+ 
+     def install_intrepid(self):
+ 	if not self.vm.ec2:
+ 	    return False
+ 
+ 	logging.info('Installing software for intrepid')
+ 	self.vm.addpkg += ['ec2-modules',
+ 			   'ruby',
+ 			   'libopenssl-ruby',
+                            'server^',
+                            'policykit',
+ 			   'landscape-common',
+ 			   'landscape-client']
+ 
+     def postinstall_intrepid(self):
+ 	if not self.vm.ec2:
+ 	    return False
+ 
+ 	logging.info('Running post-install for intrepid')
+ 	self.install_from_template('/etc/update-motd.d/51_update-motd', '51_update-motd-intrepid')
+ 
+     def install_jaunty(self):
+ 	if not self.vm.ec2:
+ 	    return False
+ 
+ 	logging.info('Installing software for jaunty')
+ 	self.vm.addpkg += ['ec2-modules',
+ 			   'ruby1.8',
+                            'server^',
+ 			   'libopenssl-ruby1.8']
+ 
+     def postinall_jaunty(self):
+ 	if not self.vm.ec2:
+             return False
+ 	
+ 	logging.info('Running post-install for jaunty') 
+ 	self.install_from_template('/etc/update-motd.d/51_update-motd', '51_update-motd-intrepid')
+ 
+     def postinstall_common(self):
+ 	if not self.vm.ec2:
+ 	    return False
+ 
+ 	logging.info('Running common post-install')
+ 	self.install_from_template('/etc/ssh/sshd_config', 'sshd_config')
+ 	self.run_in_target('chpasswd', '-e', stdin='ubuntu:!\n')
+ 	# this makes my skin crawl
+ 	self.install_from_template('/etc/sudoers', 'sudoers')
+ 	# this doesnt
+ 	self.run_in_target('chmod', '755', '/etc/update-motd.d/51_update-motd')
+ 	self.install_from_template('/etc/ec2_version', 'ec2_version', { 'version' : self.vm.ec2_version })
+ 
+ 	self.run_in_target('rm', '-f', '/etc/localtime')
+ 	self.run_in_target('ln', '-s', '/usr/share/zoneinfo/UTC', '/etc/localtime')
+ 
+ 	self.run_in_target('usermod', '-u', '135', 'ubuntu')
+ 	self.run_in_target('chown', '-R', 'ubuntu', '/home/ubuntu')
+ 
+ 	self.run_in_target('update-rc.d', '-f', 'hwclock.sh', 'remove') 
+ 	self.install_from_template('/etc/default/landscape-client', 'landscape_client')
+ 
  register_plugin(EC2)
diff --combined VMBuilder/plugins/ubuntu/dapper.py
index 60b0b6a,32bca6f..f598dad
--- a/VMBuilder/plugins/ubuntu/dapper.py
+++ b/VMBuilder/plugins/ubuntu/dapper.py
@@@ -20,12 -20,11 +20,12 @@@
  import glob
  import logging
  import os
 -import suite
  import shutil
  import socket
 +import tempfile
  import VMBuilder
  import VMBuilder.disk as disk
 +import VMBuilder.suite as suite
  from   VMBuilder.util import run_cmd
  
  class Dapper(suite.Suite):
@@@ -53,9 -52,6 +53,9 @@@
          logging.debug("Setting up sources.list")
          self.install_sources_list()
  
 +        logging.debug("Setting up apt proxy")
 +        self.install_apt_proxy()
 +
          logging.debug("Installing fstab")
          self.install_fstab()
  
@@@ -82,15 -78,18 +82,21 @@@
              logging.debug("Creating device.map")
              self.install_device_map()
  
+         logging.debug("Installing ssh keys")
+         self.install_authorized_keys()
+ 
+ 	logging.debug("Install xen kernel")
+ 	self.install_xen_kernel()
+ 
          logging.debug("Installing extra packages")
          self.install_extras()
  
          logging.debug("Creating initial user")
          self.create_initial_user()
  
 +        logging.debug("Installing ssh keys")
 +        self.install_authorized_keys()
 +
          logging.debug("Copy host settings")
          self.copy_settings()
  
@@@ -107,8 -106,7 +113,8 @@@
          self.unprevent_daemons_starting()
  
      def update(self):
 -        self.run_in_target('apt-get', '-y', '--force-yes', 'dist-upgrade')
 +        self.run_in_target('apt-get', '-y', '--force-yes', 'dist-upgrade',
 +                           env={ 'DEBIAN_FRONTEND' : 'noninteractive' })
          
      def install_authorized_keys(self):
          if self.vm.ssh_key:
@@@ -119,25 -117,14 +125,25 @@@
              os.mkdir('%s/home/%s/.ssh' % (self.destdir, self.vm.user), 0700)
              shutil.copy(self.vm.ssh_user_key, '%s/home/%s/.ssh/authorized_keys' % (self.destdir, self.vm.user))
              os.chmod('%s/home/%s/.ssh/authorized_keys' % (self.destdir, self.vm.user), 0644)
 +            self.run_in_target('chown', '-R', '%s:%s' % (self.vm.user,)*2, '/home/%s/.ssh/' % (self.vm.user)) 
 +
          if self.vm.ssh_user_key or self.vm.ssh_key:
              if not self.vm.addpkg:
                  self.vm.addpkg = []
              self.vm.addpkg += ['openssh-server']
  
 +    def update_passwords(self):
 +        # Set the user password, using md5
 +        self.run_in_target('chpasswd', '-m', stdin=('%s:%s\n' % (self.vm.user, getattr(self.vm, 'pass'))))
 +
 +        # Lock root account only if we didn't set the root password
 +        if self.vm.rootpass:
 +            self.run_in_target('chpasswd', '-m', stdin=('%s:%s\n' % ('root', self.vm.rootpass)))
 +        else:
 +            self.run_in_target('chpasswd', '-e', stdin='root:!\n')
 +
      def create_initial_user(self):
          self.run_in_target('adduser', '--disabled-password', '--gecos', self.vm.name, self.vm.user)
 -        self.run_in_target('chpasswd', stdin=('%s:%s\n' % (self.vm.user, getattr(self.vm, 'pass'))))
          self.run_in_target('addgroup', '--system', 'admin')
          self.run_in_target('adduser', self.vm.user, 'admin')
  
@@@ -145,7 -132,8 +151,7 @@@
          for group in ['adm', 'audio', 'cdrom', 'dialout', 'floppy', 'video', 'plugdev', 'dip', 'netdev', 'powerdev', 'lpadmin', 'scanner']:
              self.run_in_target('adduser', self.vm.user, group, ignore_fail=True)
  
 -        # Lock root account
 -        self.run_in_target('chpasswd', '-e', stdin='root:!\n')
 +        self.update_passwords()
  
      def kernel_name(self):
          return 'linux-image-%s' % (self.vm.flavour or self.default_flavour[self.vm.arch],)
@@@ -208,10 -196,6 +214,10 @@@
          # final vm is going to be on).
          self.run_in_target('apt-get', 'update', ignore_fail=final)
  
 +    def install_apt_proxy(self):
 +        if self.vm.proxy is not None:
 +            self.vm.install_file('/etc/apt/apt.conf', '// Proxy added by vmbuilder\nAcquire::http { Proxy "%s"; };' % self.vm.proxy)
 +
      def install_fstab(self):
          if self.vm.hypervisor.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE:
              self.install_from_template('/etc/fstab', 'dapper_fstab_fsimage', { 'fss' : disk.get_ordered_filesystems(self.vm), 'prefix' : self.disk_prefix })
@@@ -222,18 -206,12 +228,18 @@@
          self.install_from_template('/boot/grub/device.map', 'devicemap', { 'prefix' : self.disk_prefix })
  
      def debootstrap(self):
 -        cmd = ['/usr/sbin/debootstrap', '--arch=%s' % self.vm.arch, self.vm.suite, self.destdir, self.debootstrap_mirror()]
 -        run_cmd(*cmd)
 +        cmd = ['/usr/sbin/debootstrap', '--arch=%s' % self.vm.arch]
 +        if self.vm.variant:
 +            cmd += ['--variant=%s' % self.vm.variant]
 +        cmd += [self.vm.suite, self.destdir, self.debootstrap_mirror()]
 +        kwargs = { 'env' : { 'DEBIAN_FRONTEND' : 'noninteractive' } }
 +        if self.vm.proxy:
 +            kwargs['env']['http_proxy'] = self.vm.proxy
 +        run_cmd(*cmd, **kwargs)
      
      def debootstrap_mirror(self):
          if self.vm.iso:
 -            os.mkdir(isodir)
 +            isodir = tempfile.mkdtemp()
              self.vm.add_clean_cb(lambda:os.rmdir(isodir))
              run_cmd('mount', '-o', 'loop', '-t', 'iso9660', self.vm.iso, isodir)
              self.vm.add_clean_cmd('umount', isodir)
@@@ -289,7 -267,6 +295,7 @@@
          self.vm.distro.run_in_target(*args, **kwargs)
  
      def copy_to_target(self, infile, destpath):
 +        logging.debug("Copying %s on host to %s in guest" % (infile, destpath))
          dir = '%s/%s' % (self.destdir, os.path.dirname(destpath))
          if not os.path.isdir(dir):
              os.makedirs(dir)
@@@ -308,13 -285,9 +314,13 @@@
      def copy_settings(self):
          self.copy_to_target('/etc/default/locale', '/etc/default/locale')
          self.copy_to_target('/etc/timezone', '/etc/timezone')
 -        self.run_in_target('dpkg-reconfigure', '-pcritical', 'libc6')
 +        self.run_in_target('dpkg-reconfigure', '-fnoninteractive', '-pcritical', 'libc6')
          self.run_in_target('locale-gen', 'en_US')
          if self.vm.lang:
              self.run_in_target('locale-gen', self.vm.lang)
              self.install_from_template('/etc/default/locale', 'locale', { 'lang' : self.vm.lang })
 +        self.run_in_target('dpkg-reconfigure', '-fnoninteractive', '-pcritical', 'locales')
          self.run_in_target('dpkg-reconfigure', '-pcritical', 'locales')
 +
 +    def install_vmbuilder_log(self, logfile, rootdir):
 +        shutil.copy(logfile, '%s/var/log/vmbuilder-install.log' % (rootdir,))
diff --combined VMBuilder/plugins/ubuntu/dapper.py~
index 60b0b6a,32bca6f..2370804
--- a/VMBuilder/plugins/ubuntu/dapper.py~
+++ b/VMBuilder/plugins/ubuntu/dapper.py~
@@@ -20,12 -20,11 +20,12 @@@
  import glob
  import logging
  import os
 -import suite
  import shutil
  import socket
 +import tempfile
  import VMBuilder
  import VMBuilder.disk as disk
 +import VMBuilder.suite as suite
  from   VMBuilder.util import run_cmd
  
  class Dapper(suite.Suite):
@@@ -53,9 -52,6 +53,9 @@@
          logging.debug("Setting up sources.list")
          self.install_sources_list()
  
 +        logging.debug("Setting up apt proxy")
 +        self.install_apt_proxy()
 +
          logging.debug("Installing fstab")
          self.install_fstab()
  
@@@ -82,15 -78,18 +82,24 @@@
              logging.debug("Creating device.map")
              self.install_device_map()
  
++<<<<<<< HEAD:VMBuilder/plugins/ubuntu/dapper.py
++=======
+         logging.debug("Installing ssh keys")
+         self.install_authorized_keys()
+ 
+ 	logging.debug("Install xen kernel")
+ 	self.install_xen_kernel()
+ 
++>>>>>>> vmbuilder_ec2_patches:VMBuilder/plugins/ubuntu/dapper.py
          logging.debug("Installing extra packages")
          self.install_extras()
  
          logging.debug("Creating initial user")
          self.create_initial_user()
  
 +        logging.debug("Installing ssh keys")
 +        self.install_authorized_keys()
 +
          logging.debug("Copy host settings")
          self.copy_settings()
  
@@@ -107,8 -106,7 +116,8 @@@
          self.unprevent_daemons_starting()
  
      def update(self):
 -        self.run_in_target('apt-get', '-y', '--force-yes', 'dist-upgrade')
 +        self.run_in_target('apt-get', '-y', '--force-yes', 'dist-upgrade',
 +                           env={ 'DEBIAN_FRONTEND' : 'noninteractive' })
          
      def install_authorized_keys(self):
          if self.vm.ssh_key:
@@@ -119,25 -117,14 +128,25 @@@
              os.mkdir('%s/home/%s/.ssh' % (self.destdir, self.vm.user), 0700)
              shutil.copy(self.vm.ssh_user_key, '%s/home/%s/.ssh/authorized_keys' % (self.destdir, self.vm.user))
              os.chmod('%s/home/%s/.ssh/authorized_keys' % (self.destdir, self.vm.user), 0644)
 +            self.run_in_target('chown', '-R', '%s:%s' % (self.vm.user,)*2, '/home/%s/.ssh/' % (self.vm.user)) 
 +
          if self.vm.ssh_user_key or self.vm.ssh_key:
              if not self.vm.addpkg:
                  self.vm.addpkg = []
              self.vm.addpkg += ['openssh-server']
  
 +    def update_passwords(self):
 +        # Set the user password, using md5
 +        self.run_in_target('chpasswd', '-m', stdin=('%s:%s\n' % (self.vm.user, getattr(self.vm, 'pass'))))
 +
 +        # Lock root account only if we didn't set the root password
 +        if self.vm.rootpass:
 +            self.run_in_target('chpasswd', '-m', stdin=('%s:%s\n' % ('root', self.vm.rootpass)))
 +        else:
 +            self.run_in_target('chpasswd', '-e', stdin='root:!\n')
 +
      def create_initial_user(self):
          self.run_in_target('adduser', '--disabled-password', '--gecos', self.vm.name, self.vm.user)
 -        self.run_in_target('chpasswd', stdin=('%s:%s\n' % (self.vm.user, getattr(self.vm, 'pass'))))
          self.run_in_target('addgroup', '--system', 'admin')
          self.run_in_target('adduser', self.vm.user, 'admin')
  
@@@ -145,7 -132,8 +154,7 @@@
          for group in ['adm', 'audio', 'cdrom', 'dialout', 'floppy', 'video', 'plugdev', 'dip', 'netdev', 'powerdev', 'lpadmin', 'scanner']:
              self.run_in_target('adduser', self.vm.user, group, ignore_fail=True)
  
 -        # Lock root account
 -        self.run_in_target('chpasswd', '-e', stdin='root:!\n')
 +        self.update_passwords()
  
      def kernel_name(self):
          return 'linux-image-%s' % (self.vm.flavour or self.default_flavour[self.vm.arch],)
@@@ -208,10 -196,6 +217,10 @@@
          # final vm is going to be on).
          self.run_in_target('apt-get', 'update', ignore_fail=final)
  
 +    def install_apt_proxy(self):
 +        if self.vm.proxy is not None:
 +            self.vm.install_file('/etc/apt/apt.conf', '// Proxy added by vmbuilder\nAcquire::http { Proxy "%s"; };' % self.vm.proxy)
 +
      def install_fstab(self):
          if self.vm.hypervisor.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE:
              self.install_from_template('/etc/fstab', 'dapper_fstab_fsimage', { 'fss' : disk.get_ordered_filesystems(self.vm), 'prefix' : self.disk_prefix })
@@@ -222,18 -206,12 +231,18 @@@
          self.install_from_template('/boot/grub/device.map', 'devicemap', { 'prefix' : self.disk_prefix })
  
      def debootstrap(self):
 -        cmd = ['/usr/sbin/debootstrap', '--arch=%s' % self.vm.arch, self.vm.suite, self.destdir, self.debootstrap_mirror()]
 -        run_cmd(*cmd)
 +        cmd = ['/usr/sbin/debootstrap', '--arch=%s' % self.vm.arch]
 +        if self.vm.variant:
 +            cmd += ['--variant=%s' % self.vm.variant]
 +        cmd += [self.vm.suite, self.destdir, self.debootstrap_mirror()]
 +        kwargs = { 'env' : { 'DEBIAN_FRONTEND' : 'noninteractive' } }
 +        if self.vm.proxy:
 +            kwargs['env']['http_proxy'] = self.vm.proxy
 +        run_cmd(*cmd, **kwargs)
      
      def debootstrap_mirror(self):
          if self.vm.iso:
 -            os.mkdir(isodir)
 +            isodir = tempfile.mkdtemp()
              self.vm.add_clean_cb(lambda:os.rmdir(isodir))
              run_cmd('mount', '-o', 'loop', '-t', 'iso9660', self.vm.iso, isodir)
              self.vm.add_clean_cmd('umount', isodir)
@@@ -289,7 -267,6 +298,7 @@@
          self.vm.distro.run_in_target(*args, **kwargs)
  
      def copy_to_target(self, infile, destpath):
 +        logging.debug("Copying %s on host to %s in guest" % (infile, destpath))
          dir = '%s/%s' % (self.destdir, os.path.dirname(destpath))
          if not os.path.isdir(dir):
              os.makedirs(dir)
@@@ -308,13 -285,9 +317,13 @@@
      def copy_settings(self):
          self.copy_to_target('/etc/default/locale', '/etc/default/locale')
          self.copy_to_target('/etc/timezone', '/etc/timezone')
 -        self.run_in_target('dpkg-reconfigure', '-pcritical', 'libc6')
 +        self.run_in_target('dpkg-reconfigure', '-fnoninteractive', '-pcritical', 'libc6')
          self.run_in_target('locale-gen', 'en_US')
          if self.vm.lang:
              self.run_in_target('locale-gen', self.vm.lang)
              self.install_from_template('/etc/default/locale', 'locale', { 'lang' : self.vm.lang })
 +        self.run_in_target('dpkg-reconfigure', '-fnoninteractive', '-pcritical', 'locales')
          self.run_in_target('dpkg-reconfigure', '-pcritical', 'locales')
 +
 +    def install_vmbuilder_log(self, logfile, rootdir):
 +        shutil.copy(logfile, '%s/var/log/vmbuilder-install.log' % (rootdir,))
diff --combined VMBuilder/plugins/ubuntu/hardy.py~
index 76b2f97,3ce1caf..3ce1caf
--- a/VMBuilder/plugins/ubuntu/hardy.py~
+++ b/VMBuilder/plugins/ubuntu/hardy.py~
@@@ -17,14 -17,25 +17,25 @@@
  #    You should have received a copy of the GNU General Public License
  #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  #
- import VMBuilder.suite as suite
+ import suite
+ import logging
+ import VMBuilder
+ from VMBuilder.util		    import run_cmd
  from VMBuilder.plugins.ubuntu.gutsy import Gutsy
  
  class Hardy(Gutsy):
      virtio_net = True
  
      def xen_kernel_path(self):
-         return '/boot/vmlinuz-2.6.24-19-xen'
+ 	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):
-         return '/boot/initrd.img-2.6.24-19-xen'
+ 	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 --combined VMBuilder/plugins/ubuntu/intrepid.py
index ee27598,5f9cabe..cc5bb98
--- a/VMBuilder/plugins/ubuntu/intrepid.py
+++ b/VMBuilder/plugins/ubuntu/intrepid.py
@@@ -17,9 -17,9 +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/>.
  #
 -import suite
  import logging
  import VMBuilder.disk as disk
 +import VMBuilder.suite as suite
  from   VMBuilder.util import run_cmd
  from   VMBuilder.plugins.ubuntu.hardy import Hardy
  
@@@ -35,3 -35,8 +35,8 @@@ class Intrepid(Hardy)
          run_cmd('sed', '-ie', 's/^# kopt=root=\([^ ]*\)\(.*\)/# kopt=root=UUID=%s\\2/g' % bootdev.fs.uuid, '%s/boot/grub/menu.lst' % self.destdir)
          run_cmd('sed', '-ie', 's/^# groot.*/# groot=%s/g' % bootdev.fs.uuid, '%s/boot/grub/menu.lst' % self.destdir)
          run_cmd('sed', '-ie', '/^# kopt_2_6/ d', '%s/boot/grub/menu.lst' % self.destdir)
+     def install_xen_kernel(self):
+ 	import VMBuilder.plugins.xen
+ 
+ 	if isinstance(self.vm.hypervisor, VMBuilder.plugins.xen.Xen):
+ 	   logging.info('Skipping Xen kernel installation.')
diff --combined VMBuilder/plugins/ubuntu/jaunty.py
index 50f9041,b800dec..edb8eee
--- a/VMBuilder/plugins/ubuntu/jaunty.py
+++ b/VMBuilder/plugins/ubuntu/jaunty.py
@@@ -17,9 -17,9 +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/>.
  #
 -import suite
  import logging
  import VMBuilder.disk as disk
 +import VMBuilder.suite as suite
  from   VMBuilder.util import run_cmd
  from   VMBuilder.plugins.ubuntu.intrepid import Intrepid
  
@@@ -32,13 -32,8 +32,18 @@@ class Jaunty(Intrepid)
          run_cmd('sed', '-ie', 's/^# groot.*/# groot=%s/g' % bootdev.fs.uuid, '%s/boot/grub/menu.lst' % self.destdir)
          run_cmd('sed', '-ie', '/^# kopt_2_6/ d', '%s/boot/grub/menu.lst' % self.destdir)
  
 +    def update_passwords(self):
 +        # Set the user password, using using defaults from /etc/login.defs (ie, no need to specify '-m')
 +        self.run_in_target('chpasswd', stdin=('%s:%s\n' % (self.vm.user, getattr(self.vm, 'pass'))))
 +
 +        # Lock root account only if we didn't set the root password
 +        if self.vm.rootpass:
 +            self.run_in_target('chpasswd', stdin=('%s:%s\n' % ('root', self.vm.rootpass)))
 +        else:
 +            self.run_in_target('chpasswd', '-e', stdin='root:!\n')
 +
+     def install_xen_kernel(self):
+ 	import VMBuilder.plugins.xen
+ 
+   	if isinstance(self.vm.hypervisor, VMBuilder.plugins.xen.Xen):
+ 	    logging.info('Skipping Xen kernel installation.')
diff --combined VMBuilder/plugins/ubuntu/jaunty.py~
index 50f9041,b800dec..2d368fd
--- a/VMBuilder/plugins/ubuntu/jaunty.py~
+++ b/VMBuilder/plugins/ubuntu/jaunty.py~
@@@ -17,9 -17,9 +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/>.
  #
 -import suite
  import logging
  import VMBuilder.disk as disk
 +import VMBuilder.suite as suite
  from   VMBuilder.util import run_cmd
  from   VMBuilder.plugins.ubuntu.intrepid import Intrepid
  
@@@ -32,13 -32,8 +32,21 @@@ class Jaunty(Intrepid)
          run_cmd('sed', '-ie', 's/^# groot.*/# groot=%s/g' % bootdev.fs.uuid, '%s/boot/grub/menu.lst' % self.destdir)
          run_cmd('sed', '-ie', '/^# kopt_2_6/ d', '%s/boot/grub/menu.lst' % self.destdir)
  
++<<<<<<< HEAD:VMBuilder/plugins/ubuntu/jaunty.py
 +    def update_passwords(self):
 +        # Set the user password, using using defaults from /etc/login.defs (ie, no need to specify '-m')
 +        self.run_in_target('chpasswd', stdin=('%s:%s\n' % (self.vm.user, getattr(self.vm, 'pass'))))
 +
 +        # Lock root account only if we didn't set the root password
 +        if self.vm.rootpass:
 +            self.run_in_target('chpasswd', stdin=('%s:%s\n' % ('root', self.vm.rootpass)))
 +        else:
 +            self.run_in_target('chpasswd', '-e', stdin='root:!\n')
 +
++=======
+     def install_xen_kernel(self):
+ 	import VMBuilder.plugins.xen
+ 
+   	if isinstance(self.vm.hypervisor, VMBuilder.plugins.xen.Xen):
+ 	    logging.info('Skipping Xen kernel installation.')
++>>>>>>> vmbuilder_ec2_patches:VMBuilder/plugins/ubuntu/jaunty.py
diff --combined VMBuilder/vm.py~
index ab116f5,a03f286..01b764e
--- a/VMBuilder/vm.py~
+++ b/VMBuilder/vm.py~
@@@ -29,7 -29,6 +29,7 @@@ import tempfil
  import textwrap
  import socket
  import struct
 +import urllib
  import VMBuilder
  import VMBuilder.util      as util
  import VMBuilder.log       as log
@@@ -91,8 -90,6 +91,11 @@@ class VM(object)
  
          self._register_base_settings()
  
++<<<<<<< HEAD:VMBuilder/vm.py
 +        self.add_clean_cmd('rm', log.logfile)
 +
++=======
++>>>>>>> vmbuilder_ec2_patches:VMBuilder/vm.py
      def get_version_info(self):
          import vcsversion
          info = vcsversion.version_info
@@@ -150,7 -147,7 +153,7 @@@
          self.register_setting('--cpus', type='int', default=1, help='Number of virtual CPU\'s. [default: %default]')
  
          group = self.setting_group('Network related options')
 -        domainname = '.'.join(socket.gethostbyname_ex(socket.gethostname())[0].split('.')[1:])
 +        domainname = '.'.join(socket.gethostbyname_ex(socket.gethostname())[0].split('.')[1:]) or "defaultdomain"
          group.add_option('--domain', metavar='DOMAIN', default=domainname, help='Set DOMAIN as the domain name of the guest [default: The domain of the machine running this script: %default].')
          group.add_option('--ip', metavar='ADDRESS', default='dhcp', help='IP address in dotted form [default: %default].')
          group.add_option('--mac', metavar='VALUE', help='MAC address of the guest [default: one will be automatically generated on first run].')
@@@ -247,7 -244,7 +250,7 @@@
          is called to give all the plugins and the distro and hypervisor plugin a chance to set
          some reasonable defaults, which the frontend then can inspect and present
          """
 -
 +        multiline_split = re.compile("\s*,\s*")
          if self.distro and self.hypervisor:
              for plugin in VMBuilder._plugins:
                  self.plugins.append(plugin(self))
@@@ -260,8 -257,7 +263,8 @@@
                  if confvalue:
                      if self.optparser.get_option('--%s' % k):
                          if self.optparser.get_option('--%s' % k).action == 'append':
 -                            setattr(self, k, confvalue.split(', '))
 +                            values = multiline_split.split(confvalue)
 +                            setattr(self, k, values)
                          else:
                              setattr(self, k, confvalue)
                      else:
@@@ -301,7 -297,7 +304,7 @@@
                  if (ipclass > 0) and (ipclass <= 127):
                      mask = 0xFF
                  elif (ipclass > 128) and (ipclass < 192):
 -                    mask = OxFFFF
 +                    mask = 0xFFFF
                  elif (ipclass < 224):
                      mask = 0xFFFFFF
                  else:
@@@ -416,8 -412,6 +419,8 @@@
              logging.info("Installing bootloader")
              self.distro.install_bootloader()
  
 +        self.distro.install_vmbuilder_log(log.logfile, self.rootmnt)
 +
      def preflight_check(self):
          for opt in sum([self.confparser.options(section) for section in self.confparser.sections()], []) + [k for (k,v) in self.confparser.defaults().iteritems()]:
              if '-' in opt:
@@@ -426,20 -420,6 +429,20 @@@
          self.ip_defaults()
          self.call_hooks('preflight_check')
  
 +        # Check repository availability
 +        if self.mirror:
 +            testurl = self.mirror
 +        else:
 +            testurl = 'http://archive.ubuntu.com/'
 +
 +        try:
 +            logging.debug('Testing access to %s' % testurl)
 +            testnet = urllib.urlopen(testurl)
 +        except IOError:
 +            raise VMBuilderUserError('Could not connect to %s. Please check your connectivity and try again.' % testurl)
 +
 +        testnet.close()
 +
      def install_file(self, path, contents=None, source=None, mode=None):
          fullpath = '%s%s' % (self.installdir, path)
          if source and not contents:

-- 
Tool for creating VM images.



More information about the Pkg-escience-soc2009 mailing list