GPU服务API文档
GPU实例
检查指定规格的资源可用性

CheckCompShareResourceCapacity — 检查指定规格的资源可用性

接口说明

检查指定 GPU 类型、CPU 平台、镜像和磁盘配置下,各种 GPU/CPU/Memory 组合是否有足够的资源可创建实例。该接口会模拟真实的调度流程,返回每种规格组合的资源可用状态。

建议在调用 CreateCompShareInstance 之前先调用此接口进行资源预检。


请求参数

名称类型必填描述示例值
ActionString接口名称CheckCompShareResourceCapacity
RegionString地域cn-wlcb
ZoneString可用区cn-wlcb-01
GpuTypeStringGPU 类型4090
MachineTypeString机型,固定 GG
MinimalCpuPlatformStringCPU 平台。Intel/AutoAmd/AutoAutoAuto
CompShareImageIdString镜像 IDcompshareImage-xxxx
ChargeTypeString计费模式。MonthDayDynamicPostpaySpotMonth
Disks.N.IsBootBoolean是否为系统盘true
Disks.N.TypeString磁盘类型CLOUD_SSD
Disks.N.SizeInteger磁盘大小(GB)60

响应参数

名称类型描述示例值
ActionString响应名称CheckCompShareResourceCapacityResponse
RetCodeInteger返回码,0 为成功0
SpecsArray of Object各规格组合的资源可用状态

Specs 元素结构

名称类型描述
GpuIntegerGPU 卡数
CpuIntegerCPU 核数
MemInteger内存大小(GB)
ResourceEnoughBoolean资源是否充足

请求示例

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",    # 替换为你的公钥,从 https://console.compshare.cn/uaccount/api_manage 获取
        "private_key": "my_private_key",   # 替换为你的私钥
        "base_url": "https://api.compshare.cn",
    })
 
    try:
        resp = client.ucompshare().invoke("CheckCompShareResourceCapacity", {
            "Region": "cn-wlcb",
            "Zone": "cn-wlcb-01",
            "GpuType": "4090",
            "MachineType": "G",
            "MinimalCpuPlatform": "Auto",
            "CompShareImageId": "compshareImage-xxxx",  # 镜像 ID,通过 DescribeCompShareImages 获取
            "ChargeType": "Dynamic",
            "Disks": [{"IsBoot": "true", "Type": "CLOUD_SSD", "Size": 60}],
        })
        for spec in resp.get("Specs", []):
            status = "可用" if spec["ResourceEnough"] else "不足"
            print(f"  GPU:{spec['Gpu']} CPU:{spec['Cpu']} Mem:{spec['Mem']}GB - {status}")
    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 DiskParam struct {
	IsBoot string // "true" = 系统盘, "false" = 数据盘
	Type   string // 磁盘类型: CLOUD_SSD / CLOUD_RSSD 等
	Size   *int   // 磁盘大小 (GB)
}
 
type CheckCompShareResourceCapacityRequest struct {
	request.CommonBase
	GpuType            *string
	MachineType        *string
	MinimalCpuPlatform *string
	CompShareImageId   *string
	ChargeType         *string
	Disks              []DiskParam
}
 
type ResourceSpec struct {
	Gpu            int  `json:"Gpu"`
	Cpu            int  `json:"Cpu"`
	Mem            int  `json:"Mem"` // 单位 GB
	ResourceEnough bool `json:"ResourceEnough"`
}
 
type CheckCompShareResourceCapacityResponse struct {
	response.CommonBase
	Specs []ResourceSpec `json:"Specs"`
}
 
func main() {
	cfg := ucloud.NewConfig()
	cfg.Region = "cn-wlcb"
	cfg.BaseUrl = "https://api.compshare.cn"
 
	credential := auth.NewCredential()
	credential.PublicKey = "my_public_key"   // 替换为你的公钥,从 https://console.compshare.cn/uaccount/api_manage 获取
	credential.PrivateKey = "my_private_key" // 替换为你的私钥
	client := ucloud.NewClient(&cfg, &credential)
 
	req := &CheckCompShareResourceCapacityRequest{
		GpuType:            ucloud.String("4090"),
		MachineType:        ucloud.String("G"),
		MinimalCpuPlatform: ucloud.String("Auto"),
		CompShareImageId:   ucloud.String("compshareImage-xxxx"), // 替换为真实镜像 ID,通过 DescribeCompShareImages 获取
		ChargeType:         ucloud.String("Dynamic"),
		Disks:              []DiskParam{{IsBoot: "true", Type: "CLOUD_SSD", Size: ucloud.Int(60)}},
	}
	req.SetRegion("cn-wlcb")
	req.SetZone("cn-wlcb-01")
	resp := &CheckCompShareResourceCapacityResponse{}
 
	if err := client.InvokeAction("CheckCompShareResourceCapacity", req, resp); err != nil {
		fmt.Printf("调用失败: RetCode=%d Msg=%s err=%v\n", resp.RetCode, resp.Message, err)
		return
	}
	for _, spec := range resp.Specs {
		status := "缺货"
		if spec.ResourceEnough {
			status = "有货"
		}
		fmt.Printf("  GPU:%d CPU:%d Mem:%dGB - %s\n", spec.Gpu, spec.Cpu, spec.Mem, status)
	}
}

响应示例

{
  "Action": "CheckCompShareResourceCapacityResponse",
  "RetCode": 0,
  "Specs": [
    {"Gpu": 1, "Cpu": 16, "Mem": 32, "ResourceEnough": true},
    {"Gpu": 1, "Cpu": 16, "Mem": 64, "ResourceEnough": true},
    {"Gpu": 2, "Cpu": 32, "Mem": 128, "ResourceEnough": false}
  ]
}
Copyright © 2026 沪ICP备12020087号-61