summaryrefslogtreecommitdiff
path: root/novaclient/shell.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/shell.py')
-rw-r--r--novaclient/shell.py56
1 files changed, 8 insertions, 48 deletions
diff --git a/novaclient/shell.py b/novaclient/shell.py
index 4e7b5c9..5151635 100644
--- a/novaclient/shell.py
+++ b/novaclient/shell.py
@@ -58,13 +58,7 @@ from novaclient.v2 import shell as shell_v2
58 58
59DEFAULT_OS_COMPUTE_API_VERSION = "2" 59DEFAULT_OS_COMPUTE_API_VERSION = "2"
60DEFAULT_NOVA_ENDPOINT_TYPE = 'publicURL' 60DEFAULT_NOVA_ENDPOINT_TYPE = 'publicURL'
61# NOTE(cyeoh): Having the service type dependent on the API version 61DEFAULT_NOVA_SERVICE_TYPE = "compute"
62# is pretty ugly, but we have to do this because traditionally the
63# catalog entry for compute points directly to the V2 API rather than
64# the root, and then doing version discovery.
65DEFAULT_NOVA_SERVICE_TYPE_MAP = {'1.1': 'compute',
66 '2': 'compute',
67 '3': 'computev3'}
68 62
69logger = logging.getLogger(__name__) 63logger = logging.getLogger(__name__)
70 64
@@ -414,7 +408,7 @@ class OpenStackComputeShell(object):
414 metavar='<compute-api-ver>', 408 metavar='<compute-api-ver>',
415 default=cliutils.env('OS_COMPUTE_API_VERSION', 409 default=cliutils.env('OS_COMPUTE_API_VERSION',
416 default=DEFAULT_OS_COMPUTE_API_VERSION), 410 default=DEFAULT_OS_COMPUTE_API_VERSION),
417 help=_('Accepts 1.1 or 3, ' 411 help=_('Accepts number of API version, '
418 'defaults to env[OS_COMPUTE_API_VERSION].')) 412 'defaults to env[OS_COMPUTE_API_VERSION].'))
419 parser.add_argument( 413 parser.add_argument(
420 '--os_compute_api_version', 414 '--os_compute_api_version',
@@ -490,9 +484,9 @@ class OpenStackComputeShell(object):
490 def _discover_via_contrib_path(self, version): 484 def _discover_via_contrib_path(self, version):
491 module_path = os.path.dirname(os.path.abspath(__file__)) 485 module_path = os.path.dirname(os.path.abspath(__file__))
492 version_str = "v%s" % version.replace('.', '_') 486 version_str = "v%s" % version.replace('.', '_')
493 # NOTE(akurilin): v1.1, v2 and v3 have one implementation, so 487 # NOTE(andreykurilin): v1.1 uses implementation of v2, so we should
494 # we should discover contrib modules in one place. 488 # discover contrib modules in novaclient.v2 dir.
495 if version_str in ["v1_1", "v3"]: 489 if version_str == "v1_1":
496 version_str = "v2" 490 version_str = "v2"
497 ext_path = os.path.join(module_path, version_str, 'contrib') 491 ext_path = os.path.join(module_path, version_str, 'contrib')
498 ext_glob = os.path.join(ext_path, "*.py") 492 ext_glob = os.path.join(ext_path, "*.py")
@@ -656,15 +650,8 @@ class OpenStackComputeShell(object):
656 endpoint_type += 'URL' 650 endpoint_type += 'URL'
657 651
658 if not service_type: 652 if not service_type:
659 os_compute_api_version = (options.os_compute_api_version or 653 service_type = (cliutils.get_service_type(args.func) or
660 DEFAULT_OS_COMPUTE_API_VERSION) 654 DEFAULT_NOVA_SERVICE_TYPE)
661 try:
662 service_type = DEFAULT_NOVA_SERVICE_TYPE_MAP[
663 os_compute_api_version]
664 except KeyError:
665 service_type = DEFAULT_NOVA_SERVICE_TYPE_MAP[
666 DEFAULT_OS_COMPUTE_API_VERSION]
667 service_type = cliutils.get_service_type(args.func) or service_type
668 655
669 # If we have an auth token but no management_url, we must auth anyway. 656 # If we have an auth token but no management_url, we must auth anyway.
670 # Expired tokens are handled by client.py:_cs_request 657 # Expired tokens are handled by client.py:_cs_request
@@ -734,8 +721,7 @@ class OpenStackComputeShell(object):
734 project_domain_id=args.os_project_domain_id, 721 project_domain_id=args.os_project_domain_id,
735 project_domain_name=args.os_project_domain_name) 722 project_domain_name=args.os_project_domain_name)
736 723
737 if (options.os_compute_api_version and 724 if options.os_compute_api_version:
738 options.os_compute_api_version != '1.0'):
739 if not any([args.os_tenant_id, args.os_tenant_name, 725 if not any([args.os_tenant_id, args.os_tenant_name,
740 args.os_project_id, args.os_project_name]): 726 args.os_project_id, args.os_project_name]):
741 raise exc.CommandError(_("You must provide a project name or" 727 raise exc.CommandError(_("You must provide a project name or"
@@ -806,32 +792,6 @@ class OpenStackComputeShell(object):
806 except exc.AuthorizationFailure: 792 except exc.AuthorizationFailure:
807 raise exc.CommandError(_("Unable to authorize user")) 793 raise exc.CommandError(_("Unable to authorize user"))
808 794
809 if options.os_compute_api_version == "3" and service_type != 'image':
810 # NOTE(cyeoh): create an image based client because the
811 # images api is no longer proxied by the V3 API and we
812 # sometimes need to be able to look up images information
813 # via glance when connected to the nova api.
814 image_service_type = 'image'
815 # NOTE(hdd): the password is needed again because creating a new
816 # Client without specifying bypass_url will force authentication.
817 # We can't reuse self.cs's bypass_url, because that's the URL for
818 # the nova service; we need to get glance's URL for this Client
819 if not os_password:
820 os_password = helper.password
821 self.cs.image_cs = client.Client(
822 options.os_compute_api_version, os_username,
823 os_password, os_tenant_name, tenant_id=os_tenant_id,
824 auth_url=os_auth_url, insecure=insecure,
825 region_name=os_region_name, endpoint_type=endpoint_type,
826 extensions=self.extensions, service_type=image_service_type,
827 service_name=service_name, auth_system=os_auth_system,
828 auth_plugin=auth_plugin,
829 volume_service_name=volume_service_name,
830 timings=args.timings, bypass_url=bypass_url,
831 os_cache=os_cache, http_log_debug=options.debug,
832 session=keystone_session, auth=keystone_auth,
833 cacert=cacert, timeout=timeout)
834
835 args.func(self.cs, args) 795 args.func(self.cs, args)
836 796
837 if args.timings: 797 if args.timings: