diff --git a/podman/api/client.py b/podman/api/client.py index 880fdc3d..7a98669b 100644 --- a/podman/api/client.py +++ b/podman/api/client.py @@ -1,6 +1,7 @@ """APIClient for connecting to Podman service.""" import json +import warnings import urllib.parse from typing import Any, ClassVar, IO, Iterable, List, Mapping, Optional, Tuple, Type, Union @@ -28,6 +29,16 @@ """Type alias for request timeout parameter.""" +class ParameterDeprecationWarning(DeprecationWarning): + """ + Custom DeprecationWarning for deprecated parameters. + """ + + +# Make the ParameterDeprecationWarning visible for user. +warnings.simplefilter('always', ParameterDeprecationWarning) + + class APIResponse: """APIResponse proxy requests.Response objects. @@ -89,7 +100,8 @@ def __init__( num_pools: Optional[int] = None, credstore_env: Optional[Mapping[str, str]] = None, use_ssh_client=True, - max_pools_size=None, + max_pool_size=None, + max_pools_size=None, # This parameter is kept only for backward compatibility. **kwargs, ): # pylint: disable=unused-argument """Instantiate APIClient object. @@ -103,6 +115,7 @@ def __init__( num_pools: The number of connection pools to cache. credstore_env: Environment for storing credentials. use_ssh_client: Use system ssh agent rather than ssh module. Always, True. + max_pools_size: Deprecated! Please use 'max_pool_size'. max_pool_size: Override number of connections pools to maintain. Default: requests.adapters.DEFAULT_POOLSIZE @@ -117,10 +130,32 @@ def __init__( self.base_url = self._normalize_url(base_url) adapter_kwargs = kwargs.copy() + + # The HTTPAdapter doesn't handle the "**kwargs", so it needs special structure + # where the parameters are set specifically. + http_adapter_kwargs = {} + + # 'max_pools_size' has been changed to 'max_pool_size' + # and the below section is needed for backward compatible. + # This section can be removed in a future release. + if max_pools_size is not None: + warnings.warn( + "'max_pools_size' parameter is deprecated! Please use 'max_pool_size' parameter.", + ParameterDeprecationWarning, + ) + if max_pool_size is not None: + raise ValueError( + "Both of 'max_pools_size' and 'max_pool_size' parameters are set. " + "Please use only the 'max_pool_size', 'max_pools_size' is deprecated!" + ) + max_pool_size = max_pools_size + if num_pools is not None: adapter_kwargs["pool_connections"] = num_pools - if max_pools_size is not None: - adapter_kwargs["pool_maxsize"] = max_pools_size + http_adapter_kwargs["pool_connections"] = num_pools + if max_pool_size is not None: + adapter_kwargs["pool_maxsize"] = max_pool_size + http_adapter_kwargs["pool_maxsize"] = max_pool_size if timeout is not None: adapter_kwargs["timeout"] = timeout @@ -133,8 +168,8 @@ def __init__( self.mount("https://", SSHAdapter(self.base_url.geturl(), **adapter_kwargs)) elif self.base_url.scheme == "http": - self.mount("http://", HTTPAdapter(**adapter_kwargs)) - self.mount("https://", HTTPAdapter(**adapter_kwargs)) + self.mount("http://", HTTPAdapter(**http_adapter_kwargs)) + self.mount("https://", HTTPAdapter(**http_adapter_kwargs)) else: assert False, "APIClient.supported_schemes changed without adding a branch here."