From 7d3dc8578bc21a6c0578f5040ea414a6c530485a Mon Sep 17 00:00:00 2001 From: Nikos Skalkotos Date: Fri, 18 May 2012 17:05:01 +0300 Subject: [PATCH] Add option for passing user-defined image metadata The metadata passed by the user will overwrite any automatically collected metadata with the same key. --- image_creator/main.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/image_creator/main.py b/image_creator/main.py index a18d6c7..cbbc42b 100644 --- a/image_creator/main.py +++ b/image_creator/main.py @@ -90,6 +90,10 @@ def parse_options(input_args): help="Use this ACCOUNT when uploading/registring images [Default: %s]"\ % account) + parser.add_option("-m", "--metadata", dest="metadata", default=[], + help="Add custom KEY=VALUE metadata to the image", action="append", + metavar="KEY=VALUE") + parser.add_option("-t", "--token", dest="token", type="string", default=token, help="Use this token when uploading/registring images [Default: %s]"\ @@ -117,6 +121,7 @@ def parse_options(input_args): if len(args) != 1: parser.error('Wrong number of arguments') + options.source = args[0] if not os.path.exists(options.source): raise FatalError("Input media `%s' is not accessible" % options.source) @@ -132,6 +137,16 @@ def parse_options(input_args): raise FatalError("Image uploading cannot be performed. No ~okeanos " "token is specified. User -t to set a token.") + meta = {} + for m in options.metadata: + try: + key, value = m.split('=', 1) + except ValueError: + raise FatalError("Metadata option: `%s' is not in "\ + "KEY=VALUE format." % m) + meta[key] = value + options.metadata = meta + return options @@ -194,6 +209,9 @@ def image_creator(): size = options.shrink and dev.shrink() or dev.size metadata.update(dev.meta) + # Add command line metadata to the collected ones... + metadata.update(options.metadata) + checksum = md5(snapshot, size) metastring = '\n'.join( -- 1.7.10.4