1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
29 name = 'Ubuntu'
30 arg = 'ubuntu'
31 suites = ['dapper', 'feisty', 'gutsy', 'hardy', 'intrepid']
32
33
34 valid_archs = { 'amd64' : ['amd64', 'i386', 'lpia' ],
35 'i386' : [ 'i386', 'lpia' ],
36 'lpia' : [ 'i386', 'lpia' ] }
37
38
42
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
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
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
117
118 - def post_mount(self, fs):
120
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