|
|
def | __init__ (self, _cu, _data_category, _server, _username, _password, **kwargs) |
| |
| def | run (self) |
| |
|
def | __str__ (self) |
| |
|
|
| cu |
| |
|
| data_category |
| |
|
| server |
| |
|
| username |
| |
|
| password |
| |
|
| payload |
| |
|
| getstream |
| |
|
| histstatus |
| |
|
| endpoint_script |
| |
|
| response |
| |
Retrieve response from Mammoth.
Definition at line 21 of file ody_migr_mmth_endpoint.py.
◆ _dest_url()
| def ody_migr_mmth_endpoint.MammothMigration._dest_url |
( |
|
self | ) |
|
|
private |
Generate a Mammoth endpoint url
Definition at line 71 of file ody_migr_mmth_endpoint.py.
72 """Generate a Mammoth endpoint url""" 73 hash = generate_hash(self.data_category, self.cu,
74 os.environ.get(ENV_MIGR_SECRET_KEY))
75 server_dest =
"https://{}.homecu.net".format(self.server)
76 if self.data_category == DATA_OPT_GETCULIST:
77 resource_dest = (
"{}?" 79 "action={}").format(self.endpoint_script,
84 resource_dest = (
"{}?" 87 "action={}").format(self.endpoint_script,
91 return os.path.join(server_dest, resource_dest)
◆ _initiate_http_request()
| def ody_migr_mmth_endpoint.MammothMigration._initiate_http_request |
( |
|
self | ) |
|
|
private |
Establish connection with Mammoth and obtain response object
Definition at line 156 of file ody_migr_mmth_endpoint.py.
156 def _initiate_http_request(self):
157 """Establish connection with Mammoth and obtain response object""" 162 with requests.Session()
as s:
163 url = self._dest_url()
164 if self.payload
is None:
167 auth=(self.username, self.password),
168 stream=self.getstream
173 auth=(self.username, self.password),
177 status_code = http_resp.status_code
178 if int(status_code) >= 300:
179 http_resp.raise_for_status()
181 LOGGER.info(
"HTTP response url: {}".format(http_resp.url))
182 if int(status_code) == 200:
183 if self.data_category == DATA_OPT_GET_HIST:
184 self.response = http_resp
187 self.response = http_resp.json()
189 except (requests.exceptions.HTTPError,
190 requests.exceptions.ConnectionError)
as err:
191 LOGGER.error(
"Mammoth endpoint status: {}".format(err))
192 raise SystemExit(err)
◆ _validate_response()
| def ody_migr_mmth_endpoint.MammothMigration._validate_response |
( |
|
self | ) |
|
|
private |
Validate response data returned from Mammoth.
Raises:
SystemExit on error
Definition at line 93 of file ody_migr_mmth_endpoint.py.
93 def _validate_response(self):
94 """Validate response data returned from Mammoth. 102 resp_error = DEFAULT_ERROR_STR
104 if self.data_category == DATA_OPT_GET_HIST:
106 if dict(self.response.headers)[
107 "Content-Type"].strip() ==
"application/json":
108 resp_error = self.response.json()[
"error"]
109 if resp_error != DEFAULT_ERROR_STR:
110 if "Process is already started" in resp_error:
112 if "ERROR:" in resp_error:
113 resp_error = resp_error.split(
"ERROR:")[1].strip()
114 self.histstatus = resp_error
119 if dict(self.response.headers)[
120 "Content-Type"].split(
";")[0].strip() ==
"text/plain":
121 resp_error = self.response.content.decode()
122 if "Process is already started" in resp_error:
124 if "ERROR:" in resp_error:
125 resp_error = resp_error.split(
"ERROR:")[1].strip()
126 self.histstatus = resp_error
131 assert self.response != {}
132 resp_error = self.response[
"error"]
133 if resp_error != DEFAULT_ERROR_STR:
134 if "Process is already started" in resp_error:
136 if "ERROR:" in resp_error:
137 resp_error = resp_error.split(
"ERROR:")[1].strip()
138 self.histstatus = resp_error
143 LOGGER.error(
"Mammoth endpoint status: {}".format(resp_error))
145 "Migration Request with `cu = {} and " 146 "data_category = {}` returned with error. Error: {}" 152 resp_error =
"NORMAL!" if resp_error == DEFAULT_ERROR_STR \
154 LOGGER.info(
"Mammoth endpoint status: {}".format(resp_error))
◆ run()
| def ody_migr_mmth_endpoint.MammothMigration.run |
( |
|
self | ) |
|
Connect to mammoth endpoint and fetch response json data
Definition at line 194 of file ody_migr_mmth_endpoint.py.
195 """Connect to mammoth endpoint and fetch response json data""" 196 self._initiate_http_request()
197 self._validate_response()
The documentation for this class was generated from the following file: