import re
import requests
+from requests.auth import AuthBase
from requests.exceptions import ConnectionError, InvalidURL, Timeout
from .settings import Settings
-from .tools import build_url
try:
from requests.packages.urllib3.exceptions import SSLError
except ImportError:
from urllib3.exceptions import SSLError # type: ignore
-try:
- from typing import List
-except ImportError:
- pass # Just for type checking
+from typing import List, Optional
+from mgr_util import build_url
logger = logging.getLogger('rest_client')
class RestClient(object):
- def __init__(self, host, port, client_name=None, ssl=False, auth=None, ssl_verify=True):
+ def __init__(self,
+ host: str,
+ port: int,
+ client_name: Optional[str] = None,
+ ssl: bool = False,
+ auth: Optional[AuthBase] = None,
+ ssl_verify: bool = True) -> None:
super(RestClient, self).__init__()
self.client_name = client_name if client_name else ''
self.host = host
from distutils.util import strtobool
from subprocess import SubprocessError
+from mgr_util import build_url
+
from .. import mgr
from ..awsauth import S3Auth
from ..exceptions import DashboardException
from ..rest_client import RequestException, RestClient
from ..settings import Settings
-from ..tools import build_url, dict_contains_path, dict_get, json_str_to_object
+from ..tools import dict_contains_path, dict_get, json_str_to_object
try:
from typing import Any, Dict, List, Optional, Tuple, Union
service_url=self.service_url)
def __init__(self,
- access_key,
- secret_key,
- daemon_name,
- user_id=None):
+ access_key: str,
+ secret_key: str,
+ daemon_name: str,
+ user_id: Optional[str] = None) -> None:
try:
daemon = RgwClient._daemons[daemon_name]
except KeyError as error:
from distutils.util import strtobool
import cherrypy
-from ceph.deployment.utils import wrap_ipv6
+from mgr_util import build_url
from . import mgr
from .exceptions import ViewCacheNoDataException
return self._begin_time
-def build_url(host, scheme=None, port=None):
- """
- Build a valid URL. IPv6 addresses specified in host will be enclosed in brackets
- automatically.
-
- >>> build_url('example.com', 'https', 443)
- 'https://example.com:443'
-
- >>> build_url(host='example.com', port=443)
- '//example.com:443'
-
- >>> build_url('fce:9af7:a667:7286:4917:b8d3:34df:8373', port=80, scheme='http')
- 'http://[fce:9af7:a667:7286:4917:b8d3:34df:8373]:80'
-
- :param scheme: The scheme, e.g. http, https or ftp.
- :type scheme: str
- :param host: Consisting of either a registered name (including but not limited to
- a hostname) or an IP address.
- :type host: str
- :type port: int
- :rtype: str
- """
- netloc = wrap_ipv6(host)
- if port:
- netloc += ':{}'.format(port)
- pr = urllib.parse.ParseResult(
- scheme=scheme if scheme else '',
- netloc=netloc,
- path='',
- params='',
- query='',
- fragment='')
- return pr.geturl()
-
-
def prepare_url_prefix(url_prefix):
"""
return '' if no prefix, or '/prefix' without slash in the end.
import sys
from threading import Lock, Condition, Event
from typing import no_type_check
+import urllib
from functools import wraps
if sys.version_info >= (3, 3):
from threading import Timer
from threading import _Timer as Timer
from typing import Tuple, Any, Callable, Optional, Dict, TYPE_CHECKING, TypeVar, List, Iterable, Generator, Generic, Iterator
+
+from ceph.deployment.utils import wrap_ipv6
+
T = TypeVar('T')
if TYPE_CHECKING:
return result
+def build_url(host: str, scheme: Optional[str] = None, port: Optional[int] = None) -> str:
+ """
+ Build a valid URL. IPv6 addresses specified in host will be enclosed in brackets
+ automatically.
+
+ >>> build_url('example.com', 'https', 443)
+ 'https://example.com:443'
+
+ >>> build_url(host='example.com', port=443)
+ '//example.com:443'
+
+ >>> build_url('fce:9af7:a667:7286:4917:b8d3:34df:8373', port=80, scheme='http')
+ 'http://[fce:9af7:a667:7286:4917:b8d3:34df:8373]:80'
+
+ :param scheme: The scheme, e.g. http, https or ftp.
+ :type scheme: str
+ :param host: Consisting of either a registered name (including but not limited to
+ a hostname) or an IP address.
+ :type host: str
+ :type port: int
+ :rtype: str
+ """
+ netloc = wrap_ipv6(host)
+ if port:
+ netloc += ':{}'.format(port)
+ pr = urllib.parse.ParseResult(
+ scheme=scheme if scheme else '',
+ netloc=netloc,
+ path='',
+ params='',
+ query='',
+ fragment='')
+ return pr.geturl()
+
+
class ServerConfigException(Exception):
pass