Revision 789a3763 image_creator/dialog_wizard.py
b/image_creator/dialog_wizard.py | ||
---|---|---|
213 | 213 |
image_os = session['image_os'] |
214 | 214 |
wizard = session['wizard'] |
215 | 215 |
|
216 |
out = OutputWthProgress(True) |
|
217 |
#Initialize the output |
|
218 |
disk.out = out |
|
219 |
device.out = out |
|
220 |
image_os.out = out |
|
221 |
|
|
222 |
out.clear() |
|
223 |
|
|
224 |
#Sysprep |
|
225 |
device.mount(False) |
|
226 |
image_os.do_sysprep() |
|
227 |
metadata = image_os.meta |
|
228 |
device.umount() |
|
216 |
with_progress = OutputWthProgress(True) |
|
217 |
out = disk.out |
|
218 |
out.add(with_progress) |
|
219 |
try: |
|
220 |
out.clear() |
|
229 | 221 |
|
230 |
#Shrink |
|
231 |
size = device.shrink() |
|
222 |
#Sysprep |
|
223 |
device.mount(False) |
|
224 |
image_os.do_sysprep() |
|
225 |
metadata = image_os.meta |
|
226 |
device.umount() |
|
232 | 227 |
|
233 |
metadata.update(device.meta)
|
|
234 |
metadata['DESCRIPTION'] = wizard['ImageDescription']
|
|
228 |
#Shrink
|
|
229 |
size = device.shrink()
|
|
235 | 230 |
|
236 |
#MD5 |
|
237 |
md5 = MD5(out) |
|
238 |
session['checksum'] = md5.compute(snapshot, size) |
|
231 |
metadata.update(device.meta) |
|
232 |
metadata['DESCRIPTION'] = wizard['ImageDescription'] |
|
239 | 233 |
|
240 |
#Metadata |
|
241 |
metastring = '\n'.join( |
|
242 |
['%s=%s' % (key, value) for (key, value) in metadata.items()]) |
|
243 |
metastring += '\n' |
|
234 |
#MD5 |
|
235 |
md5 = MD5(out) |
|
236 |
session['checksum'] = md5.compute(snapshot, size) |
|
244 | 237 |
|
245 |
out.output() |
|
246 |
try: |
|
247 |
out.output("Uploading image to pithos:") |
|
248 |
kamaki = Kamaki(wizard['account'], wizard['token'], out) |
|
249 |
|
|
250 |
name = "%s-%s.diskdump" % (wizard['ImageName'], |
|
251 |
time.strftime("%Y%m%d%H%M")) |
|
252 |
pithos_file = "" |
|
253 |
with open(snapshot, 'rb') as f: |
|
254 |
pithos_file = kamaki.upload(f, size, name, |
|
255 |
"(1/4) Calculating block hashes", |
|
256 |
"(2/4) Uploading missing blocks") |
|
257 |
|
|
258 |
out.output("(3/4) Uploading metadata file...", False) |
|
259 |
kamaki.upload(StringIO.StringIO(metastring), size=len(metastring), |
|
260 |
remote_path="%s.%s" % (name, 'meta')) |
|
261 |
out.success('done') |
|
262 |
out.output("(4/4) Uploading md5sum file...", False) |
|
263 |
md5sumstr = '%s %s\n' % (session['checksum'], name) |
|
264 |
kamaki.upload(StringIO.StringIO(md5sumstr), size=len(md5sumstr), |
|
265 |
remote_path="%s.%s" % (name, 'md5sum')) |
|
266 |
out.success('done') |
|
267 |
out.output() |
|
238 |
#Metadata |
|
239 |
metastring = '\n'.join( |
|
240 |
['%s=%s' % (key, value) for (key, value) in metadata.items()]) |
|
241 |
metastring += '\n' |
|
268 | 242 |
|
269 |
out.output('Registring image to ~okeanos...', False) |
|
270 |
kamaki.register(wizard['ImageName'], pithos_file, metadata) |
|
271 |
out.success('done') |
|
272 | 243 |
out.output() |
273 |
|
|
274 |
except ClientError as e: |
|
275 |
raise FatalError("Pithos client: %d %s" % (e.status, e.message)) |
|
244 |
try: |
|
245 |
out.output("Uploading image to pithos:") |
|
246 |
kamaki = Kamaki(wizard['account'], wizard['token'], out) |
|
247 |
|
|
248 |
name = "%s-%s.diskdump" % (wizard['ImageName'], |
|
249 |
time.strftime("%Y%m%d%H%M")) |
|
250 |
pithos_file = "" |
|
251 |
with open(snapshot, 'rb') as f: |
|
252 |
pithos_file = kamaki.upload(f, size, name, |
|
253 |
"(1/4) Calculating block hashes", |
|
254 |
"(2/4) Uploading missing blocks") |
|
255 |
|
|
256 |
out.output("(3/4) Uploading metadata file...", False) |
|
257 |
kamaki.upload(StringIO.StringIO(metastring), size=len(metastring), |
|
258 |
remote_path="%s.%s" % (name, 'meta')) |
|
259 |
out.success('done') |
|
260 |
out.output("(4/4) Uploading md5sum file...", False) |
|
261 |
md5sumstr = '%s %s\n' % (session['checksum'], name) |
|
262 |
kamaki.upload(StringIO.StringIO(md5sumstr), size=len(md5sumstr), |
|
263 |
remote_path="%s.%s" % (name, 'md5sum')) |
|
264 |
out.success('done') |
|
265 |
out.output() |
|
266 |
|
|
267 |
out.output('Registring image to ~okeanos...', False) |
|
268 |
kamaki.register(wizard['ImageName'], pithos_file, metadata) |
|
269 |
out.success('done') |
|
270 |
out.output() |
|
271 |
|
|
272 |
except ClientError as e: |
|
273 |
raise FatalError("Pithos client: %d %s" % (e.status, e.message)) |
|
274 |
finally: |
|
275 |
out.remove(with_progress) |
|
276 | 276 |
|
277 | 277 |
msg = "The image was successfully uploaded and registered to " \ |
278 | 278 |
"~okeanos. Would you like to keep a local copy of the image?" |
Also available in: Unified diff