From b3a4845c0699ab1d22ca88f6209f8c704a069e7a Mon Sep 17 00:00:00 2001 From: Nikos Skalkotos Date: Tue, 18 Jun 2013 17:21:28 +0300 Subject: [PATCH] Add --cloud option in snf-image-creator This options can be used to get the authentication URL and token from a saved cloud section in the kamaki configuration file --- image_creator/main.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/image_creator/main.py b/image_creator/main.py index 86680c6..dbcb127 100644 --- a/image_creator/main.py +++ b/image_creator/main.py @@ -102,6 +102,11 @@ def parse_options(input_args): default=None, help="use this authentication URL when " "uploading/registering images") + parser.add_option("-c", "--cloud", dest="cloud", type="string", + default=None, help="use this saved cloud account to " + "authenticate against a cloud when " + "uploading/registering images") + parser.add_option("--print-sysprep", dest="print_sysprep", default=False, help="print the enabled and disabled system preparation " "operations for this input media", action="store_true") @@ -142,11 +147,11 @@ def parse_options(input_args): if options.register and not options.upload: raise FatalError("You also need to set -u when -r option is set") - if options.upload and (options.token is None or options.url is None): - if options.url is None: - err = "No authentication URL is specified. Use -a to set a URL" - else: - err = "No autentication token is specified. Use -t to set a token" + if options.upload and (options.token is None or options.url is None) and \ + options.cloud is None: + + err = "You need to either specify an authentication URL and token " \ + "pair or an available cloud name." raise FatalError("Image uploading cannot be performed. %s" % err) @@ -196,7 +201,7 @@ def image_creator(): raise FatalError("Output file `%s' exists " "(use --force to overwrite it)." % filename) - # Check if the authentication token is valid. The earlier the better + # Check if the authentication info is valid. The earlier the better if options.token is not None and options.url is not None: try: account = Kamaki.create_account(options.url, options.token) @@ -207,6 +212,21 @@ def image_creator(): kamaki = Kamaki(account, out) except ClientError as e: raise FatalError("Astakos client: %d %s" % (e.status, e.message)) + elif options.cloud: + avail_clouds = Kamaki.get_clouds() + if options.cloud not in avail_clouds.keys(): + raise FatalError( + "Cloud: `%s' does not exist.\n\nAvailable clouds:\n\n\t%s\n" + % (options.cloud, "\n\t".join(avail_clouds.keys()))) + try: + account = Kamaki.get_account(options.cloud) + if account is None: + raise FatalError( + "Cloud: `$s' exists but is not valid!" % options.cloud) + else: + kamaki = Kamaki(account, out) + except ClientError as e: + raise FatalError("Astakos client: %d %s" % (e.status, e.message)) if options.upload and not options.force: if kamaki.object_exists(options.upload): -- 1.7.10.4