DescribeCompShareInstance — 查询实例列表
接口说明
查询优云智算 GPU 实例的详细信息,支持分页和多种筛选条件。返回实例的规格、状态、IP、磁盘、镜像、计费等完整信息。
使用限制
- 单次最多查询 100 个实例(
Limit上限为 100)。 - 按实例 ID 筛选时,
UHostIds最多传入 100 个。 Offset不能超过实例总数,否则返回错误。
请求参数
| 名称 | 类型 | 必填 | 描述 | 示例值 |
|---|---|---|---|---|
| Action | String | 是 | 接口名称 | DescribeCompShareInstance |
| Region | String | 是 | 地域 | cn-wlcb |
| Zone | String | 否 | 可用区。不传则查询该地域下所有可用区 | cn-wlcb-01 |
| ProjectId | String | 否 | 项目 ID。通过 SDK 向同一网关发送 GetProjectList 请求获取(resp.ProjectSet[].ProjectId) | org-xxx |
| UHostIds.N | String | 否 | 实例 ID 列表,用于查询指定实例。最多 100 个 | uhost-xxx |
| Limit | Integer | 否 | 每页数量,默认 20,最大 100 | 20 |
| Offset | Integer | 否 | 偏移量,默认 0,用于分页 | 0 |
| Tag | String | 否 | 按业务组名称筛选 | my-group |
| VPCId | String | 否 | 按 VPC ID 筛选 | uvnet-xxx |
| SubnetId | String | 否 | 按子网 ID 筛选 | subnet-xxx |
| UDiskIdForAttachment | String | 否 | 云盘 ID,筛选可挂载该云盘的实例 | udisk-xxx |
| WithoutGpu | Boolean | 否 | 是否获取无卡模式的规格信息,默认 false | false |
响应参数
| 名称 | 类型 | 描述 | 示例值 |
|---|---|---|---|
| Action | String | 响应名称 | DescribeCompShareInstanceResponse |
| RetCode | Integer | 返回码,0 为成功 | 0 |
| TotalCount | Integer | 满足条件的实例总数 | 5 |
| UHostSet | Array of Object | 实例信息列表,详见下方 | — |
UHostSet 元素结构
| 名称 | 类型 | 描述 |
|---|---|---|
| UHostId | String | 实例 ID |
| Name | String | 实例名称 |
| State | String | 实例状态。Running:运行中,Stopped:已关机,Starting:启动中,Stopping:关机中,Install:安装中,Rebooting:重启中 |
| Zone | String | 可用区 |
| Region | String | 地域 |
| MachineType | String | 机型 |
| CPU | Integer | CPU 核数 |
| Memory | Integer | 内存大小(MB) |
| GPU | Integer | GPU 卡数 |
| GpuType | String | GPU 类型 |
| CpuPlatform | String | CPU 平台 |
| ChargeType | String | 计费模式 |
| CreateTime | Integer | 创建时间(Unix 时间戳) |
| ExpireTime | Integer | 到期时间(Unix 时间戳) |
| IsExpire | String | 是否过期。Yes / No |
| AutoRenew | String | 是否自动续费。Yes / No |
| IsSpot | Boolean | 是否为抢占式实例 |
| CompShareImageId | String | 镜像 ID |
| CompShareImageName | String | 镜像名称 |
| CompShareImageType | String | 镜像类型。System / App / Custom / Community |
| InstanceType | String | 实例类型。UHost:普通主机,Container:容器主机 |
| OsName | String | 操作系统名称 |
| OsType | String | 操作系统类别。Windows / Linux |
| Password | String | 实例密码(Base64 编码) |
| SshLoginCommand | String | SSH 登录命令(仅 Linux) |
| IPSet | Array of Object | IP 信息列表 |
| DiskSet | Array of Object | 磁盘信息列表 |
| Softwares | Array of Object | 应用信息列表(端口、访问地址) |
| GraphicsMemory | Object | 显存信息 |
| InstancePrice | Float | 实例价格(元/小时) |
| DiskPrice | Float | 磁盘总价格(元/小时) |
| TotalDiskSpace | Integer | 数据盘总空间(GB) |
| FileBrowserPassword | String | FileBrowser 密码(Base64 编码) |
| CompShareImageStatus | String | 镜像状态 |
| CompShareImageOwnerAlias | String | 镜像来源 |
| CompShareImageAuthor | String | 镜像作者昵称 |
| BasicImageId | String | 基础镜像 ID |
| BasicImageName | String | 基础镜像名称 |
| Remark | String | 实例备注 |
| SupportWithoutGpuStart | Boolean | 是否支持无卡开机 |
| CompShareImagePrice | Float | 镜像价格(元/小时,仅付费社区镜像) |
| DiskPriceInfo | Array of Object | 磁盘分项价格明细 |
| DiscountType | Integer | 折扣类型。1:夜间折扣,2:节日折扣 |
| SchedulerStopTime | Integer | 定时关机时间(Unix 时间戳) |
| StartTime | Integer | 实例启动时间(Unix 时间戳) |
| StopTime | Integer | 关机时间(Unix 时间戳) |
| UpdateTime | Integer | 状态更新时间(Unix 时间戳) |
| ReleaseTime | Integer | 释放时间(按量付费实例关机后 +7 天,Unix 时间戳) |
| AttachUs3Time | Integer | US3 挂载时间(Unix 时间戳) |
| MonitorMessages | Object | 监控信息(CPU/内存/GPU 使用率) |
请求示例
Python(使用 UCloud SDK)
安装 SDK:
pip install --upgrade ucloud-sdk-python3示例代码:
from ucloud.core import exc
from ucloud.client import Client
def main():
client = Client({
"region": "cn-wlcb",
"public_key": "my_public_key", # 替换为你的公钥(控制台 账户中心 → API 密钥:https://console.compshare.cn/uaccount/api_manage)
"private_key": "my_private_key", # 替换为你的私钥
"base_url": "https://api.compshare.cn",
})
try:
# 查询所有实例(分页)
resp = client.ucompshare().invoke("DescribeCompShareInstance", {
"Region": "cn-wlcb",
"Limit": 20,
"Offset": 0,
})
print(f"总数: {resp.get('TotalCount')}")
for inst in resp.get("UHostSet", []):
print(f" {inst['UHostId']} - {inst['Name']} - {inst['State']}")
# 查询指定实例
resp = client.ucompshare().invoke("DescribeCompShareInstance", {
"Region": "cn-wlcb",
"UHostIds": ["uhost-xxxx"],
})
print(resp)
except exc.UCloudException as e:
print(e)
if __name__ == "__main__":
main()Go(使用 UCloud SDK)
安装依赖:
go get github.com/ucloud/ucloud-sdk-go示例代码:
package main
import (
"fmt"
"github.com/ucloud/ucloud-sdk-go/ucloud"
"github.com/ucloud/ucloud-sdk-go/ucloud/auth"
"github.com/ucloud/ucloud-sdk-go/ucloud/request"
"github.com/ucloud/ucloud-sdk-go/ucloud/response"
)
type DescribeCompShareInstanceRequest struct {
request.CommonBase
UHostIds []string `required:"false"`
Limit *int `required:"false"`
Offset *int `required:"false"`
}
type IPInfo struct {
IP string `json:"IP"`
Type string `json:"Type"`
}
// UHostInstance 只列举常用字段,多余字段会被自动忽略
type UHostInstance struct {
UHostId string `json:"UHostId"`
Name string `json:"Name"`
State string `json:"State"` // Running / Stopped / Starting / Install ...
Zone string `json:"Zone"`
CPU int `json:"CPU"`
Memory int `json:"Memory"` // MB
GPU int `json:"GPU"`
GpuType string `json:"GpuType"`
ChargeType string `json:"ChargeType"`
OsName string `json:"OsName"`
OsType string `json:"OsType"`
Password string `json:"Password"` // Base64
SshLoginCommand string `json:"SshLoginCommand"`
CompShareImageId string `json:"CompShareImageId"`
CompShareImageName string `json:"CompShareImageName"`
IPSet []IPInfo `json:"IPSet"`
DiskSet interface{} `json:"DiskSet"`
}
type DescribeCompShareInstanceResponse struct {
response.CommonBase
TotalCount int `json:"TotalCount"`
UHostSet []UHostInstance `json:"UHostSet"`
}
func main() {
cfg := ucloud.NewConfig()
cfg.Region = "cn-wlcb"
cfg.BaseUrl = "https://api.compshare.cn"
credential := auth.NewCredential()
credential.PublicKey = "my_public_key" // 替换为你的公钥(控制台 账户中心 → API 密钥:https://console.compshare.cn/uaccount/api_manage)
credential.PrivateKey = "my_private_key" // 替换为你的私钥
client := ucloud.NewClient(&cfg, &credential)
req := &DescribeCompShareInstanceRequest{
Limit: ucloud.Int(20),
Offset: ucloud.Int(0),
}
req.SetRegion("cn-wlcb")
resp := &DescribeCompShareInstanceResponse{}
if err := client.InvokeAction("DescribeCompShareInstance", req, resp); err != nil {
fmt.Printf("调用失败: RetCode=%d Msg=%s err=%v\n", resp.RetCode, resp.Message, err)
return
}
fmt.Printf("总数: %d\n", resp.TotalCount)
for _, inst := range resp.UHostSet {
fmt.Printf(" %s - %s - %s\n", inst.UHostId, inst.Name, inst.State)
}
}响应示例
{
"Action": "DescribeCompShareInstanceResponse",
"RetCode": 0,
"TotalCount": 1,
"UHostSet": [
{
"UHostId": "uhost-xxxx",
"Name": "my-gpu-instance",
"State": "Running",
"Zone": "cn-wlcb-01",
"Region": "cn-wlcb",
"MachineType": "G",
"CPU": 16,
"Memory": 65536,
"GPU": 1,
"GpuType": "4090",
"CpuPlatform": "Amd/Epyc2",
"ChargeType": "Month",
"CreateTime": 1712563200,
"ExpireTime": 1715155200,
"IsExpire": "No",
"IsSpot": false,
"CompShareImageId": "compshareImage-xxxx",
"CompShareImageName": "PyTorch 2.1",
"CompShareImageType": "System",
"InstanceType": "Container",
"OsType": "Linux",
"Password": "dWNsb3VkLmNu",
"SshLoginCommand": "ssh root@x.x.x.x -p 60022",
"IPSet": [],
"DiskSet": [],
"SupportWithoutGpuStart": true
}
]
}