]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/rest_client.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / rest_client.py
index 4d58d0dfde17f2b71093f36062b6b93d0427b5a4..90cfd41ad77ebb925847b0fa998ba202bae1730b 100644 (file)
@@ -16,8 +16,10 @@ from __future__ import absolute_import
 import inspect
 import logging
 import re
+
 import requests
 from requests.exceptions import ConnectionError, InvalidURL, Timeout
+
 from .settings import Settings
 from .tools import build_url
 
@@ -39,6 +41,7 @@ class TimeoutRequestsSession(requests.Session):
     """
     Set timeout argument for all requests if this is not already done.
     """
+
     def request(self, *args, **kwargs):
         if ((args[8] if len(args) > 8 else None) is None) \
                 and kwargs.get('timeout') is None:
@@ -442,7 +445,7 @@ class RestClient(object):
                     "{}"  # TODO remove
                     .format(self.client_name, resp.status_code, pf(
                         resp.content)),
-                    resp.status_code,
+                    self._handle_response_status_code(resp.status_code),
                     resp.content)
         except ConnectionError as ex:
             if ex.args:
@@ -503,15 +506,22 @@ class RestClient(object):
             logger.exception(msg)
             raise RequestException(msg)
 
+    @staticmethod
+    def _handle_response_status_code(status_code: int) -> int:
+        """
+        Method to be overridden by subclasses that need specific handling.
+        """
+        return status_code
+
     @staticmethod
     def api(path, **api_kwargs):
         def call_decorator(func):
             def func_wrapper(self, *args, **kwargs):
                 method = api_kwargs.get('method', None)
                 resp_structure = api_kwargs.get('resp_structure', None)
-                args_name = inspect.getargspec(func).args
+                args_name = inspect.getfullargspec(func).args
                 args_dict = dict(zip(args_name[1:], args))
-                for key, val in kwargs:
+                for key, val in kwargs.items():
                     args_dict[key] = val
                 return func(
                     self,