116 lines
3.1 KiB
Markdown
116 lines
3.1 KiB
Markdown
# 云计算价格计算器 API 文档
|
|
|
|
**描述:** 支持多云平台价格计算的服务。
|
|
|
|
**基本 URL:** `/api`
|
|
|
|
---
|
|
|
|
## 端点
|
|
|
|
### 1. 获取区域列表
|
|
|
|
- **描述:** 获取指定平台的可用区域列表。
|
|
- **路径:** `GET /regions`
|
|
- **方法:** `GET`
|
|
- **查询参数:**
|
|
- `platform` (string, optional, default: "aws"): 云平台。支持的值: "aws", "azure", "aliyun"。
|
|
- **成功响应 (200):**
|
|
```json
|
|
[
|
|
{
|
|
"code": "us-east-1",
|
|
"name": "US East (N. Virginia)"
|
|
}
|
|
]
|
|
```
|
|
- **错误响应 (400):** 如果平台不受支持。
|
|
|
|
---
|
|
|
|
### 2. 获取实例类型
|
|
|
|
- **描述:** 获取指定平台的可用实例类型。
|
|
- **路径:** `GET /instance-types`
|
|
- **方法:** `GET`
|
|
- **查询参数:**
|
|
- `platform` (string, optional, default: "aws"): 云平台。
|
|
- **成功响应 (200):** 包含实例类型及其信息的字典。
|
|
- **错误响应 (400):** 如果平台不受支持。
|
|
|
|
---
|
|
|
|
### 3. 搜索实例
|
|
|
|
- **描述:** 搜索符合指定条件的实例类型。
|
|
- **路径:** `POST /search-instances`
|
|
- **方法:** `POST`
|
|
- **请求体:** `InstanceSearchRequest`
|
|
- **成功响应 (200):** 匹配的实例列表,按月度总价排序。
|
|
- **错误响应 (400):** 如果缺少必需的参数。
|
|
- **错误响应 (500):** 内部服务器错误。
|
|
|
|
---
|
|
|
|
### 4. 搜索实例 V2
|
|
|
|
- **描述:** 使用 MySQL 数据库搜索符合条件的 AWS 实例。
|
|
- **路径:** `POST /search-instances-v2`
|
|
- **方法:** `POST`
|
|
- **请求体:** `InstanceSearchRequestV2`
|
|
- **成功响应 (200):** 匹配的实例列表。
|
|
- **错误响应 (500):** 内部服务器错误。
|
|
|
|
---
|
|
|
|
### 5. 比较价格
|
|
|
|
- **描述:** 比较多种实例配置的价格。
|
|
- **路径:** `POST /compare-prices`
|
|
- **方法:** `POST`
|
|
- **请求体:** `PriceComparison`
|
|
- **成功响应 (200):** 包含配置及其计算价格的列表。
|
|
- **错误响应 (500):** 内部服务器错误。
|
|
|
|
---
|
|
|
|
## 数据模型
|
|
|
|
### `InstanceSearchRequest`
|
|
|
|
| 字段 | 类型 | 描述 | 默认值 |
|
|
|---|---|---|---|
|
|
| `cpu_cores` | integer | CPU 核心数 | (optional) |
|
|
| `memory_gb` | float | 内存 (GB) | (optional) |
|
|
| `disk_gb` | integer | 磁盘大小 (GB) | (optional) |
|
|
| `region` | string | 区域 | (optional) |
|
|
| `operating_system` | string | 操作系统 | "Linux" |
|
|
| `platform` | string | 云平台 | "aws" |
|
|
|
|
### `InstanceSearchRequestV2`
|
|
|
|
| 字段 | 类型 | 描述 | 默认值 |
|
|
|---|---|---|---|
|
|
| `cpu_cores` | integer | CPU 核心数 | (optional) |
|
|
| `memory_gb` | float | 内存 (GB) | (optional) |
|
|
| `disk_gb` | integer | 磁盘大小 (GB) | (optional) |
|
|
| `region` | string | 区域 | (optional) |
|
|
| `operating_system` | string | 操作系统 | "Linux" |
|
|
|
|
### `PriceComparison`
|
|
|
|
| 字段 | 类型 | 描述 |
|
|
|---|---|---|
|
|
| `configurations` | List[`PriceRequest`] | 价格请求配置列表 |
|
|
|
|
### `PriceRequest`
|
|
|
|
| 字段 | 类型 | 描述 | 默认值 |
|
|
|---|---|---|---|
|
|
| `instance_type` | string | 实例类型 (required) | |
|
|
| `region` | string | 区域 (required) | |
|
|
| `operating_system` | string | 操作系统 (required) | |
|
|
| `purchase_option` | string | 购买选项 (required) | |
|
|
| `duration` | integer | 持续时间 | 1 |
|
|
| `disk_gb` | integer | 磁盘大小 (GB) | 0 |
|