完善get_aliyun_instance_upgrade_plans
This commit is contained in:
parent
40559c299d
commit
4d2c648fe2
@ -752,8 +752,38 @@ def get_aliyun_instance_details(instance_ids, region_id='cn-shanghai'):
|
||||
@jingrow.whitelist()
|
||||
def get_aliyun_instance_upgrade_plans(instance_id, region_id='cn-shanghai'):
|
||||
"""获取指定实例可升级的套餐列表"""
|
||||
manager = _get_manager()
|
||||
return manager.get_instance_upgrade_plans(instance_id, region_id)
|
||||
try:
|
||||
# 获取当前实例的os_type
|
||||
server = jingrow.get_pg("Jsite Server", {"instance_id": instance_id})
|
||||
if not server or not server.os_type:
|
||||
return {"success": False, "message": "找不到服务器记录或缺少os_type信息"}
|
||||
|
||||
# 获取可升级套餐列表
|
||||
manager = _get_manager()
|
||||
result = manager.get_instance_upgrade_plans(instance_id, region_id)
|
||||
|
||||
if not result or not result.get('success'):
|
||||
return result
|
||||
|
||||
# 过滤套餐:只返回support_platform包含当前实例os_type的套餐
|
||||
if result.get('data') and 'plans' in result['data']:
|
||||
filtered_plans = []
|
||||
for plan in result['data']['plans']:
|
||||
support_platform_str = plan.get('support_platform', '')
|
||||
try:
|
||||
support_platform_list = json.loads(support_platform_str) if support_platform_str else []
|
||||
if server.os_type in support_platform_list:
|
||||
filtered_plans.append(plan)
|
||||
except:
|
||||
continue
|
||||
|
||||
result['data']['plans'] = filtered_plans
|
||||
|
||||
return result
|
||||
|
||||
except Exception as e:
|
||||
jingrow.log_error("获取可升级套餐列表失败", f"获取实例 {instance_id} 可升级套餐时发生错误: {str(e)}")
|
||||
return {"success": False, "error": str(e), "message": "获取可升级套餐列表失败"}
|
||||
|
||||
|
||||
# 服务器订单和创建相关
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user