Make _discover_extensions public
Heat wants to use `cinderclient.shell.OpenStackCinderShell._discover_extensions` function (https://bugs.launchpad.net/heat/+bug/1527071), which is private currently. It's better to change this method to public for public use. This change will do it as novaclient did. Change-Id: Iaaa4cab530fd495877e15a372fff1354ddbeaa17 Closes-Bug: #1527169
This commit is contained in:
		@@ -20,7 +20,12 @@ OpenStack Client interface. Handles the REST calls and responses.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from __future__ import print_function
 | 
					from __future__ import print_function
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import glob
 | 
				
			||||||
 | 
					import imp
 | 
				
			||||||
 | 
					import itertools
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					import pkgutil
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
import six
 | 
					import six
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -31,6 +36,7 @@ from keystoneclient import discover
 | 
				
			|||||||
import requests
 | 
					import requests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from cinderclient import exceptions
 | 
					from cinderclient import exceptions
 | 
				
			||||||
 | 
					import cinderclient.extension
 | 
				
			||||||
from cinderclient.openstack.common import importutils
 | 
					from cinderclient.openstack.common import importutils
 | 
				
			||||||
from cinderclient.openstack.common.gettextutils import _
 | 
					from cinderclient.openstack.common.gettextutils import _
 | 
				
			||||||
from oslo_utils import strutils
 | 
					from oslo_utils import strutils
 | 
				
			||||||
@@ -570,6 +576,45 @@ def get_client_class(version):
 | 
				
			|||||||
    return importutils.import_class(client_path)
 | 
					    return importutils.import_class(client_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def discover_extensions(version):
 | 
				
			||||||
 | 
					    extensions = []
 | 
				
			||||||
 | 
					    for name, module in itertools.chain(
 | 
				
			||||||
 | 
					            _discover_via_python_path(),
 | 
				
			||||||
 | 
					            _discover_via_contrib_path(version)):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        extension = cinderclient.extension.Extension(name, module)
 | 
				
			||||||
 | 
					        extensions.append(extension)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return extensions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _discover_via_python_path():
 | 
				
			||||||
 | 
					    for (module_loader, name, ispkg) in pkgutil.iter_modules():
 | 
				
			||||||
 | 
					        if name.endswith('python_cinderclient_ext'):
 | 
				
			||||||
 | 
					            if not hasattr(module_loader, 'load_module'):
 | 
				
			||||||
 | 
					                # Python 2.6 compat: actually get an ImpImporter obj
 | 
				
			||||||
 | 
					                module_loader = module_loader.find_module(name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            module = module_loader.load_module(name)
 | 
				
			||||||
 | 
					            yield name, module
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _discover_via_contrib_path(version):
 | 
				
			||||||
 | 
					    module_path = os.path.dirname(os.path.abspath(__file__))
 | 
				
			||||||
 | 
					    version_str = "v%s" % version.replace('.', '_')
 | 
				
			||||||
 | 
					    ext_path = os.path.join(module_path, version_str, 'contrib')
 | 
				
			||||||
 | 
					    ext_glob = os.path.join(ext_path, "*.py")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for ext_path in glob.iglob(ext_glob):
 | 
				
			||||||
 | 
					        name = os.path.basename(ext_path)[:-3]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if name == "__init__":
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        module = imp.load_source(name, ext_path)
 | 
				
			||||||
 | 
					        yield name, module
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def Client(version, *args, **kwargs):
 | 
					def Client(version, *args, **kwargs):
 | 
				
			||||||
    client_class = get_client_class(version)
 | 
					    client_class = get_client_class(version)
 | 
				
			||||||
    return client_class(*args, **kwargs)
 | 
					    return client_class(*args, **kwargs)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,12 +22,7 @@ from __future__ import print_function
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
import getpass
 | 
					import getpass
 | 
				
			||||||
import glob
 | 
					 | 
				
			||||||
import imp
 | 
					 | 
				
			||||||
import itertools
 | 
					 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import os
 | 
					 | 
				
			||||||
import pkgutil
 | 
					 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import requests
 | 
					import requests
 | 
				
			||||||
@@ -36,7 +31,6 @@ from cinderclient import client
 | 
				
			|||||||
from cinderclient import exceptions as exc
 | 
					from cinderclient import exceptions as exc
 | 
				
			||||||
from cinderclient import utils
 | 
					from cinderclient import utils
 | 
				
			||||||
import cinderclient.auth_plugin
 | 
					import cinderclient.auth_plugin
 | 
				
			||||||
import cinderclient.extension
 | 
					 | 
				
			||||||
from cinderclient.openstack.common import importutils
 | 
					from cinderclient.openstack.common import importutils
 | 
				
			||||||
from cinderclient.openstack.common.gettextutils import _
 | 
					from cinderclient.openstack.common.gettextutils import _
 | 
				
			||||||
from cinderclient.v1 import shell as shell_v1
 | 
					from cinderclient.v1 import shell as shell_v1
 | 
				
			||||||
@@ -412,42 +406,6 @@ class OpenStackCinderShell(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return parser
 | 
					        return parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _discover_extensions(self, version):
 | 
					 | 
				
			||||||
        extensions = []
 | 
					 | 
				
			||||||
        for name, module in itertools.chain(
 | 
					 | 
				
			||||||
                self._discover_via_python_path(version),
 | 
					 | 
				
			||||||
                self._discover_via_contrib_path(version)):
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            extension = cinderclient.extension.Extension(name, module)
 | 
					 | 
				
			||||||
            extensions.append(extension)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return extensions
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def _discover_via_python_path(self, version):
 | 
					 | 
				
			||||||
        for (module_loader, name, ispkg) in pkgutil.iter_modules():
 | 
					 | 
				
			||||||
            if name.endswith('python_cinderclient_ext'):
 | 
					 | 
				
			||||||
                if not hasattr(module_loader, 'load_module'):
 | 
					 | 
				
			||||||
                    # Python 2.6 compat: actually get an ImpImporter obj
 | 
					 | 
				
			||||||
                    module_loader = module_loader.find_module(name)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                module = module_loader.load_module(name)
 | 
					 | 
				
			||||||
                yield name, module
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def _discover_via_contrib_path(self, version):
 | 
					 | 
				
			||||||
        module_path = os.path.dirname(os.path.abspath(__file__))
 | 
					 | 
				
			||||||
        version_str = "v%s" % version.replace('.', '_')
 | 
					 | 
				
			||||||
        ext_path = os.path.join(module_path, version_str, 'contrib')
 | 
					 | 
				
			||||||
        ext_glob = os.path.join(ext_path, "*.py")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for ext_path in glob.iglob(ext_glob):
 | 
					 | 
				
			||||||
            name = os.path.basename(ext_path)[:-3]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if name == "__init__":
 | 
					 | 
				
			||||||
                continue
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            module = imp.load_source(name, ext_path)
 | 
					 | 
				
			||||||
            yield name, module
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def _add_bash_completion_subparser(self, subparsers):
 | 
					    def _add_bash_completion_subparser(self, subparsers):
 | 
				
			||||||
        subparser = subparsers.add_parser(
 | 
					        subparser = subparsers.add_parser(
 | 
				
			||||||
            'bash_completion',
 | 
					            'bash_completion',
 | 
				
			||||||
@@ -540,7 +498,7 @@ class OpenStackCinderShell(object):
 | 
				
			|||||||
            api_version_input = False
 | 
					            api_version_input = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # build available subcommands based on version
 | 
					        # build available subcommands based on version
 | 
				
			||||||
        self.extensions = self._discover_extensions(
 | 
					        self.extensions = client.discover_extensions(
 | 
				
			||||||
            options.os_volume_api_version)
 | 
					            options.os_volume_api_version)
 | 
				
			||||||
        self._run_extension_hooks('__pre_parse_args__')
 | 
					        self._run_extension_hooks('__pre_parse_args__')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user