Revision f5174d2c image_creator/main.py
b/image_creator/main.py | ||
---|---|---|
38 | 38 |
from image_creator.util import FatalError, MD5 |
39 | 39 |
from image_creator.output.cli import SilentOutput, SimpleOutput, \ |
40 | 40 |
OutputWthProgress |
41 |
from image_creator.os_type import os_cls |
|
42 | 41 |
from image_creator.kamaki_wrapper import Kamaki, ClientError |
43 | 42 |
import sys |
44 | 43 |
import os |
... | ... | |
205 | 204 |
try: |
206 | 205 |
snapshot = disk.snapshot() |
207 | 206 |
|
208 |
dev = disk.get_device(snapshot)
|
|
207 |
image = disk.get_image(snapshot)
|
|
209 | 208 |
|
210 | 209 |
# If no customization is to be applied, the image should be mounted ro |
211 |
readonly = (not (options.sysprep or options.shrink) or |
|
212 |
options.print_sysprep) |
|
213 |
dev.mount(readonly) |
|
214 |
|
|
215 |
cls = os_cls(dev.distro, dev.ostype) |
|
216 |
image_os = cls(dev.root, dev.g, out) |
|
217 |
out.output() |
|
218 |
|
|
219 |
for sysprep in options.disabled_syspreps: |
|
220 |
image_os.disable_sysprep(image_os.get_sysprep_by_name(sysprep)) |
|
210 |
ro = (not (options.sysprep or options.shrink) or options.print_sysprep) |
|
211 |
image.mount(ro) |
|
212 |
try: |
|
213 |
for sysprep in options.disabled_syspreps: |
|
214 |
image.os.disable_sysprep(image.os.get_sysprep_by_name(sysprep)) |
|
221 | 215 |
|
222 |
for sysprep in options.enabled_syspreps: |
|
223 |
image_os.enable_sysprep(image_os.get_sysprep_by_name(sysprep))
|
|
216 |
for sysprep in options.enabled_syspreps:
|
|
217 |
image.os.enable_sysprep(image.os.get_sysprep_by_name(sysprep))
|
|
224 | 218 |
|
225 |
if options.print_sysprep: |
|
226 |
image_os.print_syspreps()
|
|
227 |
out.output() |
|
219 |
if options.print_sysprep:
|
|
220 |
image.os.print_syspreps()
|
|
221 |
out.output()
|
|
228 | 222 |
|
229 |
if options.outfile is None and not options.upload: |
|
230 |
return 0 |
|
223 |
if options.outfile is None and not options.upload:
|
|
224 |
return 0
|
|
231 | 225 |
|
232 |
if options.sysprep: |
|
233 |
image_os.do_sysprep()
|
|
226 |
if options.sysprep:
|
|
227 |
image.os.do_sysprep()
|
|
234 | 228 |
|
235 |
metadata = image_os.meta |
|
236 |
dev.umount() |
|
229 |
metadata = image.os.meta |
|
230 |
finally: |
|
231 |
image.umount() |
|
237 | 232 |
|
238 |
size = options.shrink and dev.shrink() or dev.size
|
|
239 |
metadata.update(dev.meta)
|
|
233 |
size = options.shrink and image.shrink() or image.size
|
|
234 |
metadata.update(image.meta)
|
|
240 | 235 |
|
241 | 236 |
# Add command line metadata to the collected ones... |
242 | 237 |
metadata.update(options.metadata) |
243 | 238 |
|
244 | 239 |
md5 = MD5(out) |
245 |
checksum = md5.compute(snapshot, size)
|
|
240 |
checksum = md5.compute(image.device, size)
|
|
246 | 241 |
|
247 | 242 |
metastring = '\n'.join( |
248 | 243 |
['%s=%s' % (key, value) for (key, value) in metadata.items()]) |
249 | 244 |
metastring += '\n' |
250 | 245 |
|
251 | 246 |
if options.outfile is not None: |
252 |
dev.dump(options.outfile)
|
|
247 |
image.dump(options.outfile)
|
|
253 | 248 |
|
254 | 249 |
out.output('Dumping metadata file ...', False) |
255 | 250 |
with open('%s.%s' % (options.outfile, 'meta'), 'w') as f: |
... | ... | |
262 | 257 |
os.path.basename(options.outfile))) |
263 | 258 |
out.success('done') |
264 | 259 |
|
265 |
# Destroy the device. We only need the snapshot from now on
|
|
266 |
disk.destroy_device(dev)
|
|
260 |
# Destroy the image instance. We only need the snapshot from now on
|
|
261 |
disk.destroy_image(image)
|
|
267 | 262 |
|
268 | 263 |
out.output() |
269 | 264 |
try: |
Also available in: Unified diff