appmesh 1.1.9__py3-none-any.whl → 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- appmesh/appmesh_client.py +29 -18
- {appmesh-1.1.9.dist-info → appmesh-1.2.0.dist-info}/METADATA +1 -1
- appmesh-1.2.0.dist-info/RECORD +6 -0
- appmesh-1.1.9.dist-info/RECORD +0 -6
- {appmesh-1.1.9.dist-info → appmesh-1.2.0.dist-info}/WHEEL +0 -0
- {appmesh-1.1.9.dist-info → appmesh-1.2.0.dist-info}/top_level.txt +0 -0
appmesh/appmesh_client.py
CHANGED
@@ -10,9 +10,10 @@ import ssl
|
|
10
10
|
import uuid
|
11
11
|
|
12
12
|
from enum import Enum, unique
|
13
|
+
from datetime import datetime
|
13
14
|
from http import HTTPStatus
|
15
|
+
from typing import Optional
|
14
16
|
from urllib import parse
|
15
|
-
from datetime import datetime
|
16
17
|
|
17
18
|
import aniso8601
|
18
19
|
import requests
|
@@ -48,6 +49,20 @@ def _get_native_item(data: dict, key):
|
|
48
49
|
return copy.deepcopy(data[key]) if (data and key in data and data[key]) else None
|
49
50
|
|
50
51
|
|
52
|
+
class AppOutput(object):
|
53
|
+
"""App output object for app_output() method"""
|
54
|
+
|
55
|
+
def __init__(self, status_code: HTTPStatus, output: str, out_position: Optional[int], exit_code: Optional[int]) -> None:
|
56
|
+
# HTTP status code
|
57
|
+
self.status_code = status_code
|
58
|
+
# HTTP response text
|
59
|
+
self.output = output
|
60
|
+
# Current read position (int or None)
|
61
|
+
self.out_position = out_position
|
62
|
+
# Process exit code (int or None)
|
63
|
+
self.exit_code = exit_code
|
64
|
+
|
65
|
+
|
51
66
|
class App(object):
|
52
67
|
"""
|
53
68
|
App object present an application in App Mesh
|
@@ -539,7 +554,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
539
554
|
apps.append(App(app))
|
540
555
|
return apps
|
541
556
|
|
542
|
-
def app_output(self, app_name: str, stdout_position: int = 0, stdout_index: int = 0, stdout_maxsize: int = 10240, process_uuid: str = "", timeout: int = 0):
|
557
|
+
def app_output(self, app_name: str, stdout_position: int = 0, stdout_index: int = 0, stdout_maxsize: int = 10240, process_uuid: str = "", timeout: int = 0) -> AppOutput:
|
543
558
|
"""Get application stdout/stderr
|
544
559
|
|
545
560
|
Args:
|
@@ -552,10 +567,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
552
567
|
timeout (int, optional): wait for the running process for some time(seconds) to get the output.
|
553
568
|
|
554
569
|
Returns:
|
555
|
-
|
556
|
-
str: output string.
|
557
|
-
int or None: current read position.
|
558
|
-
int or None: process exit code.
|
570
|
+
AppOutput object.
|
559
571
|
"""
|
560
572
|
resp = self._request_http(
|
561
573
|
AppMeshClient.Method.GET,
|
@@ -570,7 +582,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
570
582
|
)
|
571
583
|
out_position = int(resp.headers["Output-Position"]) if "Output-Position" in resp.headers else None
|
572
584
|
exit_code = int(resp.headers["Exit-Code"]) if "Exit-Code" in resp.headers else None
|
573
|
-
return (resp.status_code
|
585
|
+
return AppOutput(status_code=resp.status_code, output=resp.text, out_position=out_position, exit_code=exit_code)
|
574
586
|
|
575
587
|
def app_health(self, app_name: str) -> int:
|
576
588
|
"""Get application health status, 0 is health.
|
@@ -1169,28 +1181,27 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
1169
1181
|
Returns:
|
1170
1182
|
int: return exit code if process finished, return None for timeout or exception.
|
1171
1183
|
"""
|
1172
|
-
exit_code = None
|
1173
1184
|
if run:
|
1174
|
-
|
1185
|
+
last_output_position = 0
|
1175
1186
|
start = datetime.now()
|
1176
1187
|
interval = 1 if self.__class__.__name__ == "AppMeshClient" else 1000
|
1177
1188
|
while len(run.proc_uid) > 0:
|
1178
|
-
|
1179
|
-
if output and stdout_print:
|
1180
|
-
print(output, end="")
|
1181
|
-
if
|
1182
|
-
|
1183
|
-
if exit_code is not None:
|
1189
|
+
app_out = self.app_output(app_name=run.app_name, stdout_position=last_output_position, stdout_index=0, process_uuid=run.proc_uid, timeout=interval)
|
1190
|
+
if app_out.output and stdout_print:
|
1191
|
+
print(app_out.output, end="")
|
1192
|
+
if app_out.out_position is not None:
|
1193
|
+
last_output_position = app_out.out_position
|
1194
|
+
if app_out.exit_code is not None:
|
1184
1195
|
# success
|
1185
1196
|
self.app_delete(run.app_name)
|
1186
|
-
|
1187
|
-
if
|
1197
|
+
return app_out.exit_code
|
1198
|
+
if app_out.status_code != HTTPStatus.OK:
|
1188
1199
|
# failed
|
1189
1200
|
break
|
1190
1201
|
if timeout > 0 and (datetime.now() - start).seconds > timeout:
|
1191
1202
|
# timeout
|
1192
1203
|
break
|
1193
|
-
return
|
1204
|
+
return None
|
1194
1205
|
|
1195
1206
|
def run_sync(
|
1196
1207
|
self,
|
@@ -0,0 +1,6 @@
|
|
1
|
+
appmesh/__init__.py,sha256=xRdXeFHEieRauuJZElbEBASgXG0ZzU1a5_0isAhM7Gw,11
|
2
|
+
appmesh/appmesh_client.py,sha256=Gpf7pdqijTThDQQWH3gDPSZO7Wfjpdp4h4yUpkdk_aQ,60075
|
3
|
+
appmesh-1.2.0.dist-info/METADATA,sha256=aOLMvUjWhjrg3DzFdUs6luSMZlHo4ZVsksqgYO3Xr20,10928
|
4
|
+
appmesh-1.2.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
5
|
+
appmesh-1.2.0.dist-info/top_level.txt,sha256=-y0MNQOGJxUzLdHZ6E_Rfv5_LNCkV-GTmOBME_b6pg8,8
|
6
|
+
appmesh-1.2.0.dist-info/RECORD,,
|
appmesh-1.1.9.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
appmesh/__init__.py,sha256=xRdXeFHEieRauuJZElbEBASgXG0ZzU1a5_0isAhM7Gw,11
|
2
|
-
appmesh/appmesh_client.py,sha256=8nnB38J3wvS8tguEzX_KTJkilW6uMoA4opKIaDq1lG0,59591
|
3
|
-
appmesh-1.1.9.dist-info/METADATA,sha256=UDHcFjxQFDL5Ld2v-LguTsuWcx8_pzKR6I3wyMHI3is,10928
|
4
|
-
appmesh-1.1.9.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
5
|
-
appmesh-1.1.9.dist-info/top_level.txt,sha256=-y0MNQOGJxUzLdHZ6E_Rfv5_LNCkV-GTmOBME_b6pg8,8
|
6
|
-
appmesh-1.1.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|