Add useful error on invalid --os-image-api-version

This adds a useful error message when a user enters an invalid value
for --os-image-api-version. Previously, the shell directly attempted to
import the module the user specified, and printed the error from the
exception raised when that failed:

    $ glance --os-image-api-version stupid-glance-version
    No module named vstupid-glance-version.shell

Glanceclient now catches this exception and prints something
understandable for a user:

    $ glance --os-image-api-version stupid-glance-version
    "stupid-glance-version" is not a supported API version. Example values are "1" or "2".

Closes-Bug: #1395841

Change-Id: I48a95b7562c10bd68d777be408dcfa22cb05ec6a
This commit is contained in:
Louis Taylor 2014-11-25 15:33:57 +00:00
parent 265bb4aa17
commit d5a0e657ed

@ -284,7 +284,13 @@ class OpenStackImagesShell(object):
self.subcommands = {}
subparsers = parser.add_subparsers(metavar='<subcommand>')
submodule = utils.import_versioned_module(version, 'shell')
try:
submodule = utils.import_versioned_module(version, 'shell')
except ImportError:
print('"%s" is not a supported API version. Example '
'values are "1" or "2".' % version)
utils.exit()
self._find_actions(subparsers, submodule)
self._find_actions(subparsers, self)