]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/tools.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / tools.py
index ec88cbbff74c6165a2f069f4dab1c37517214bbd..a6f14e82d00845a2a14b8ba27cde3c14b0a49003 100644 (file)
@@ -1,36 +1,28 @@
 # -*- coding: utf-8 -*-
 from __future__ import absolute_import
 
-import sys
+import collections
+import fnmatch
 import inspect
 import json
-import functools
 import logging
-
-import collections
+import threading
+import time
+import urllib
 from datetime import datetime, timedelta
 from distutils.util import strtobool
-import fnmatch
-import time
-import threading
-from six.moves import urllib
-import cherrypy
-
-try:
-    from urlparse import urljoin
-except ImportError:
-    from urllib.parse import urljoin
 
+import cherrypy
 from ceph.deployment.utils import wrap_ipv6
 
 from . import mgr
 from .exceptions import ViewCacheNoDataException
-from .settings import Settings
 from .services.auth import JwtManager
+from .settings import Settings
 
 try:
-    from typing import Any, AnyStr, Callable, DefaultDict, Deque,\
-        Dict, List, Set, Tuple, Union  # noqa pylint: disable=unused-import
+    from typing import Any, AnyStr, Callable, DefaultDict, Deque, Dict, List, \
+        Optional, Set, Tuple, Union
 except ImportError:
     pass  # For typing only
 
@@ -74,7 +66,7 @@ class RequestLoggingTool(cherrypy.Tool):
                 for key in keys:
                     params[key] = '***'
                 msg = '{} params=\'{}\''.format(msg, json.dumps(params))
-            mgr.cluster_log('audit', mgr.CLUSTER_LOG_PRIO_INFO, msg)
+            mgr.cluster_log('audit', mgr.ClusterLogPrio.INFO, msg)
 
     def request_error(self):
         self._request_log(self.logger.error)
@@ -578,9 +570,9 @@ class Task(object):
         self.event = threading.Event()
         self.progress = None
         self.ret_value = None
-        self.begin_time = None
-        self.end_time = None
-        self.duration = 0
+        self._begin_time: Optional[float] = None
+        self._end_time: Optional[float] = None
+        self.duration = 0.0
         self.exception = None
         self.logger = logging.getLogger('task')
         self.lock = threading.Lock()
@@ -604,7 +596,7 @@ class Task(object):
             assert not self.running
             self.executor.init(self)
             self.set_progress(0, in_lock=True)
-            self.begin_time = time.time()
+            self._begin_time = time.time()
             self.running = True
         self.executor.start()
 
@@ -618,10 +610,10 @@ class Task(object):
                 exception = ex
         with self.lock:
             assert self.running, "_complete cannot be called before _run"
-            self.end_time = now
+            self._end_time = now
             self.ret_value = ret_value
             self.exception = exception
-            self.duration = now - self.begin_time  # type: ignore
+            self.duration = now - self.begin_time
             if not self.exception:
                 self.set_progress(100, True)
         NotificationQueue.new_notification('cd_task_finished', self)
@@ -670,6 +662,16 @@ class Task(object):
         if not in_lock:
             self.lock.release()
 
+    @property
+    def end_time(self) -> float:
+        assert self._end_time is not None
+        return self._end_time
+
+    @property
+    def begin_time(self) -> float:
+        assert self._begin_time is not None
+        return self._begin_time
+
 
 def build_url(host, scheme=None, port=None):
     """
@@ -710,7 +712,7 @@ def prepare_url_prefix(url_prefix):
     """
     return '' if no prefix, or '/prefix' without slash in the end.
     """
-    url_prefix = urljoin('/', url_prefix)
+    url_prefix = urllib.parse.urljoin('/', url_prefix)
     return url_prefix.rstrip('/')
 
 
@@ -748,20 +750,6 @@ def dict_get(obj, path, default=None):
     return current
 
 
-if sys.version_info > (3, 0):
-    wraps = functools.wraps
-    _getargspec = inspect.getfullargspec
-else:
-    def wraps(func):
-        def decorator(wrapper):
-            new_wrapper = functools.wraps(func)(wrapper)
-            new_wrapper.__wrapped__ = func  # set __wrapped__ even for Python 2
-            return new_wrapper
-        return decorator
-
-    _getargspec = inspect.getargspec
-
-
 def getargspec(func):
     try:
         while True:
@@ -769,7 +757,7 @@ def getargspec(func):
     except AttributeError:
         pass
     # pylint: disable=deprecated-method
-    return _getargspec(func)
+    return inspect.getfullargspec(func)
 
 
 def str_to_bool(val):