From 819b195a678550920af1a9c949928fcea79fe86c Mon Sep 17 00:00:00 2001 From: jingrow Date: Wed, 6 Aug 2025 22:11:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=90=8E=E5=BB=B6=E8=BF=9F30=E7=A7=92?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=85=AC=E7=BD=91ip=E7=AD=89=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=B8=94=E8=AE=BE=E7=BD=AE=E6=9C=80=E5=A4=A7=E9=87=8D?= =?UTF-8?q?=E8=AF=9530=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jcloud/api/aliyun_server_light.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/jcloud/api/aliyun_server_light.py b/jcloud/api/aliyun_server_light.py index fbb0a48..b86ea64 100644 --- a/jcloud/api/aliyun_server_light.py +++ b/jcloud/api/aliyun_server_light.py @@ -1285,7 +1285,7 @@ def create_aliyun_server(order_name): jingrow.db.commit() # 延迟60秒执行update_server_record来更新服务器详细信息 - time.sleep(60) + time.sleep(30) jingrow.enqueue( "jcloud.api.aliyun_server_light.update_server_record", instance_ids=json.dumps([instance_id]), @@ -1380,10 +1380,22 @@ def update_server_record(instance_ids): instance_info = instances[0] # 取第一个实例 - # 更新public_ip + # 获取公网IP(最多重试30次) public_ip = instance_info.get('public_ip_address') - if public_ip: - server.public_ip = public_ip + if not public_ip: + for retry in range(30): + time.sleep(10) + retry_details = get_aliyun_instance_details(instance_ids, region_id) + if retry_details and retry_details.get('success'): + retry_instances = retry_details.get('data', {}).get('instances', []) + if retry_instances and retry_instances[0].get('public_ip_address'): + public_ip = retry_instances[0].get('public_ip_address') + break + else: + jingrow.log_error(f"获取公网IP失败-{instance_id}", f"实例 {instance_id} 在30次重试后仍未获取到公网IP") + return {"success": False, "message": f"实例 {instance_id} 在30次重试后仍未获取到公网IP"} + + server.public_ip = public_ip # 更新end_date(从expired_time转换) expired_time = instance_info.get('expired_time')