Update watcher api command argument
This patch set updates watcher api command argument. 1. os_watcher_api_version to os_infra_optim_api_version 2. OS_WATCHER_API_VERSION to OS_INFRA_OPTIM_API_VERSION This patch set also updated --os-infra-optim-api-version help message. Change-Id: I2502377b350b8cabfeba80c68f0569d567d24b3a
This commit is contained in:
		| @@ -136,7 +136,7 @@ watcher optional arguments | ||||
|   Defaults to ``env[OS_AUTH_TOKEN]``. | ||||
|  | ||||
| ``--os-watcher-api-version <os-watcher-api-version>`` | ||||
|   Defaults to ``env[OS_WATCHER_API_VERSION]``. | ||||
|   Defaults to ``env[OS_INFRA_OPTIM_API_VERSION]``. | ||||
|  | ||||
| ``--os-endpoint-type OS_ENDPOINT_TYPE`` | ||||
|   Defaults to ``env[OS_ENDPOINT_TYPE]`` or "publicURL" | ||||
|   | ||||
| @@ -28,7 +28,7 @@ def get_client(api_version, os_auth_token=None, watcher_url=None, | ||||
|                os_service_type=None, os_endpoint_type=None, | ||||
|                insecure=None, timeout=None, os_cacert=None, ca_file=None, | ||||
|                os_cert=None, cert_file=None, os_key=None, key_file=None, | ||||
|                os_watcher_api_version=None, max_retries=None, | ||||
|                os_infra_optim_api_version=None, max_retries=None, | ||||
|                retry_interval=None, session=None, os_endpoint_override=None, | ||||
|                **ignored_kwargs): | ||||
|     """Get an authenticated client, based on the credentials. | ||||
| @@ -61,7 +61,7 @@ def get_client(api_version, os_auth_token=None, watcher_url=None, | ||||
|     :param cert_file: path to cert file, deprecated in favour of os_cert | ||||
|     :param os_key: path to key file | ||||
|     :param key_file: path to key file, deprecated in favour of os_key | ||||
|     :param os_watcher_api_version: watcher API version to use | ||||
|     :param os_infra_optim_api_version: watcher API version to use | ||||
|     :param max_retries: Maximum number of retries in case of conflict error | ||||
|     :param retry_interval: Amount of time (in seconds) between retries in case | ||||
|         of conflict error | ||||
| @@ -75,7 +75,7 @@ def get_client(api_version, os_auth_token=None, watcher_url=None, | ||||
|     project_id = (os_project_id or os_tenant_id) | ||||
|     project_name = (os_project_name or os_tenant_name) | ||||
|     kwargs = { | ||||
|         'os_watcher_api_version': os_watcher_api_version, | ||||
|         'os_infra_optim_api_version': os_infra_optim_api_version, | ||||
|         'max_retries': max_retries, | ||||
|         'retry_interval': retry_interval, | ||||
|     } | ||||
|   | ||||
| @@ -116,25 +116,25 @@ class VersionNegotiationMixin(object): | ||||
|                   "server or the requested operation is not supported by the " | ||||
|                   "requested version.  Supported version range is %(min)s to " | ||||
|                   "%(max)s") | ||||
|                 % {'req': self.os_watcher_api_version, | ||||
|                 % {'req': self.os_infra_optim_api_version, | ||||
|                    'min': min_ver, 'max': max_ver})) | ||||
|         if self.api_version_select_state == 'negotiated': | ||||
|             raise exceptions.UnsupportedVersion(textwrap.fill( | ||||
|                 _("No API version was specified and the requested operation " | ||||
|                   "was not supported by the client's negotiated API version " | ||||
|                   "%(req)s.  Supported version range is: %(min)s to %(max)s") | ||||
|                 % {'req': self.os_watcher_api_version, | ||||
|                 % {'req': self.os_infra_optim_api_version, | ||||
|                    'min': min_ver, 'max': max_ver})) | ||||
|  | ||||
|         negotiated_ver = str( | ||||
|             min(version.StrictVersion(self.os_watcher_api_version), | ||||
|             min(version.StrictVersion(self.os_infra_optim_api_version), | ||||
|                 version.StrictVersion(max_ver))) | ||||
|         if negotiated_ver < min_ver: | ||||
|             negotiated_ver = min_ver | ||||
|         # server handles microversions, but doesn't support | ||||
|         # the requested version, so try a negotiated version | ||||
|         self.api_version_select_state = 'negotiated' | ||||
|         self.os_watcher_api_version = negotiated_ver | ||||
|         self.os_infra_optim_api_version = negotiated_ver | ||||
|         LOG.debug('Negotiated API version is %s', negotiated_ver) | ||||
|  | ||||
|         return negotiated_ver | ||||
| @@ -196,8 +196,8 @@ class HTTPClient(VersionNegotiationMixin): | ||||
|         self.endpoint_trimmed = _trim_endpoint_api_version(endpoint) | ||||
|         self.auth_token = kwargs.get('token') | ||||
|         self.auth_ref = kwargs.get('auth_ref') | ||||
|         self.os_watcher_api_version = kwargs.get('os_watcher_api_version', | ||||
|                                                  DEFAULT_VER) | ||||
|         self.os_infra_optim_api_version = kwargs.get( | ||||
|             'os_infra_optim_api_version', DEFAULT_VER) | ||||
|         self.api_version_select_state = kwargs.get( | ||||
|             'api_version_select_state', 'default') | ||||
|         self.conflict_max_retries = kwargs.pop('max_retries', | ||||
| @@ -297,10 +297,10 @@ class HTTPClient(VersionNegotiationMixin): | ||||
|         # Copy the kwargs so we can reuse the original in case of redirects | ||||
|         kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {})) | ||||
|         kwargs['headers'].setdefault('User-Agent', USER_AGENT) | ||||
|         if self.os_watcher_api_version: | ||||
|         if self.os_infra_optim_api_version: | ||||
|             kwargs['headers'].setdefault( | ||||
|                 'OpenStack-API-Version', | ||||
|                 ' '.join(['infra-optim', self.os_watcher_api_version])) | ||||
|                 ' '.join(['infra-optim', self.os_infra_optim_api_version])) | ||||
|         if self.auth_token: | ||||
|             kwargs['headers'].setdefault('X-Auth-Token', self.auth_token) | ||||
|  | ||||
| @@ -476,13 +476,13 @@ class SessionClient(VersionNegotiationMixin, adapter.LegacyJsonAdapter): | ||||
|     """HTTP client based on Keystone client session.""" | ||||
|  | ||||
|     def __init__(self, | ||||
|                  os_watcher_api_version, | ||||
|                  os_infra_optim_api_version, | ||||
|                  api_version_select_state, | ||||
|                  max_retries, | ||||
|                  retry_interval, | ||||
|                  endpoint, | ||||
|                  **kwargs): | ||||
|         self.os_watcher_api_version = os_watcher_api_version | ||||
|         self.os_infra_optim_api_version = os_infra_optim_api_version | ||||
|         self.api_version_select_state = api_version_select_state | ||||
|         self.conflict_max_retries = max_retries | ||||
|         self.conflict_retry_interval = retry_interval | ||||
| @@ -507,11 +507,11 @@ class SessionClient(VersionNegotiationMixin, adapter.LegacyJsonAdapter): | ||||
|                 _trim_endpoint_api_version(self.endpoint_override) | ||||
|             ) | ||||
|  | ||||
|         if getattr(self, 'os_watcher_api_version', None): | ||||
|         if getattr(self, 'os_infra_optim_api_version', None): | ||||
|             kwargs['headers'].setdefault( | ||||
|                 'OpenStack-API-Version', | ||||
|                 ' '.join(['infra-optim', | ||||
|                           self.os_watcher_api_version])) | ||||
|                           self.os_infra_optim_api_version])) | ||||
|  | ||||
|         endpoint_filter = kwargs.setdefault('endpoint_filter', {}) | ||||
|         endpoint_filter.setdefault('interface', self.interface) | ||||
| @@ -575,7 +575,7 @@ def _construct_http_client(endpoint=None, | ||||
|                            session=None, | ||||
|                            token=None, | ||||
|                            auth_ref=None, | ||||
|                            os_watcher_api_version=DEFAULT_VER, | ||||
|                            os_infra_optim_api_version=DEFAULT_VER, | ||||
|                            api_version_select_state='default', | ||||
|                            max_retries=DEFAULT_MAX_RETRIES, | ||||
|                            retry_interval=DEFAULT_RETRY_INTERVAL, | ||||
| @@ -606,8 +606,9 @@ def _construct_http_client(endpoint=None, | ||||
|                         'the session to construct a client: %s', | ||||
|                         ', '.join(dvars)) | ||||
|  | ||||
|         return SessionClient(session=session, | ||||
|                              os_watcher_api_version=os_watcher_api_version, | ||||
|         return SessionClient( | ||||
|             session=session, | ||||
|             os_infra_optim_api_version=os_infra_optim_api_version, | ||||
|             api_version_select_state=api_version_select_state, | ||||
|             max_retries=max_retries, | ||||
|             retry_interval=retry_interval, | ||||
| @@ -618,10 +619,11 @@ def _construct_http_client(endpoint=None, | ||||
|             LOG.warning('The following arguments are being ignored when ' | ||||
|                         'constructing the client: %s', ', '.join(kwargs)) | ||||
|  | ||||
|         return HTTPClient(endpoint=endpoint, | ||||
|         return HTTPClient( | ||||
|             endpoint=endpoint, | ||||
|             token=token, | ||||
|             auth_ref=auth_ref, | ||||
|                           os_watcher_api_version=os_watcher_api_version, | ||||
|             os_infra_optim_api_version=os_infra_optim_api_version, | ||||
|             api_version_select_state=api_version_select_state, | ||||
|             max_retries=max_retries, | ||||
|             retry_interval=retry_interval, | ||||
|   | ||||
| @@ -41,7 +41,7 @@ def make_client(instance): | ||||
|     LOG.debug('Instantiating infraoptim client: %s', infraoptim_client_class) | ||||
|  | ||||
|     client = infraoptim_client_class( | ||||
|         os_watcher_api_version=instance._api_version[API_NAME], | ||||
|         os_infra_optim_api_version=instance._api_version[API_NAME], | ||||
|         session=instance.session, | ||||
|         region_name=instance._region_name, | ||||
|     ) | ||||
|   | ||||
| @@ -39,6 +39,7 @@ API_NAME = 'infra-optim' | ||||
| API_VERSIONS = { | ||||
|     '1': 'watcherclient.v1.client.Client', | ||||
| } | ||||
| DEFAULT_OS_INFRA_OPTIM_API_VERSION = '1.latest' | ||||
| _DEFAULT_IDENTITY_API_VERSION = '3' | ||||
| _IDENTITY_API_VERSION_2 = ['2', '2.0'] | ||||
| _IDENTITY_API_VERSION_3 = ['3'] | ||||
| @@ -147,11 +148,13 @@ class WatcherShell(app.App): | ||||
|                             metavar='<auth-token>', | ||||
|                             default=utils.env('OS_AUTH_TOKEN'), | ||||
|                             help='Defaults to env[OS_AUTH_TOKEN].') | ||||
|         parser.add_argument('--os-watcher-api-version', | ||||
|                             metavar='<os-watcher-api-version>', | ||||
|                             default=utils.env('OS_WATCHER_API_VERSION', | ||||
|                                               default='1'), | ||||
|                             help='Defaults to env[OS_WATCHER_API_VERSION].') | ||||
|         parser.add_argument( | ||||
|             '--os-infra-optim-api-version', | ||||
|             metavar='<infra-optim-api-version>', | ||||
|             default=utils.env('OS_INFRA_OPTIM_API_VERSION', | ||||
|                               default=DEFAULT_OS_INFRA_OPTIM_API_VERSION), | ||||
|             help='Accepts X, X.Y (where X is major and Y is minor part) or ' | ||||
|                  '"X.latest", defaults to env[OS_INFRA_OPTIM_API_VERSION].') | ||||
|         parser.add_argument('--os-endpoint-type', | ||||
|                             default=utils.env('OS_ENDPOINT_TYPE'), | ||||
|                             help='Defaults to env[OS_ENDPOINT_TYPE] or ' | ||||
|   | ||||
| @@ -118,7 +118,7 @@ class ClientTest(utils.BaseTestCase): | ||||
|             'os_password': 'PASSWORD', | ||||
|             'os_auth_url': 'http://localhost:35357/v2.0', | ||||
|             'os_auth_token': '', | ||||
|             'os_watcher_api_version': "latest", | ||||
|             'os_infra_optim_api_version': "latest", | ||||
|         } | ||||
|         self._test_get_client(**kwargs) | ||||
|  | ||||
| @@ -129,7 +129,7 @@ class ClientTest(utils.BaseTestCase): | ||||
|             'os_password': 'PASSWORD', | ||||
|             'os_auth_url': 'http://localhost:35357/v2.0', | ||||
|             'os_auth_token': '', | ||||
|             'os_watcher_api_version': "1.4", | ||||
|             'os_infra_optim_api_version': "1.4", | ||||
|         } | ||||
|         self._test_get_client(**kwargs) | ||||
|  | ||||
| @@ -267,7 +267,7 @@ class ClientTest(utils.BaseTestCase): | ||||
|         kwargs = { | ||||
|             'watcher_url': 'http://watcher.example.org:9322/', | ||||
|             'os_auth_token': 'USER_AUTH_TOKEN', | ||||
|             'os_watcher_api_version': 'latest', | ||||
|             'os_infra_optim_api_version': 'latest', | ||||
|             'insecure': True, | ||||
|             'max_retries': 10, | ||||
|             'retry_interval': 10, | ||||
| @@ -277,7 +277,7 @@ class ClientTest(utils.BaseTestCase): | ||||
|         mock_client.assert_called_once_with( | ||||
|             '1', 'http://watcher.example.org:9322/', | ||||
|             **{ | ||||
|                 'os_watcher_api_version': 'latest', | ||||
|                 'os_infra_optim_api_version': 'latest', | ||||
|                 'max_retries': 10, | ||||
|                 'retry_interval': 10, | ||||
|                 'token': 'USER_AUTH_TOKEN', | ||||
| @@ -309,7 +309,7 @@ class ClientTest(utils.BaseTestCase): | ||||
|         mock_client.assert_called_once_with( | ||||
|             '1', session.get_endpoint.return_value, | ||||
|             **{ | ||||
|                 'os_watcher_api_version': None, | ||||
|                 'os_infra_optim_api_version': None, | ||||
|                 'max_retries': None, | ||||
|                 'retry_interval': None, | ||||
|                 'session': session, | ||||
| @@ -328,7 +328,7 @@ class ClientTest(utils.BaseTestCase): | ||||
|         mock_client.assert_called_once_with( | ||||
|             '1', session.get_endpoint.return_value, | ||||
|             **{ | ||||
|                 'os_watcher_api_version': None, | ||||
|                 'os_infra_optim_api_version': None, | ||||
|                 'max_retries': None, | ||||
|                 'retry_interval': None, | ||||
|                 'session': session, | ||||
|   | ||||
| @@ -25,7 +25,7 @@ from watcherclient.tests.unit import utils | ||||
|  | ||||
| class CommandTestCase(utils.BaseTestCase): | ||||
|  | ||||
|     def setUp(self, os_watcher_api_version='1.0'): | ||||
|     def setUp(self, os_infra_optim_api_version='1.0'): | ||||
|         super(CommandTestCase, self).setUp() | ||||
|  | ||||
|         self.fake_env = { | ||||
| @@ -38,7 +38,7 @@ class CommandTestCase(utils.BaseTestCase): | ||||
|             'os_username': 'test', | ||||
|             'os_password': 'test', | ||||
|             'timeout': 600, | ||||
|             'os_watcher_api_version': os_watcher_api_version} | ||||
|             'os_infra_optim_api_version': os_infra_optim_api_version} | ||||
|         self.m_env = mock.Mock( | ||||
|             name='m_env', | ||||
|             side_effect=lambda x, *args, **kwargs: self.fake_env.get( | ||||
|   | ||||
| @@ -128,9 +128,9 @@ class AuditShellTest(base.CommandTestCase): | ||||
|                     'Strategy', 'Audit Scope', 'Auto Trigger', | ||||
|                     'Next Run Time', 'Hostname'] | ||||
|  | ||||
|     def setUp(self, os_watcher_api_version='1.0'): | ||||
|     def setUp(self, os_infra_optim_api_version='1.0'): | ||||
|         super(AuditShellTest, self).setUp( | ||||
|             os_watcher_api_version=os_watcher_api_version) | ||||
|             os_infra_optim_api_version=os_infra_optim_api_version) | ||||
|  | ||||
|         # goal mock | ||||
|         p_goal_manager = mock.patch.object(resource, 'GoalManager') | ||||
| @@ -468,7 +468,7 @@ class AuditShellTest(base.CommandTestCase): | ||||
|  | ||||
| class AuditShellTestv11(AuditShellTest): | ||||
|     def setUp(self): | ||||
|         super(AuditShellTestv11, self).setUp(os_watcher_api_version='1.1') | ||||
|         super(AuditShellTestv11, self).setUp(os_infra_optim_api_version='1.1') | ||||
|         v11 = dict(start_time=None, end_time=None) | ||||
|         for audit in (self.AUDIT_1, self.AUDIT_2, self.AUDIT_3): | ||||
|             audit.update(v11) | ||||
|   | ||||
| @@ -29,7 +29,7 @@ from watcherclient.v1 import resource_fields as res_fields | ||||
| def drop_start_end_field(app_args, fields, field_labels): | ||||
|     fields = copy.copy(fields) | ||||
|     field_labels = copy.copy(field_labels) | ||||
|     api_ver = app_args.os_watcher_api_version | ||||
|     api_ver = app_args.os_infra_optim_api_version | ||||
|     if not api_versioning.allow_start_end_audit_time(api_ver): | ||||
|         for field, label in zip(('start_time', 'end_time'), | ||||
|                                 ('Start Time', 'End Time')): | ||||
| @@ -230,7 +230,7 @@ class CreateAudit(command.ShowOne): | ||||
|                       'interval', 'goal', 'strategy', 'auto_trigger', | ||||
|                       'name'] | ||||
|  | ||||
|         api_ver = self.app_args.os_watcher_api_version | ||||
|         api_ver = self.app_args.os_infra_optim_api_version | ||||
|         if api_versioning.allow_start_end_audit_time(api_ver): | ||||
|             if parsed_args.start_time is not None: | ||||
|                 field_list.append('start_time') | ||||
|   | ||||
| @@ -31,19 +31,19 @@ class Client(object): | ||||
|  | ||||
|     def __init__(self, endpoint=None, *args, **kwargs): | ||||
|         """Initialize a new client for the Watcher v1 API.""" | ||||
|         if kwargs.get('os_watcher_api_version'): | ||||
|         if kwargs.get('os_infra_optim_api_version'): | ||||
|             kwargs['api_version_select_state'] = "user" | ||||
|         else: | ||||
|             if not endpoint: | ||||
|                 raise exceptions.EndpointException( | ||||
|                     _("Must provide 'endpoint' if os_watcher_api_version " | ||||
|                     _("Must provide 'endpoint' if os_infra_optim_api_version " | ||||
|                       "isn't specified")) | ||||
|  | ||||
|             # If the user didn't specify a version, use a cached version if | ||||
|             # one has been stored | ||||
|             host, netport = httpclient.get_server(endpoint) | ||||
|             kwargs['api_version_select_state'] = "default" | ||||
|             kwargs['os_watcher_api_version'] = httpclient.DEFAULT_VER | ||||
|             kwargs['os_infra_optim_api_version'] = httpclient.DEFAULT_VER | ||||
|  | ||||
|         self.http_client = httpclient._construct_http_client( | ||||
|             endpoint, *args, **kwargs) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Hidekazu Nakamura
					Hidekazu Nakamura