deploy fix bug
This commit is contained in:
parent
4cd2d4e31c
commit
e69c17592e
@ -45,6 +45,13 @@ def decode_output(encoded: str | None) -> str:
|
|||||||
return "<failed to decode output>"
|
return "<failed to decode output>"
|
||||||
|
|
||||||
|
|
||||||
|
def sdk_body(resp: Any) -> dict[str, Any]:
|
||||||
|
body = json.loads(resp.to_json_string())
|
||||||
|
if not isinstance(body, dict):
|
||||||
|
raise RuntimeError(f"unexpected sdk response type: {type(body).__name__}")
|
||||||
|
return body
|
||||||
|
|
||||||
|
|
||||||
class CloudOperator:
|
class CloudOperator:
|
||||||
def __init__(self, config: dict[str, Any], service_name: str, instance_id: str, release_id: str | None) -> None:
|
def __init__(self, config: dict[str, Any], service_name: str, instance_id: str, release_id: str | None) -> None:
|
||||||
self.config = config
|
self.config = config
|
||||||
@ -197,7 +204,7 @@ class CloudOperator:
|
|||||||
req = tat_models.RunCommandRequest()
|
req = tat_models.RunCommandRequest()
|
||||||
req.from_json_string(json.dumps(payload))
|
req.from_json_string(json.dumps(payload))
|
||||||
resp = self.tat.RunCommand(req)
|
resp = self.tat.RunCommand(req)
|
||||||
body = json.loads(resp.to_json_string())["Response"]
|
body = sdk_body(resp)
|
||||||
return str(body["InvocationId"])
|
return str(body["InvocationId"])
|
||||||
|
|
||||||
def wait_for_tat(self, invocation_id: str) -> dict[str, Any]:
|
def wait_for_tat(self, invocation_id: str) -> dict[str, Any]:
|
||||||
@ -214,7 +221,7 @@ class CloudOperator:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
resp = self.tat.DescribeInvocationTasks(req)
|
resp = self.tat.DescribeInvocationTasks(req)
|
||||||
body = json.loads(resp.to_json_string())["Response"]
|
body = sdk_body(resp)
|
||||||
tasks = body.get("InvocationTaskSet", [])
|
tasks = body.get("InvocationTaskSet", [])
|
||||||
task = next((item for item in tasks if str(item["InstanceId"]) == self.instance_id), None)
|
task = next((item for item in tasks if str(item["InstanceId"]) == self.instance_id), None)
|
||||||
if not task:
|
if not task:
|
||||||
@ -240,7 +247,7 @@ class CloudOperator:
|
|||||||
req = tat_models.DescribeAutomationAgentStatusRequest()
|
req = tat_models.DescribeAutomationAgentStatusRequest()
|
||||||
req.from_json_string(json.dumps({"InstanceIds": [self.instance_id], "Limit": 1}))
|
req.from_json_string(json.dumps({"InstanceIds": [self.instance_id], "Limit": 1}))
|
||||||
resp = self.tat.DescribeAutomationAgentStatus(req)
|
resp = self.tat.DescribeAutomationAgentStatus(req)
|
||||||
body = json.loads(resp.to_json_string())["Response"]
|
body = sdk_body(resp)
|
||||||
online = any(item.get("AgentStatus") == "Online" for item in body.get("AutomationAgentSet", []))
|
online = any(item.get("AgentStatus") == "Online" for item in body.get("AutomationAgentSet", []))
|
||||||
if not online:
|
if not online:
|
||||||
raise RuntimeError(f"TAT agent is not online for {self.instance_id}")
|
raise RuntimeError(f"TAT agent is not online for {self.instance_id}")
|
||||||
@ -279,7 +286,7 @@ class CloudOperator:
|
|||||||
req = clb_models.ModifyTargetWeightRequest()
|
req = clb_models.ModifyTargetWeightRequest()
|
||||||
req.from_json_string(json.dumps(payload))
|
req.from_json_string(json.dumps(payload))
|
||||||
resp = self.clb.ModifyTargetWeight(req)
|
resp = self.clb.ModifyTargetWeight(req)
|
||||||
request_id = json.loads(resp.to_json_string())["Response"]["RequestId"]
|
request_id = sdk_body(resp)["RequestId"]
|
||||||
self.wait_for_clb_task(request_id)
|
self.wait_for_clb_task(request_id)
|
||||||
|
|
||||||
def wait_for_clb_task(self, request_id: str) -> None:
|
def wait_for_clb_task(self, request_id: str) -> None:
|
||||||
@ -288,7 +295,7 @@ class CloudOperator:
|
|||||||
req = clb_models.DescribeTaskStatusRequest()
|
req = clb_models.DescribeTaskStatusRequest()
|
||||||
req.from_json_string(json.dumps({"TaskId": request_id}))
|
req.from_json_string(json.dumps({"TaskId": request_id}))
|
||||||
resp = self.clb.DescribeTaskStatus(req)
|
resp = self.clb.DescribeTaskStatus(req)
|
||||||
body = json.loads(resp.to_json_string())["Response"]
|
body = sdk_body(resp)
|
||||||
status = int(body["Status"])
|
status = int(body["Status"])
|
||||||
if status == 0:
|
if status == 0:
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user