~ubuntu-branches/ubuntu/quantal/virtinst/quantal-proposed

« back to all changes in this revision

Viewing changes to virtinst/ImageInstaller.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-02-01 15:40:11 UTC
  • mfrom: (1.3.16 experimental)
  • Revision ID: james.westby@ubuntu.com-20110201154011-op0nusgc240xajvb
Tags: 0.500.5-1ubuntu1
* Merge from debian experimental. Remaining changes:
  - debian/patches/9001_Ubuntu.patch:
     + Updated to add maverick and natty to OS list and enable virtio
       for them.
  - debian/patches/9003-fix-path-to-hvmloader-in-testsuite.patch: adjust
    testsuite for 0001-fix-path-to-hvmloader.patch and
    0002-Fix-path-to-pygrub.patch. (refreshed)
  - debian/control: added acl package to depends.
  - Demote virt-viewer to Suggests, as it's in universe.
  - Recommends libvirt-bin
* Removed patches:
  - debian/patches/9002-libvirt_disk_format.patch: Upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
class ImageInstaller(Installer.Installer):
34
34
    """Installer for image-based guests"""
35
35
    def __init__(self, image, capabilities=None, boot_index=None, conn=None):
36
 
        Installer.Installer.__init__(self, conn=conn)
 
36
        Installer.Installer.__init__(self, conn=conn, caps=capabilities)
37
37
 
38
38
        self._arch = None
39
39
        self._image = image
40
40
 
41
 
        # Set capabilities
42
 
        if self.conn:
43
 
            self._capabilities = Cap.parse(self.conn.getCapabilities())
44
 
        elif capabilities:
45
 
            if not isinstance(capabilities, Cap.Capabilities):
46
 
                raise ValueError(_("'capabilities' must be a "
47
 
                                   "Capabilities instance."))
48
 
            self._capabilities = capabilities
49
 
        else:
 
41
        if not (self.conn or self._get_caps()):
50
42
            raise ValueError(_("'conn' or 'capabilities' must be specified."))
51
43
 
52
44
        # Set boot _boot_caps/_boot_parameters
53
45
        if boot_index is None:
54
 
            self._boot_caps = match_boots(self._capabilities,
 
46
            self._boot_caps = match_boots(self._get_caps(),
55
47
                                     self.image.domain.boots)
56
48
            if self._boot_caps is None:
57
49
                raise ImageInstallerException(_("Could not find suitable boot "
63
55
            self._boot_caps = image.domain.boots[boot_index]
64
56
 
65
57
        # Set up internal caps.guest object
66
 
        self._guest = self._capabilities.guestForOSType(self.boot_caps.type,
67
 
                                                        self.boot_caps.arch)
 
58
        self._guest = self._get_caps().guestForOSType(self.boot_caps.type,
 
59
                                                      self.boot_caps.arch)
68
60
        if self._guest is None:
69
61
            raise PlatformMatchException(_("Unsupported virtualization type: "
70
62
                                           "%s %s" % (self.boot_caps.type,
94
86
 
95
87
    # General Installer methods
96
88
 
97
 
    def prepare(self, guest, meter, distro = None):
98
 
        self._make_disks(guest)
 
89
    def prepare(self, guest, meter):
 
90
        self.cleanup()
 
91
 
 
92
        self._make_disks()
99
93
 
100
94
        for f in ['pae', 'acpi', 'apic']:
101
95
            if self.boot_caps.features[f] & Cap.FEATURE_ON:
103
97
            elif self.boot_caps.features[f] & Cap.FEATURE_OFF:
104
98
                guest.features[f] = False
105
99
 
106
 
    def get_install_xml(self, guest, isinstall):
107
 
 
108
 
        kernel = { "kernel" : self.boot_caps.kernel,
109
 
                   "initrd" : self.boot_caps.initrd,
110
 
                   "extrargs" : self.boot_caps.cmdline }
111
 
 
112
 
        if self.boot_caps.kernel:
113
 
            isinstall = True
114
 
        else:
115
 
            isinstall = False
116
 
 
117
 
        # FYI: self.boot_caps.loader is _not_ analagous to guest loader tag
118
 
 
119
 
        return self._get_osblob_helper(guest, isinstall=isinstall,
120
 
                                       kernel=kernel,
121
 
                                       bootdev=self.boot_caps.bootdev)
 
100
        self.bootconfig.kernel = self.boot_caps.kernel
 
101
        self.bootconfig.initrd = self.boot_caps.initrd
 
102
        self.bootconfig.kernel_args = self.boot_caps.cmdline
122
103
 
123
104
    def post_install_check(self, guest):
124
105
        return True
125
106
 
 
107
    def has_install_phase(self):
 
108
        return False
126
109
 
127
110
    # Private methods
 
111
    def _get_bootdev(self, isinstall, guest):
 
112
        return self.boot_caps.bootdev
128
113
 
129
 
    def _make_disks(self, guest):
130
 
        for m in self.boot_caps.drives:
131
 
            p = self._abspath(m.disk.file)
132
 
            s = None
133
 
            if m.disk.size is not None:
134
 
                s = float(m.disk.size)/1024
 
114
    def _make_disks(self):
 
115
        for drive in self.boot_caps.drives:
 
116
            path = self._abspath(drive.disk.file)
 
117
            size = None
 
118
            if drive.disk.size is not None:
 
119
                size = float(drive.disk.size) / 1024
135
120
 
136
121
            # FIXME: This is awkward; the image should be able to express
137
122
            # whether the disk is expected to be there or not independently
138
123
            # of its classification, especially for user disks
139
124
            # FIXME: We ignore the target for the mapping in m.target
140
 
            if (m.disk.use == ImageParser.Disk.USE_SYSTEM and
141
 
                not os.path.exists(p)):
 
125
            if (drive.disk.use == ImageParser.Disk.USE_SYSTEM and
 
126
                not os.path.exists(path)):
142
127
                raise ImageInstallerException(_("System disk %s does not exist")
143
 
                                              % p)
 
128
                                              % path)
 
129
 
144
130
            device = VirtualDisk.DEVICE_DISK
145
 
            if m.disk.format == ImageParser.Disk.FORMAT_ISO:
 
131
            if drive.disk.format == ImageParser.Disk.FORMAT_ISO:
146
132
                device = VirtualDisk.DEVICE_CDROM
147
 
            d = VirtualDisk(p, s,
148
 
                            device = device,
149
 
                            type = VirtualDisk.TYPE_FILE)
150
 
            d.target = m.target
151
 
 
152
 
            guest._add_install_dev(d)
 
133
 
 
134
 
 
135
            disk = VirtualDisk(conn=self.conn,
 
136
                               path=path,
 
137
                               size=size,
 
138
                               device=device,
 
139
                               format=drive.disk.format)
 
140
            disk.target = drive.target
 
141
 
 
142
            self.install_devices.append(disk)
153
143
 
154
144
    def _abspath(self, p):
155
145
        return self.image.abspath(p)