Revision 8e58e699
b/image_creator/dialog_menu.py | ||
---|---|---|
40 | 40 |
import os |
41 | 41 |
import textwrap |
42 | 42 |
import StringIO |
43 |
import json |
|
43 | 44 |
|
44 | 45 |
from image_creator import __version__ as version |
45 | 46 |
from image_creator.util import MD5, FatalError |
... | ... | |
249 | 250 |
try: |
250 | 251 |
out.output("Registering %s image with Cyclades..." % img_type) |
251 | 252 |
kamaki = Kamaki(session['account'], out) |
252 |
kamaki.register(name, session['pithos_uri'], metadata, |
|
253 |
is_public) |
|
253 |
result = kamaki.register(name, session['pithos_uri'], metadata,
|
|
254 |
is_public)
|
|
254 | 255 |
out.success('done') |
255 | 256 |
# Upload metadata file |
256 | 257 |
out.output("Uploading metadata file...") |
257 |
metastring = extract_metadata_string(session)
|
|
258 |
metastring = unicode(json.dumps(result, ensure_ascii=False))
|
|
258 | 259 |
kamaki.upload(StringIO.StringIO(metastring), |
259 | 260 |
size=len(metastring), |
260 | 261 |
remote_path="%s.meta" % session['upload']) |
b/image_creator/dialog_util.py | ||
---|---|---|
39 | 39 |
|
40 | 40 |
import os |
41 | 41 |
import re |
42 |
import json |
|
42 | 43 |
from image_creator.output.dialog import GaugeOutput |
43 | 44 |
from image_creator.util import MD5 |
44 | 45 |
from image_creator.kamaki_wrapper import Kamaki |
... | ... | |
84 | 85 |
|
85 | 86 |
def extract_metadata_string(session): |
86 | 87 |
"""Convert image metadata to text""" |
87 |
metadata = ['%s=%s' % (k, v) for (k, v) in session['metadata'].items()]
|
|
88 |
|
|
88 |
metadata = {}
|
|
89 |
metadata.update(session['metadata']) |
|
89 | 90 |
if 'task_metadata' in session: |
90 |
metadata.extend("%s=yes" % m for m in session['task_metadata']) |
|
91 |
for key in session['task_metadata']: |
|
92 |
metadata[key] = 'yes' |
|
91 | 93 |
|
92 |
return '\n'.join(metadata) + '\n' |
|
94 |
return unicode(json.dumps({'properties': metadata, |
|
95 |
'disk-format': 'diskdump'}, ensure_ascii=False)) |
|
93 | 96 |
|
94 | 97 |
|
95 | 98 |
def extract_image(session): |
b/image_creator/dialog_wizard.py | ||
---|---|---|
39 | 39 |
|
40 | 40 |
import time |
41 | 41 |
import StringIO |
42 |
import json |
|
42 | 43 |
|
43 | 44 |
from image_creator.kamaki_wrapper import Kamaki, ClientError |
44 | 45 |
from image_creator.util import MD5, FatalError |
... | ... | |
292 | 293 |
md5 = MD5(out) |
293 | 294 |
session['checksum'] = md5.compute(image.device, size) |
294 | 295 |
|
295 |
#Metadata |
|
296 |
metastring = '\n'.join( |
|
297 |
['%s=%s' % (key, value) for (key, value) in metadata.items()]) |
|
298 |
metastring += '\n' |
|
299 |
|
|
300 | 296 |
out.output() |
301 | 297 |
try: |
302 | 298 |
out.output("Uploading image to pithos:") |
... | ... | |
307 | 303 |
pithos_file = "" |
308 | 304 |
with open(image.device, 'rb') as f: |
309 | 305 |
pithos_file = kamaki.upload(f, size, name, |
310 |
"(1/4) Calculating block hashes",
|
|
311 |
"(2/4) Uploading missing blocks")
|
|
306 |
"(1/3) Calculating block hashes",
|
|
307 |
"(2/3) Uploading missing blocks")
|
|
312 | 308 |
|
313 |
out.output("(3/4) Uploading metadata file ...", False) |
|
314 |
kamaki.upload(StringIO.StringIO(metastring), size=len(metastring), |
|
315 |
remote_path="%s.%s" % (name, 'meta')) |
|
316 |
out.success('done') |
|
317 |
out.output("(4/4) Uploading md5sum file ...", False) |
|
309 |
out.output("(3/3) Uploading md5sum file ...", False) |
|
318 | 310 |
md5sumstr = '%s %s\n' % (session['checksum'], name) |
319 | 311 |
kamaki.upload(StringIO.StringIO(md5sumstr), size=len(md5sumstr), |
320 | 312 |
remote_path="%s.%s" % (name, 'md5sum')) |
... | ... | |
325 | 317 |
False |
326 | 318 |
out.output('Registering %s image with cyclades ...' % |
327 | 319 |
wizard['ImageRegistration'].lower(), False) |
328 |
kamaki.register(wizard['ImageName'], pithos_file, metadata,
|
|
329 |
is_public) |
|
320 |
result = kamaki.register(wizard['ImageName'], pithos_file,
|
|
321 |
metadata, is_public)
|
|
330 | 322 |
out.success('done') |
323 |
out.output("Uploading metadata file ...", False) |
|
324 |
metastring = unicode(json.dumps(result, ensure_ascii=False)) |
|
325 |
kamaki.upload(StringIO.StringIO(metastring), size=len(metastring), |
|
326 |
remote_path="%s.%s" % (name, 'meta')) |
|
327 |
out.success('done') |
|
328 |
|
|
331 | 329 |
if is_public: |
332 | 330 |
out.output("Sharing md5sum file ...", False) |
333 | 331 |
kamaki.share("%s.md5sum" % name) |
b/image_creator/main.py | ||
---|---|---|
49 | 49 |
import optparse |
50 | 50 |
import StringIO |
51 | 51 |
import signal |
52 |
import json |
|
52 | 53 |
|
53 | 54 |
|
54 | 55 |
def check_writable_dir(option, opt_str, value, parser): |
... | ... | |
280 | 281 |
md5 = MD5(out) |
281 | 282 |
checksum = md5.compute(image.device, size) |
282 | 283 |
|
283 |
metastring = '\n'.join(
|
|
284 |
['%s=%s' % (key, value) for (key, value) in metadata.items()])
|
|
285 |
metastring += '\n'
|
|
284 |
metastring = unicode(json.dumps(
|
|
285 |
{'properties': metadata,
|
|
286 |
'disk-format': 'diskdump'}, ensure_ascii=False))
|
|
286 | 287 |
|
287 | 288 |
if options.outfile is not None: |
288 | 289 |
image.dump(options.outfile) |
... | ... | |
324 | 325 |
img_type = 'public' if options.public else 'private' |
325 | 326 |
out.output('Registering %s image with ~okeanos ...' % img_type, |
326 | 327 |
False) |
327 |
kamaki.register(options.register, uploaded_obj, metadata,
|
|
328 |
options.public) |
|
328 |
result = kamaki.register(options.register, uploaded_obj,
|
|
329 |
metadata, options.public)
|
|
329 | 330 |
out.success('done') |
330 | 331 |
out.output("Uploading metadata file ...", False) |
332 |
metastring = unicode(json.dumps(result, ensure_ascii=False)) |
|
331 | 333 |
kamaki.upload(StringIO.StringIO(metastring), |
332 | 334 |
size=len(metastring), |
333 | 335 |
remote_path="%s.%s" % (options.upload, 'meta')) |
Also available in: Unified diff