1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-20 01:09:33 +08:00

fix: chinac cloud restart

This commit is contained in:
0O0o0oOoO00
2025-05-18 21:20:19 +08:00
parent 79fa8f7052
commit cdacf96a41

View File

@@ -1,6 +1,6 @@
import logging
from module.logger import logger
import time
import json
from module.base.base import ModuleBase
from module.base.timer import Timer
from module.cloud_phone.chinac_api import *
@@ -39,16 +39,18 @@ class CloudPhoneRestart(ModuleBase):
self.api.set_request_params({
"CloudPhones": [
{
{"Region": self.region, "Id": self.phone_id}
"Region": self.region,
"Id": self.phone_id
}
],
"Operate": "reboot"
})
res = self.api.do()
status_code = res["Info"]["code"]
if status_code != 10000 and res["Status"] == 200:
info = json.loads(res["Info"])
status_code = res["Status"]
if status_code != 200 and info["code"] == 10000:
raise ChinacError(f"Chinac api error, code: {status_code}")
logging.info("Cloud phone restart request success")
logger.info("Cloud phone restart request success")
def is_ready(self):
self.api.set_action(CloudPhoneAction.DescribeCloudPhone)
@@ -58,21 +60,23 @@ class CloudPhoneRestart(ModuleBase):
"Id": self.phone_id
})
res = self.api.do()
status_code = res["Info"]["code"]
if status_code != 10000 and res["Status"] == 200:
info = json.loads(res["Info"])
status_code = res["Status"]
if status_code != 200 and info["code"] == 10000:
raise ChinacError(f"Chinac api error, code: {status_code}")
phone_status = res["Info"]["data"]["BasicInfo"]["Status"]
logging.info(f"Cloud phone current status: {phone_status}")
phone_status = info["data"]["BasicInfo"]["Status"]
logger.info(f"Cloud phone current status: {phone_status}")
if phone_status == "START":
logging.info("Cloud phone ready")
logger.info("Cloud phone ready")
return True
return False
def wait_for_ready(self):
wait_timer = Timer(30)
wait_timer = Timer(60)
wait_timer.start()
while 1:
if wait_timer.reset():
if wait_timer.reached():
raise ChinacError("Waiting for cloud phone restart too long")
if self.is_ready():
break
@@ -85,6 +89,6 @@ class CloudPhoneRestart(ModuleBase):
self.phone_restart()
self.wait_for_ready()
except Exception as e:
logging.exception(e)
logger.exception(e)
return False
return True