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

« back to all changes in this revision

Viewing changes to virtinst/OSDistro.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:
28
28
import ConfigParser
29
29
 
30
30
import virtinst
31
 
from virtinst.Guest import Guest
 
31
import osdict
32
32
from virtinst import _util
33
33
from virtinst import _virtinst as _
34
34
 
106
106
        if store.isValidStore(fetcher, progresscb):
107
107
            return store
108
108
 
109
 
    raise ValueError, _("Could not find an installable distribution at '%s'" %
110
 
                        baseuri)
 
109
    raise ValueError(
 
110
        _("Could not find an installable distribution at '%s'\n"
 
111
          "The location must be the root directory of an install tree." %
 
112
          baseuri))
111
113
 
112
 
def _acquireMedia(iskernel, guest, baseuri, progresscb, arch,
113
 
                  scratchdir="/var/tmp", _type=None, distro=None):
 
114
def _locationCheckWrapper(guest, baseuri, progresscb,
 
115
                          scratchdir, _type, arch, callback):
114
116
    fetcher = _fetcherForURI(baseuri, scratchdir)
 
117
    if guest:
 
118
        arch = guest.arch
115
119
 
116
120
    try:
117
121
        fetcher.prepareLocation()
118
122
    except ValueError, e:
119
 
        raise ValueError, _("Invalid install location: ") + str(e)
 
123
        raise ValueError(_("Invalid install location: ") + str(e))
120
124
 
121
125
    try:
122
126
        store = _storeForDistro(fetcher=fetcher, baseuri=baseuri, typ=_type,
123
 
                                progresscb=progresscb, distro=distro,
124
 
                                scratchdir=scratchdir, arch=arch)
 
127
                                progresscb=progresscb, scratchdir=scratchdir,
 
128
                                arch=arch)
125
129
 
126
 
        if iskernel is True:
127
 
            # FIXME: We should probably do this for both kernel and boot
128
 
            # disk?
129
 
            os_type, os_variant = store.get_osdict_info()
130
 
            return (store.acquireKernel(guest, fetcher, progresscb),
131
 
                    os_type, os_variant)
132
 
        elif iskernel is False:
133
 
            return store.acquireBootDisk(fetcher, progresscb)
134
 
        else:
135
 
            # Kind of a hack. Just return the store for detectDistro
136
 
            return store
 
130
        return callback(store, fetcher)
137
131
    finally:
138
132
        fetcher.cleanupLocation()
139
133
 
 
134
def _acquireMedia(iskernel, guest, baseuri, progresscb,
 
135
                  scratchdir="/var/tmp", _type=None):
 
136
 
 
137
    def media_cb(store, fetcher):
 
138
        os_type, os_variant = store.get_osdict_info()
 
139
        media = None
 
140
 
 
141
        if iskernel:
 
142
            media = store.acquireKernel(guest, fetcher, progresscb)
 
143
        else:
 
144
            media = store.acquireBootDisk(guest, fetcher, progresscb)
 
145
 
 
146
        return [store, os_type, os_variant, media]
 
147
 
 
148
    return _locationCheckWrapper(guest, baseuri, progresscb, scratchdir, _type,
 
149
                                 None, media_cb)
 
150
 
140
151
# Helper method to lookup install media distro and fetch an install kernel
141
 
def acquireKernel(guest, baseuri, progresscb, arch,
142
 
                  scratchdir="/var/tmp", type=None, distro=None):
143
 
    return _acquireMedia(True, guest, baseuri, progresscb, arch,
144
 
                         scratchdir, type, distro)
 
152
def acquireKernel(guest, baseuri, progresscb, scratchdir, type=None):
 
153
    iskernel = True
 
154
    return _acquireMedia(iskernel, guest, baseuri, progresscb,
 
155
                         scratchdir, type)
145
156
 
146
157
# Helper method to lookup install media distro and fetch a boot iso
147
 
def acquireBootDisk(baseuri, progresscb, arch, scratchdir="/var/tmp",
148
 
                    type=None, distro=None):
149
 
    return _acquireMedia(False, None, baseuri, progresscb, arch,
150
 
                         scratchdir, type, distro)
 
158
def acquireBootDisk(guest, baseuri, progresscb, scratchdir, type=None):
 
159
    iskernel = False
 
160
    return _acquireMedia(iskernel, guest, baseuri, progresscb,
 
161
                         scratchdir, type)
151
162
 
152
163
def _check_ostype_valid(os_type):
153
 
    return bool(os_type in Guest.list_os_types())
 
164
    return bool(os_type in osdict.sort_helper(osdict.OS_TYPES))
 
165
 
154
166
def _check_osvariant_valid(os_type, os_variant):
155
167
    return bool(_check_ostype_valid(os_type) and
156
 
                os_variant in Guest.list_os_variants(os_type))
 
168
        os_variant in osdict.sort_helper(osdict.OS_TYPES[os_type]["variants"]))
157
169
 
158
170
# Attempt to detect the os type + variant for the passed location
159
171
def detectMediaDistro(location, arch):
160
172
    import urlgrabber
161
 
    progress = urlgrabber.progress.BaseMeter()
162
 
    store = _acquireMedia(None, None, location, progress, arch, "/var/tmp")
 
173
    progresscb = urlgrabber.progress.BaseMeter()
 
174
    guest = None
 
175
    baseuri = location
 
176
    scratchdir = "/var/tmp"
 
177
    _type = None
 
178
    def media_cb(store, ignore):
 
179
        return store
 
180
 
 
181
    store = _locationCheckWrapper(guest, baseuri, progresscb, scratchdir,
 
182
                                  _type, arch, media_cb)
 
183
 
163
184
    return store.get_osdict_info()
164
185
 
165
186
 
254
275
        return self._kernelFetchHelper(fetcher, guest, progresscb, kernelpath,
255
276
                                       initrdpath)
256
277
 
257
 
    def acquireBootDisk(self, fetcher, progresscb):
 
278
    def acquireBootDisk(self, guest, fetcher, progresscb):
258
279
        if self._hasTreeinfo(fetcher, progresscb):
259
280
            return fetcher.acquireFile(self._getTreeinfoMedia("boot.iso"),
260
281
                                       progresscb)
432
453
                                       self._valid_kernel_path[0],
433
454
                                       self._valid_kernel_path[1])
434
455
 
435
 
    def acquireBootDisk(self, fetcher, progresscb):
 
456
    def acquireBootDisk(self, guest, fetcher, progresscb):
436
457
        if self._valid_iso_path == None:
437
458
            raise ValueError(_("Could not find a boot iso path for this tree."))
438
459
 
482
503
            return False
483
504
 
484
505
    def _latestFedoraVariant(self):
485
 
        import osdict
486
506
        ret = None
487
507
        for var in osdict.sort_helper(osdict.OS_TYPES["linux"]["variants"]):
488
508
            if var.startswith("fedora"):
515
535
                self.os_variant = "rhel5"
516
536
                return True
517
537
            if fetcher.hasFile("RedHat"):
518
 
                logging.debug("Detected a RHEL 4 distro")
519
 
                self.os_variant = "rhel4"
 
538
                if fetcher.hasFile("dosutils"):
 
539
                    self.os_variant = "rhel3"
 
540
                else:
 
541
                    self.os_variant = "rhel4"
 
542
 
 
543
                logging.debug("Detected a %s distro" % self.os_variant)
520
544
                return True
521
545
            return False
522
546
 
699
723
    # install-initrd RPM entries - capturing the directory they are
700
724
    # in and the version'd filename.
701
725
    def _extractRPMNames(self, filelist):
702
 
        filelistData = gzip.GzipFile(filelist, mode = "r")
 
726
        filelistData = gzip.GzipFile(filelist, mode="r")
703
727
        try:
704
728
            arches = [self.arch]
705
729
            # On i686 arch, we also look under i585 and i386 dirs
796
820
                    line = fn.readline()
797
821
                    if not line:
798
822
                        break
799
 
                    line = line[:len(line)-1]
 
823
                    line = line[:len(line) - 1]
800
824
                    modnames.append(line)
801
825
            finally:
802
826
                fn.close()
822
846
 
823
847
            # Copy modules we need into initrd staging dir
824
848
            for modname in modnames:
825
 
                if modpaths.has_key(modname):
 
849
                if modname in modpaths:
826
850
                    src = modpaths[modname]
827
851
                    dst = moddir + "/" + modname
828
852
                    os.system("cp " + src + " " + dst)
982
1006
        """Determine if uri points to a tree of the store's distro"""
983
1007
        raise NotImplementedError
984
1008
 
985
 
    def acquireBootDisk(self, fetcher, progresscb):
 
1009
    def acquireBootDisk(self, guest, fetcher, progresscb):
986
1010
        return fetcher.acquireFile("images/solarisdvd.iso", progresscb)
987
1011
 
988
1012
    def process_extra_args(self, argstr):
1008
1032
                    Bargs = args[i]
1009
1033
                else:
1010
1034
                    Bargs = ','.join([Bargs, args[i]])
1011
 
        
 
1035
 
1012
1036
            elif exarg == '-m':
1013
1037
                i += 1
1014
1038
                if i == len(args):
1121
1145
class OpenSolarisDistro(SunDistro):
1122
1146
 
1123
1147
    os_variant = "opensolaris"
1124
 
 
 
1148
 
1125
1149
    kernelpath = "platform/i86xpv/kernel/unix"
1126
1150
    initrdpaths = [ "platform/i86pc/boot_archive", "boot/x86.microroot" ]
1127
1151