Package VMBuilder :: Package plugins :: Package ubuntu :: Module distro
[frames] | no frames]

Source Code for Module VMBuilder.plugins.ubuntu.distro

  1  # 
  2  #    Uncomplicated VM Builder 
  3  #    Copyright (C) 2007-2008 Canonical Ltd. 
  4  #     
  5  #    See AUTHORS for list of contributors 
  6  # 
  7  #    This program is free software: you can redistribute it and/or modify 
  8  #    it under the terms of the GNU General Public License as published by 
  9  #    the Free Software Foundation, either version 3 of the License, or 
 10  #    (at your option) any later version. 
 11  # 
 12  #    This program is distributed in the hope that it will be useful, 
 13  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 15  #    GNU General Public License for more details. 
 16  # 
 17  #    You should have received a copy of the GNU General Public License 
 18  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 19  # 
 20  import VMBuilder 
 21  from   VMBuilder           import register_distro, Distro 
 22  from   VMBuilder.util      import run_cmd 
 23  from   VMBuilder.exception import VMBuilderUserError 
 24  import socket 
 25  import logging 
 26  import types 
 27   
28 -class Ubuntu(Distro):
29 name = 'Ubuntu' 30 arg = 'ubuntu' 31 suites = ['dapper', 'feisty', 'gutsy', 'hardy', 'intrepid'] 32 33 # Maps host arch to valid guest archs 34 valid_archs = { 'amd64' : ['amd64', 'i386', 'lpia' ], 35 'i386' : [ 'i386', 'lpia' ], 36 'lpia' : [ 'i386', 'lpia' ] } 37 38
39 - def __init__(self, vm):
40 self.vm = vm 41 self.register_settings()
42
43 - def register_settings(self):
44 group = self.vm.setting_group('Package options') 45 group.add_option('--addpkg', action='append', metavar='PKG', help='Install PKG into the guest (can be specfied multiple times).') 46 group.add_option('--removepkg', action='append', metavar='PKG', help='Remove PKG from the guest (can be specfied multiple times)') 47 self.vm.register_setting_group(group) 48 49 group = self.vm.setting_group('General OS options') 50 self.host_arch = run_cmd('dpkg-architecture', '-qDEB_HOST_ARCH').rstrip() 51 group.add_option('-a', '--arch', default=self.host_arch, help='Specify the target architecture. Valid options: amd64 i386 lpia (defaults to host arch)') 52 group.add_option('--hostname', default='ubuntu', help='Set NAME as the hostname of the guest. Default: ubuntu. Also uses this name as the VM name.') 53 self.vm.register_setting_group(group) 54 55 group = self.vm.setting_group('Installation options') 56 group.add_option('--suite', default='intrepid', help='Suite to install. Valid options: %s [default: %%default]' % ' '.join(self.suites)) 57 group.add_option('--flavour', '--kernel-flavour', help='Kernel flavour to use. Default and valid options depend on architecture and suite') 58 group.add_option('--iso', metavar='PATH', help='Use an iso image as the source for installation of file. Full path to the iso must be provided. If --mirror is also provided, it will be used in the final sources.list of the vm. This requires suite and kernel parameter to match what is available on the iso, obviously.') 59 group.add_option('--mirror', metavar='URL', help='Use Ubuntu mirror at URL instead of the default, which is http://archive.ubuntu.com/ubuntu for official arches and http://ports.ubuntu.com/ubuntu-ports otherwise') 60 group.add_option('--components', metavar='COMPS', help='A comma seperated list of distro components to include (e.g. main,universe).') 61 group.add_option('--ppa', metavar='PPA', action='append', help='Add ppa belonging to PPA to the vm\'s sources.list.') 62 self.vm.register_setting_group(group) 63 64 group = self.vm.setting_group('Settings for the initial user') 65 group.add_option('--user', default='ubuntu', help='Username of initial user [default: %default]') 66 group.add_option('--name', default='Ubuntu', help='Full name of initial user [default: %default]') 67 group.add_option('--pass', default='ubuntu', help='Password of initial user [default: %default]') 68 self.vm.register_setting_group(group) 69 70 group = self.vm.setting_group('Other options') 71 group.add_option('--ssh-key', metavar='PATH', help='Add PATH to root\'s ~/.ssh/authorized_keys (WARNING: this has strong security implications).') 72 group.add_option('--ssh-user-key', help='Add PATH to the user\'s ~/.ssh/authorized_keys.') 73 self.vm.register_setting_group(group)
74
75 - def set_defaults(self):
76 if not self.vm.mirror: 77 if self.vm.arch == 'lpia': 78 self.vm.mirror = 'http://ports.ubuntu.com/ubuntu-ports' 79 else: 80 self.vm.mirror = 'http://archive.ubuntu.com/ubuntu' 81 82 if not self.vm.components: 83 self.vm.components = ['main', 'restricted', 'universe'] 84 else: 85 self.vm.components = self.vm.components.split(',')
86
87 - def preflight_check(self):
88 """While not all of these are strictly checks, their failure would inevitably 89 lead to failure, and since we can check them before we start setting up disk 90 and whatnot, we might as well go ahead an do this now.""" 91 92 if not self.vm.suite in self.suites: 93 raise VMBuilderUserError('Invalid suite. Valid suites are: %s' % ' '.join(self.suites)) 94 95 modname = 'VMBuilder.plugins.ubuntu.%s' % (self.vm.suite, ) 96 mod = __import__(modname, fromlist=[self.vm.suite]) 97 self.suite = getattr(mod, self.vm.suite.capitalize())(self.vm) 98 99 if self.vm.arch not in self.valid_archs[self.host_arch] or \ 100 not self.suite.check_arch_validity(self.vm.arch): 101 raise VMBuilderUserError('%s is not a valid architecture. Valid architectures are: %s' % (self.vm.arch, 102 ' '.join(self.valid_archs[self.host_arch]))) 103 104 if not self.vm.components: 105 self.vm.components = ['main', 'restricted', 'universe'] 106 else: 107 if type(self.vm.components) is str: 108 self.vm.components = self.vm.components.split(',')
109
110 - def install(self, destdir):
111 self.destdir = destdir 112 113 self.xen_kernel_path = getattr(self.suite, 'xen_kernel_path', lambda : None) 114 self.xen_ramdisk_path = getattr(self.suite, 'xen_ramdisk_path', lambda: None) 115 116 self.suite.install(destdir)
117
118 - def post_mount(self, fs):
119 self.suite.post_mount(fs)
120
121 - def install_bootloader(self):
122 devmapfile = '%s/device.map' % self.vm.workdir 123 devmap = open(devmapfile, 'w') 124 for (disk, id) in zip(self.vm.disks, range(len(self.vm.disks))): 125 devmap.write("(hd%d) %s\n" % (id, disk.filename)) 126 devmap.close() 127 run_cmd('grub', '--device-map=%s' % devmapfile, '--batch', stdin='''root (hd0,0) 128 setup (hd0) 129 EOT''')
130 131 register_distro(Ubuntu) 132