-
Notifications
You must be signed in to change notification settings - Fork 447
Expand file tree
/
Copy pathserver_info_item.py
More file actions
78 lines (63 loc) · 2.57 KB
/
server_info_item.py
File metadata and controls
78 lines (63 loc) · 2.57 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import logging
import warnings
import xml
from defusedxml.ElementTree import fromstring
from tableauserverclient.helpers.logging import logger
class ServerInfoItem:
"""
The ServerInfoItem class contains the build and version information for
Tableau Server. The server information is accessed with the
server_info.get() method, which returns an instance of the ServerInfo class.
Attributes
----------
product_version : str
Shows the version of the Tableau Server or Tableau Cloud
(for example, 10.2.0).
build_number : str
Shows the specific build number (for example, 10200.17.0329.1446).
rest_api_version : str
Shows the supported REST API version number. Note that this might be
different from the default value specified for the server, with the
Server.version attribute. To take advantage of new features, you should
query the server and set the Server.version to match the supported REST
API version number.
"""
def __init__(self, product_version, build_number, rest_api_version):
self._product_version = product_version
self._build_number = build_number
self._rest_api_version = rest_api_version
def __repr__(self):
return (
"ServerInfoItem: [product version: "
+ self._product_version
+ ", build no.:"
+ self._build_number
+ ", REST API version:"
+ self.rest_api_version
+ "]"
)
@property
def product_version(self):
return self._product_version
@property
def build_number(self):
return self._build_number
@property
def rest_api_version(self):
return self._rest_api_version
@classmethod
def from_response(cls, resp, ns):
try:
parsed_response = fromstring(resp)
except xml.etree.ElementTree.ParseError as error:
logger.exception(f"Unexpected response for ServerInfo: {resp}")
return cls("Unknown", "Unknown", "Unknown")
except Exception as error:
logger.exception(f"Unexpected response for ServerInfo: {resp}")
raise error
product_version_tag = parsed_response.find(".//t:productVersion", namespaces=ns)
rest_api_version_tag = parsed_response.find(".//t:restApiVersion", namespaces=ns)
build_number = product_version_tag.get("build", None)
product_version = product_version_tag.text
rest_api_version = rest_api_version_tag.text
return cls(product_version, build_number, rest_api_version)