GPU接口文档
GPU实例
获取实例资源列表

DescribeCompShareInstance — 查询实例列表

接口说明

查询优云智算 GPU 实例的详细信息,支持分页和多种筛选条件。返回实例的规格、状态、IP、磁盘、镜像、计费等完整信息。

使用限制

  • 单次最多查询 100 个实例(Limit 上限为 100)。
  • 按实例 ID 筛选时,UHostIds 最多传入 100 个。
  • Offset 不能超过实例总数,否则返回错误。

请求参数

名称类型必填描述示例值
ActionString接口名称DescribeCompShareInstance
RegionString地域cn-wlcb
ZoneString可用区。不传则查询该地域下所有可用区cn-wlcb-01
ProjectIdString项目 ID。通过 SDK 向同一网关发送 GetProjectList 请求获取(resp.ProjectSet[].ProjectIdorg-xxx
UHostIds.NString实例 ID 列表,用于查询指定实例。最多 100 个uhost-xxx
LimitInteger每页数量,默认 20,最大 10020
OffsetInteger偏移量,默认 0,用于分页0
TagString按业务组名称筛选my-group
VPCIdString按 VPC ID 筛选uvnet-xxx
SubnetIdString按子网 ID 筛选subnet-xxx
UDiskIdForAttachmentString云盘 ID,筛选可挂载该云盘的实例udisk-xxx
WithoutGpuBoolean是否获取无卡模式的规格信息,默认 falsefalse

响应参数

名称类型描述示例值
ActionString响应名称DescribeCompShareInstanceResponse
RetCodeInteger返回码,0 为成功0
TotalCountInteger满足条件的实例总数5
UHostSetArray of Object实例信息列表,详见下方

UHostSet 元素结构

名称类型描述
UHostIdString实例 ID
NameString实例名称
StateString实例状态。Running:运行中,Stopped:已关机,Starting:启动中,Stopping:关机中,Install:安装中,Rebooting:重启中
ZoneString可用区
RegionString地域
MachineTypeString机型
CPUIntegerCPU 核数
MemoryInteger内存大小(MB)
GPUIntegerGPU 卡数
GpuTypeStringGPU 类型
CpuPlatformStringCPU 平台
ChargeTypeString计费模式
CreateTimeInteger创建时间(Unix 时间戳)
ExpireTimeInteger到期时间(Unix 时间戳)
IsExpireString是否过期。Yes / No
AutoRenewString是否自动续费。Yes / No
IsSpotBoolean是否为抢占式实例
CompShareImageIdString镜像 ID
CompShareImageNameString镜像名称
CompShareImageTypeString镜像类型。System / App / Custom / Community
InstanceTypeString实例类型。UHost:普通主机,Container:容器主机
OsNameString操作系统名称
OsTypeString操作系统类别。Windows / Linux
PasswordString实例密码(Base64 编码)
SshLoginCommandStringSSH 登录命令(仅 Linux)
IPSetArray of ObjectIP 信息列表
DiskSetArray of Object磁盘信息列表
SoftwaresArray of Object应用信息列表(端口、访问地址)
GraphicsMemoryObject显存信息
InstancePriceFloat实例价格(元/小时)
DiskPriceFloat磁盘总价格(元/小时)
TotalDiskSpaceInteger数据盘总空间(GB)
FileBrowserPasswordStringFileBrowser 密码(Base64 编码)
CompShareImageStatusString镜像状态
CompShareImageOwnerAliasString镜像来源
CompShareImageAuthorString镜像作者昵称
BasicImageIdString基础镜像 ID
BasicImageNameString基础镜像名称
RemarkString实例备注
SupportWithoutGpuStartBoolean是否支持无卡开机
CompShareImagePriceFloat镜像价格(元/小时,仅付费社区镜像)
DiskPriceInfoArray of Object磁盘分项价格明细
DiscountTypeInteger折扣类型。1:夜间折扣,2:节日折扣
SchedulerStopTimeInteger定时关机时间(Unix 时间戳)
StartTimeInteger实例启动时间(Unix 时间戳)
StopTimeInteger关机时间(Unix 时间戳)
UpdateTimeInteger状态更新时间(Unix 时间戳)
ReleaseTimeInteger释放时间(按量付费实例关机后 +7 天,Unix 时间戳)
AttachUs3TimeIntegerUS3 挂载时间(Unix 时间戳)
MonitorMessagesObject监控信息(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
    }
  ]
}
Copyright © 2026 沪ICP备12020087号-61