-
Notifications
You must be signed in to change notification settings - Fork 425
/
Copy pathserver_info_endpoint.py
47 lines (39 loc) · 1.42 KB
/
server_info_endpoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import logging
from .endpoint import Endpoint, api
from .exceptions import ServerResponseError
from ..exceptions import (
ServerInfoEndpointNotFoundError,
EndpointUnavailableError,
)
from tableauserverclient.models import ServerInfoItem
class ServerInfo(Endpoint):
def __init__(self, server):
self.parent_srv = server
self._info = None
@property
def serverInfo(self):
if not self._info:
self.get()
return self._info
def __repr__(self):
return "<Endpoint {}>".format(self.serverInfo)
@property
def baseurl(self):
return "{0}/serverInfo".format(self.parent_srv.baseurl)
@api(version="2.4")
def get(self):
"""Retrieve the server info for the server. This is an unauthenticated call"""
try:
server_response = self.get_unauthenticated_request(self.baseurl)
except ServerResponseError as e:
if e.code == "404003":
raise ServerInfoEndpointNotFoundError(e)
if e.code == "404001":
raise EndpointUnavailableError(e)
raise e
try:
self._info = ServerInfoItem.from_response(server_response.content, self.parent_srv.namespace)
except Exception as e:
logging.getLogger(self.__class__.__name__).debug(e)
logging.getLogger(self.__class__.__name__).debug(server_response.content)
return self._info