예제 #1
0
 def _validate_input_api_version(self, options):
     if not options.os_share_api_version:
         api_version = manilaclient.API_MAX_VERSION
     else:
         api_version = api_versions.get_api_version(
             options.os_share_api_version)
     return api_version
 def _validate_input_api_version(self, options):
     if not options.os_share_api_version:
         api_version = manilaclient.API_MAX_VERSION
     else:
         api_version = api_versions.get_api_version(
             options.os_share_api_version)
     return api_version
 def test_major_and_minor_parts_is_presented(self, mock_apiversion):
     version = "2.7"
     self.assertEqual(mock_apiversion.return_value,
                      api_versions.get_api_version(version))
     mock_apiversion.assert_called_once_with(version)
예제 #4
0
    def main(self, argv):
        # Parse args once to find version and debug settings
        parser = self.get_base_parser()
        (options, args) = parser.parse_known_args(argv)
        self.setup_debugging(options.debug)

        os_api_version = self._validate_input_api_version(options)

        # build available subcommands based on version
        args = self._build_subcommands_and_extensions(os_api_version, argv,
                                                      options)
        if not args:
            return 0

        # Short-circuit and deal with help right away.
        if args.func == self.do_help:
            self.do_help(args)
            return 0
        elif args.func == self.do_bash_completion:
            self.do_bash_completion(args)
            return 0

        if not options.os_share_api_version:
            api_version = api_versions.get_api_version(
                DEFAULT_MAJOR_OS_SHARE_API_VERSION)
        else:
            api_version = api_versions.get_api_version(
                options.os_share_api_version)

        major_version_string = six.text_type(api_version.ver_major)
        os_service_type = args.service_type
        if not os_service_type:
            os_service_type = constants.SERVICE_TYPES[major_version_string]

        os_endpoint_type = args.endpoint_type or DEFAULT_MANILA_ENDPOINT_TYPE

        client_args = dict(
            username=args.os_username,
            password=args.os_password,
            project_name=args.os_project_name or args.os_tenant_name,
            auth_url=args.os_auth_url,
            insecure=args.insecure,
            region_name=args.os_region_name,
            tenant_id=args.os_project_id or args.os_tenant_id,
            endpoint_type=os_endpoint_type,
            extensions=self.extensions,
            service_type=os_service_type,
            service_name=args.service_name,
            retries=options.retries,
            http_log_debug=args.debug,
            cacert=args.os_cacert,
            use_keyring=args.os_cache,
            force_new_token=args.os_reset_cache,
            user_id=args.os_user_id,
            user_domain_id=args.os_user_domain_id,
            user_domain_name=args.os_user_domain_name,
            project_domain_id=args.os_project_domain_id,
            project_domain_name=args.os_project_domain_name,
            cert=args.os_cert,
            input_auth_token=args.os_token,
            service_catalog_url=args.bypass_url,
        )

        # Handle deprecated parameters
        if args.share_service_name:
            client_args['share_service_name'] = args.share_service_name

        self._validate_required_options(args.os_tenant_name, args.os_tenant_id,
                                        args.os_project_name,
                                        args.os_project_id, args.os_token,
                                        args.bypass_url,
                                        client_args['auth_url'])

        # This client is needed to discover the server api version.
        temp_client = client.Client(manilaclient.API_MAX_VERSION,
                                    **client_args)

        self.cs, discovered_version = self._discover_client(
            temp_client, os_api_version, os_endpoint_type, os_service_type,
            client_args)

        args = self._build_subcommands_and_extensions(discovered_version, argv,
                                                      options)

        profile = osprofiler_profiler and options.profile
        if profile:
            osprofiler_profiler.init(options.profile)

        args.func(self.cs, args)

        if profile:
            trace_id = osprofiler_profiler.get().get_base_id()
            print("Profiling trace ID: %s" % trace_id)
            print("To display trace use next command:\n"
                  "osprofiler trace show --html %s " % trace_id)
예제 #5
0
    def main(self, argv):
        # Parse args once to find version and debug settings
        parser = self.get_base_parser()
        (options, args) = parser.parse_known_args(argv)
        self.setup_debugging(options.debug)

        os_api_version = self._validate_input_api_version(options)

        # build available subcommands based on version
        args = self._build_subcommands_and_extensions(os_api_version,
                                                      argv,
                                                      options)
        if not args:
            return 0

        # Short-circuit and deal with help right away.
        if args.func == self.do_help:
            self.do_help(args)
            return 0
        elif args.func == self.do_bash_completion:
            self.do_bash_completion(args)
            return 0

        if not options.os_share_api_version:
            api_version = api_versions.get_api_version(
                DEFAULT_MAJOR_OS_SHARE_API_VERSION)
        else:
            api_version = api_versions.get_api_version(
                options.os_share_api_version)

        major_version_string = six.text_type(api_version.ver_major)
        os_service_type = args.service_type
        if not os_service_type:
            os_service_type = constants.SERVICE_TYPES[major_version_string]

        os_endpoint_type = args.endpoint_type or DEFAULT_MANILA_ENDPOINT_TYPE

        client_args = dict(
            username=args.os_username,
            password=args.os_password,
            project_name=args.os_project_name or args.os_tenant_name,
            auth_url=args.os_auth_url,
            insecure=args.insecure,
            region_name=args.os_region_name,
            tenant_id=args.os_project_id or args.os_tenant_id,
            endpoint_type=os_endpoint_type,
            extensions=self.extensions,
            service_type=os_service_type,
            service_name=args.service_name,
            retries=options.retries,
            http_log_debug=args.debug,
            cacert=args.os_cacert,
            use_keyring=args.os_cache,
            force_new_token=args.os_reset_cache,
            user_id=args.os_user_id,
            user_domain_id=args.os_user_domain_id,
            user_domain_name=args.os_user_domain_name,
            project_domain_id=args.os_project_domain_id,
            project_domain_name=args.os_project_domain_name,
            cert=args.os_cert,
            input_auth_token=args.os_token,
            service_catalog_url=args.bypass_url,
        )

        # Handle deprecated parameters
        if args.share_service_name:
            client_args['share_service_name'] = args.share_service_name

        self._validate_required_options(
            args.os_tenant_name, args.os_tenant_id,
            args.os_project_name, args.os_project_id,
            args.os_token, args.bypass_url,
            client_args['auth_url'])

        # This client is needed to discover the server api version.
        temp_client = client.Client(manilaclient.API_MAX_VERSION,
                                    **client_args)

        self.cs, discovered_version = self._discover_client(temp_client,
                                                            os_api_version,
                                                            os_endpoint_type,
                                                            os_service_type,
                                                            client_args)

        args = self._build_subcommands_and_extensions(discovered_version,
                                                      argv,
                                                      options)

        args.func(self.cs, args)
 def test_major_and_minor_parts_is_presented(self, mock_apiversion):
     version = "2.7"
     self.assertEqual(mock_apiversion.return_value,
                      api_versions.get_api_version(version))
     mock_apiversion.assert_called_once_with(version)