Commit 8e58e699 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Change the metadata file format to json

When registring an image, use the information returned by the
kamaki register method to construct the metadata file.

When dumping the image to the local filesystem, store the image
properties and the disk-format info in the metadata file.
parent b3a4845c
......@@ -40,6 +40,7 @@ snf-image-creator.
import os
import textwrap
import StringIO
import json
from image_creator import __version__ as version
from image_creator.util import MD5, FatalError
......@@ -249,12 +250,12 @@ def register_image(session):
try:
out.output("Registering %s image with Cyclades..." % img_type)
kamaki = Kamaki(session['account'], out)
kamaki.register(name, session['pithos_uri'], metadata,
is_public)
result = kamaki.register(name, session['pithos_uri'], metadata,
is_public)
out.success('done')
# Upload metadata file
out.output("Uploading metadata file...")
metastring = extract_metadata_string(session)
metastring = unicode(json.dumps(result, ensure_ascii=False))
kamaki.upload(StringIO.StringIO(metastring),
size=len(metastring),
remote_path="%s.meta" % session['upload'])
......
......@@ -39,6 +39,7 @@ snf-image-creator.
import os
import re
import json
from image_creator.output.dialog import GaugeOutput
from image_creator.util import MD5
from image_creator.kamaki_wrapper import Kamaki
......@@ -84,12 +85,14 @@ class Reset(Exception):
def extract_metadata_string(session):
"""Convert image metadata to text"""
metadata = ['%s=%s' % (k, v) for (k, v) in session['metadata'].items()]
metadata = {}
metadata.update(session['metadata'])
if 'task_metadata' in session:
metadata.extend("%s=yes" % m for m in session['task_metadata'])
for key in session['task_metadata']:
metadata[key] = 'yes'
return '\n'.join(metadata) + '\n'
return unicode(json.dumps({'properties': metadata,
'disk-format': 'diskdump'}, ensure_ascii=False))
def extract_image(session):
......
......@@ -39,6 +39,7 @@ snf-image-creator.
import time
import StringIO
import json
from image_creator.kamaki_wrapper import Kamaki, ClientError
from image_creator.util import MD5, FatalError
......@@ -292,11 +293,6 @@ def create_image(session, account):
md5 = MD5(out)
session['checksum'] = md5.compute(image.device, size)
#Metadata
metastring = '\n'.join(
['%s=%s' % (key, value) for (key, value) in metadata.items()])
metastring += '\n'
out.output()
try:
out.output("Uploading image to pithos:")
......@@ -307,14 +303,10 @@ def create_image(session, account):
pithos_file = ""
with open(image.device, 'rb') as f:
pithos_file = kamaki.upload(f, size, name,
"(1/4) Calculating block hashes",
"(2/4) Uploading missing blocks")
"(1/3) Calculating block hashes",
"(2/3) Uploading missing blocks")
out.output("(3/4) Uploading metadata file ...", False)
kamaki.upload(StringIO.StringIO(metastring), size=len(metastring),
remote_path="%s.%s" % (name, 'meta'))
out.success('done')
out.output("(4/4) Uploading md5sum file ...", False)
out.output("(3/3) Uploading md5sum file ...", False)
md5sumstr = '%s %s\n' % (session['checksum'], name)
kamaki.upload(StringIO.StringIO(md5sumstr), size=len(md5sumstr),
remote_path="%s.%s" % (name, 'md5sum'))
......@@ -325,9 +317,15 @@ def create_image(session, account):
False
out.output('Registering %s image with cyclades ...' %
wizard['ImageRegistration'].lower(), False)
kamaki.register(wizard['ImageName'], pithos_file, metadata,
is_public)
result = kamaki.register(wizard['ImageName'], pithos_file,
metadata, is_public)
out.success('done')
out.output("Uploading metadata file ...", False)
metastring = unicode(json.dumps(result, ensure_ascii=False))
kamaki.upload(StringIO.StringIO(metastring), size=len(metastring),
remote_path="%s.%s" % (name, 'meta'))
out.success('done')
if is_public:
out.output("Sharing md5sum file ...", False)
kamaki.share("%s.md5sum" % name)
......
......@@ -49,6 +49,7 @@ import os
import optparse
import StringIO
import signal
import json
def check_writable_dir(option, opt_str, value, parser):
......@@ -280,9 +281,9 @@ def image_creator():
md5 = MD5(out)
checksum = md5.compute(image.device, size)
metastring = '\n'.join(
['%s=%s' % (key, value) for (key, value) in metadata.items()])
metastring += '\n'
metastring = unicode(json.dumps(
{'properties': metadata,
'disk-format': 'diskdump'}, ensure_ascii=False))
if options.outfile is not None:
image.dump(options.outfile)
......@@ -324,10 +325,11 @@ def image_creator():
img_type = 'public' if options.public else 'private'
out.output('Registering %s image with ~okeanos ...' % img_type,
False)
kamaki.register(options.register, uploaded_obj, metadata,
options.public)
result = kamaki.register(options.register, uploaded_obj,
metadata, options.public)
out.success('done')
out.output("Uploading metadata file ...", False)
metastring = unicode(json.dumps(result, ensure_ascii=False))
kamaki.upload(StringIO.StringIO(metastring),
size=len(metastring),
remote_path="%s.%s" % (options.upload, 'meta'))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment