106
106
if store.isValidStore(fetcher, progresscb):
109
raise ValueError, _("Could not find an installable distribution at '%s'" %
110
_("Could not find an installable distribution at '%s'\n"
111
"The location must be the root directory of an install tree." %
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
121
fetcher.prepareLocation()
118
122
except ValueError, e:
119
raise ValueError, _("Invalid install location: ") + str(e)
123
raise ValueError(_("Invalid install location: ") + str(e))
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,
127
# FIXME: We should probably do this for both kernel and boot
129
os_type, os_variant = store.get_osdict_info()
130
return (store.acquireKernel(guest, fetcher, progresscb),
132
elif iskernel is False:
133
return store.acquireBootDisk(fetcher, progresscb)
135
# Kind of a hack. Just return the store for detectDistro
130
return callback(store, fetcher)
138
132
fetcher.cleanupLocation()
134
def _acquireMedia(iskernel, guest, baseuri, progresscb,
135
scratchdir="/var/tmp", _type=None):
137
def media_cb(store, fetcher):
138
os_type, os_variant = store.get_osdict_info()
142
media = store.acquireKernel(guest, fetcher, progresscb)
144
media = store.acquireBootDisk(guest, fetcher, progresscb)
146
return [store, os_type, os_variant, media]
148
return _locationCheckWrapper(guest, baseuri, progresscb, scratchdir, _type,
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):
154
return _acquireMedia(iskernel, guest, baseuri, progresscb,
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):
160
return _acquireMedia(iskernel, guest, baseuri, progresscb,
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))
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"]))
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()
176
scratchdir = "/var/tmp"
178
def media_cb(store, ignore):
181
store = _locationCheckWrapper(guest, baseuri, progresscb, scratchdir,
182
_type, arch, media_cb)
163
184
return store.get_osdict_info()