Skip to Content
GPU 接口文档GPU实例设置/更新定时关机
GPU API 接口

设置/更新定时关机

接口说明

为优云智算 GPU 实例设置或更新定时关机时间。到达指定时间后实例将自动关机。

POSThttps://api.compshare.cnActionUpdateCompShareStopScheduler

使用限制

  • 定时关机时间必须晚于当前时间至少 5 分钟。
  • 抢占式实例不支持定时关机。

请求参数

名称类型必填描述示例值
ActionString接口名称UpdateCompShareStopScheduler
RegionString地域cn-wlcb
ZoneString可用区cn-wlcb-01
ProjectIdString项目 ID。获取方式见下方说明org-xxx
UHostIdString实例 IDuhost-xxxx
SchedulerStopTimeInteger定时关机时间(Unix 时间戳),需 >= 当前时间 + 300 秒1712649600

如何获取 ProjectId:向同一网关(api.compshare.cn)发送 GetProjectList 请求即可获取,示例如下。

Python 获取 ProjectId

resp = client.invoke("GetProjectList") project_id = resp["ProjectSet"][0]["ProjectId"] # 例如 "org-cwy2qk"

Go 获取 ProjectId

// 使用与业务接口相同的 client(同一 api.compshare.cn 网关) type GetProjectListReq struct{ request.CommonBase } type Project struct { ProjectId string `json:"ProjectId"` ProjectName string `json:"ProjectName"` IsDefault bool `json:"IsDefault"` } type GetProjectListResp struct { response.CommonBase ProjectSet []Project `json:"ProjectSet"` } req := &GetProjectListReq{} resp := &GetProjectListResp{} err := client.InvokeAction("GetProjectList", req, resp) // resp.ProjectSet[0].ProjectId 即为 ProjectId,例如 "org-cwy2qk"

响应参数

名称类型描述示例值
ActionString响应名称UpdateCompShareStopSchedulerResponse
RetCodeInteger返回码,0 为成功0
UHostIdString实例 IDuhost-xxxx

请求示例

Python(使用 UCloud SDK)

import time 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: stop_time = int(time.time()) + 3600 # 1小时后关机 resp = client.ucompshare().update_comp_share_stop_scheduler({ "ProjectId": "org-xxx", # 项目 ID,获取方式见文档上方说明 "Zone": "cn-wlcb-01", "UHostId": "uhost-xxxx", # 实例 ID,通过 DescribeCompShareInstance 获取 "SchedulerStopTime": stop_time, }) print("定时关机设置成功:", resp.get("UHostId")) except exc.UCloudException as e: print(e) if __name__ == "__main__": main()

Go(使用 UCloud SDK)

package main import ( "fmt" "time" "github.com/ucloud/ucloud-sdk-go/services/ucompshare" "github.com/ucloud/ucloud-sdk-go/ucloud" "github.com/ucloud/ucloud-sdk-go/ucloud/auth" ) func main() { cfg := ucloud.NewConfig() cfg.Region = "cn-wlcb" cfg.Zone = "cn-wlcb-01" cfg.ProjectId = "org-xxx" // 项目 ID,获取方式见文档上方说明 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 := ucompshare.NewClient(&cfg, &credential) req := client.NewUpdateCompShareStopSchedulerRequest() req.UHostId = ucloud.String("uhost-xxxx") // 实例 ID,通过 DescribeCompShareInstance 获取 req.SchedulerStopTime = ucloud.Int64(time.Now().Unix() + 3600) resp, err := client.UpdateCompShareStopScheduler(req) if err != nil { fmt.Printf("设置失败: %s\n", err) return } fmt.Printf("定时关机设置成功: %s\n", resp.UHostId) }

响应示例

{ "Action": "UpdateCompShareStopSchedulerResponse", "RetCode": 0, "UHostId": "uhost-xxxx" }
Last updated on