Commit b3a4845c authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

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
parent 49c07ce3
......@@ -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):
......
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