45 lines
1.5 KiB
Python
Raw Normal View History

2025-04-02 16:57:05 +08:00
from typing import Dict, Any, Optional
async def calculate_storage_price(region: str, disk_gb: int) -> float:
"""
计算Azure存储价格
"""
# 这里需要实现Azure存储价格的计算逻辑
# 目前返回一个占位符价格
return 0.1 * disk_gb
async def calculate_vm_price(instance_type: str, region: str, operating_system: str = "Linux",
disk_gb: int = 0) -> Dict[str, float]:
"""
计算Azure虚拟机价格
"""
try:
# 这里需要实现具体的Azure VM价格计算逻辑
# 可以使用Azure Retail Prices API或者自定义价格表
# 目前返回一个示例价格
price_per_hour = 0.1 # 示例价格
# 计算存储价格
disk_monthly_price = await calculate_storage_price(region, disk_gb) if disk_gb > 0 else 0
# 计算每月价格
monthly_price = price_per_hour * 730 # 730小时/月
total_monthly_price = monthly_price + disk_monthly_price
return {
"hourly_price": price_per_hour,
"monthly_price": monthly_price,
"disk_monthly_price": disk_monthly_price,
"total_monthly_price": total_monthly_price
}
except Exception as e:
print(f"计算Azure价格时出错: {str(e)}")
# 返回默认值或者可以抛出异常
return {
"hourly_price": 0,
"monthly_price": 0,
"disk_monthly_price": 0,
"total_monthly_price": 0
}