Revision b3a4845c image_creator/main.py
b/image_creator/main.py | ||
---|---|---|
102 | 102 |
default=None, help="use this authentication URL when " |
103 | 103 |
"uploading/registering images") |
104 | 104 |
|
105 |
parser.add_option("-c", "--cloud", dest="cloud", type="string", |
|
106 |
default=None, help="use this saved cloud account to " |
|
107 |
"authenticate against a cloud when " |
|
108 |
"uploading/registering images") |
|
109 |
|
|
105 | 110 |
parser.add_option("--print-sysprep", dest="print_sysprep", default=False, |
106 | 111 |
help="print the enabled and disabled system preparation " |
107 | 112 |
"operations for this input media", action="store_true") |
... | ... | |
142 | 147 |
if options.register and not options.upload: |
143 | 148 |
raise FatalError("You also need to set -u when -r option is set") |
144 | 149 |
|
145 |
if options.upload and (options.token is None or options.url is None):
|
|
146 |
if options.url is None:
|
|
147 |
err = "No authentication URL is specified. Use -a to set a URL" |
|
148 |
else:
|
|
149 |
err = "No autentication token is specified. Use -t to set a token"
|
|
150 |
if options.upload and (options.token is None or options.url is None) and \
|
|
151 |
options.cloud is None:
|
|
152 |
|
|
153 |
err = "You need to either specify an authentication URL and token " \
|
|
154 |
"pair or an available cloud name."
|
|
150 | 155 |
|
151 | 156 |
raise FatalError("Image uploading cannot be performed. %s" % err) |
152 | 157 |
|
... | ... | |
196 | 201 |
raise FatalError("Output file `%s' exists " |
197 | 202 |
"(use --force to overwrite it)." % filename) |
198 | 203 |
|
199 |
# Check if the authentication token is valid. The earlier the better
|
|
204 |
# Check if the authentication info is valid. The earlier the better
|
|
200 | 205 |
if options.token is not None and options.url is not None: |
201 | 206 |
try: |
202 | 207 |
account = Kamaki.create_account(options.url, options.token) |
... | ... | |
207 | 212 |
kamaki = Kamaki(account, out) |
208 | 213 |
except ClientError as e: |
209 | 214 |
raise FatalError("Astakos client: %d %s" % (e.status, e.message)) |
215 |
elif options.cloud: |
|
216 |
avail_clouds = Kamaki.get_clouds() |
|
217 |
if options.cloud not in avail_clouds.keys(): |
|
218 |
raise FatalError( |
|
219 |
"Cloud: `%s' does not exist.\n\nAvailable clouds:\n\n\t%s\n" |
|
220 |
% (options.cloud, "\n\t".join(avail_clouds.keys()))) |
|
221 |
try: |
|
222 |
account = Kamaki.get_account(options.cloud) |
|
223 |
if account is None: |
|
224 |
raise FatalError( |
|
225 |
"Cloud: `$s' exists but is not valid!" % options.cloud) |
|
226 |
else: |
|
227 |
kamaki = Kamaki(account, out) |
|
228 |
except ClientError as e: |
|
229 |
raise FatalError("Astakos client: %d %s" % (e.status, e.message)) |
|
210 | 230 |
|
211 | 231 |
if options.upload and not options.force: |
212 | 232 |
if kamaki.object_exists(options.upload): |
Also available in: Unified diff