summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/compute/client.py3
-rw-r--r--openstackclient/image/client.py56
-rw-r--r--openstackclient/shell.py40
3 files changed, 12 insertions, 87 deletions
diff --git a/openstackclient/compute/client.py b/openstackclient/compute/client.py
index 7ca08a4f..bdba4dca 100644
--- a/openstackclient/compute/client.py
+++ b/openstackclient/compute/client.py
@@ -30,6 +30,9 @@ LOG = logging.getLogger(__name__)
DEFAULT_COMPUTE_API_VERSION = '2'
API_VERSION_OPTION = 'os_compute_api_version'
API_NAME = 'compute'
+API_VERSIONS = {
+ "2": "novaclient.client",
+}
def make_client(instance):
diff --git a/openstackclient/image/client.py b/openstackclient/image/client.py
index 35779664..c78f4425 100644
--- a/openstackclient/image/client.py
+++ b/openstackclient/image/client.py
@@ -15,9 +15,6 @@
import logging
-from glanceclient import exc as gc_exceptions
-from glanceclient.v1 import client as gc_v1_client
-from glanceclient.v1 import images as gc_v1_images
from openstackclient.common import utils
@@ -27,7 +24,7 @@ DEFAULT_IMAGE_API_VERSION = '1'
API_VERSION_OPTION = 'os_image_api_version'
API_NAME = "image"
API_VERSIONS = {
- "1": "openstackclient.image.client.Client_v1",
+ "1": "glanceclient.v1.client.Client",
"2": "glanceclient.v2.client.Client",
}
@@ -89,54 +86,3 @@ def build_option_parser(parser):
DEFAULT_IMAGE_API_VERSION +
' (Env: OS_IMAGE_API_VERSION)')
return parser
-
-
-# NOTE(dtroyer): glanceclient.v1.image.ImageManager() doesn't have a find()
-# method so add one here until the common client libs arrive
-# A similar subclass will be required for v2
-
-class Client_v1(gc_v1_client.Client):
- """An image v1 client that uses ImageManager_v1"""
-
- def __init__(self, *args, **kwargs):
- super(Client_v1, self).__init__(*args, **kwargs)
- self.images = ImageManager_v1(getattr(self, 'http_client', self))
-
-
-class ImageManager_v1(gc_v1_images.ImageManager):
- """Add find() and findall() to the ImageManager class"""
-
- def find(self, **kwargs):
- """Find a single item with attributes matching ``**kwargs``.
-
- This isn't very efficient: it loads the entire list then filters on
- the Python side.
- """
- rl = self.findall(**kwargs)
- num = len(rl)
-
- if num == 0:
- raise gc_exceptions.NotFound
- elif num > 1:
- raise gc_exceptions.NoUniqueMatch
- else:
- return rl[0]
-
- def findall(self, **kwargs):
- """Find all items with attributes matching ``**kwargs``.
-
- This isn't very efficient: it loads the entire list then filters on
- the Python side.
- """
- found = []
- searches = kwargs.items()
-
- for obj in self.list():
- try:
- if all(getattr(obj, attr) == value
- for (attr, value) in searches):
- found.append(obj)
- except AttributeError:
- continue
-
- return found
diff --git a/openstackclient/shell.py b/openstackclient/shell.py
index 3cfd7312..c118fbd2 100644
--- a/openstackclient/shell.py
+++ b/openstackclient/shell.py
@@ -76,7 +76,8 @@ class OpenStackShell(app.App):
super(OpenStackShell, self).__init__(
description=__doc__.strip(),
version=openstackclient.__version__,
- command_manager=commandmanager.CommandManager('openstack.cli'))
+ command_manager=commandmanager.CommandManager('openstack.cli'),
+ deferred_help=True)
self.api_version = {}
@@ -92,35 +93,6 @@ class OpenStackShell(app.App):
self.client_manager = None
- # NOTE(dtroyer): This hack changes the help action that Cliff
- # automatically adds to the parser so we can defer
- # its execution until after the api-versioned commands
- # have been loaded. There doesn't seem to be a
- # way to edit/remove anything from an existing parser.
-
- # Replace the cliff-added help.HelpAction to defer its execution
- self.DeferredHelpAction = None
- for a in self.parser._actions:
- if type(a) == help.HelpAction:
- # Found it, save and replace it
- self.DeferredHelpAction = a
-
- # These steps are argparse-implementation-dependent
- self.parser._actions.remove(a)
- if self.parser._option_string_actions['-h']:
- del self.parser._option_string_actions['-h']
- if self.parser._option_string_actions['--help']:
- del self.parser._option_string_actions['--help']
-
- # Make a new help option to just set a flag
- self.parser.add_argument(
- '-h', '--help',
- action='store_true',
- dest='deferred_help',
- default=False,
- help="Show this help message and exit",
- )
-
def configure_logging(self):
"""Configure logging for the app
@@ -247,6 +219,11 @@ class OpenStackShell(app.App):
if version_opt:
api = mod.API_NAME
self.api_version[api] = version_opt
+ if version_opt not in mod.API_VERSIONS:
+ self.log.warning(
+ "The %s version <%s> is not in supported versions <%s>"
+ % (api, version_opt,
+ ', '.join(mod.API_VERSIONS.keys())))
# Command groups deal only with major versions
version = '.v' + version_opt.replace('.', '_').split('_')[0]
cmd_group = 'openstack.' + api.replace('-', '_') + version
@@ -276,8 +253,7 @@ class OpenStackShell(app.App):
# set up additional clients to stuff in to client_manager??
# Handle deferred help and exit
- if self.options.deferred_help:
- self.DeferredHelpAction(self.parser, self.parser, None, None)
+ self.print_help_if_requested()
# Set up common client session
if self.options.os_cacert: