StopCompShareInstance — 关闭实例
接口说明
关闭一台运行中的优云智算 GPU 实例。调用成功后实例进入 Stopping 状态,关机完成后变为 Stopped。
使用限制
- 仅
Running状态的实例可以关闭。 - 同一实例的操作存在并发锁(10 分钟 TTL),重复操作会返回
InstanceOperationInProgress错误。 - 正在制作镜像的实例无法关闭。
- 抢占式实例默认不可手动关闭,需传入
Force=true。
请求参数
| 名称 | 类型 | 必填 | 描述 | 示例值 |
|---|---|---|---|---|
| Action | String | 是 | 接口名称 | StopCompShareInstance |
| Region | String | 是 | 地域 | cn-wlcb |
| Zone | String | 是 | 可用区 | cn-wlcb-01 |
| UHostId | String | 是 | 实例 ID | uhost-xxxx |
| Force | Boolean | 否 | 是否强制关机。用于关闭抢占式实例,默认 false | false |
响应参数
| 名称 | 类型 | 描述 | 示例值 |
|---|---|---|---|
| Action | String | 响应名称 | StopCompShareInstanceResponse |
| RetCode | Integer | 返回码,0 为成功 | 0 |
| UHostId | String | 实例 ID | uhost-xxxx |
请求示例
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("StopCompShareInstance", {
"Region": "cn-wlcb",
"Zone": "cn-wlcb-01",
"UHostId": "uhost-xxxx", # 实例 ID,通过 DescribeCompShareInstance 获取
})
print("关闭成功:", resp.get("UHostId"))
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 StopCompShareInstanceRequest struct {
request.CommonBase
UHostId *string
}
type StopCompShareInstanceResponse struct {
response.CommonBase
UHostId string `json:"UHostId"`
}
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 := &StopCompShareInstanceRequest{
UHostId: ucloud.String("uhost-xxxx"), // 实例 ID,通过 DescribeCompShareInstance 获取
}
req.SetRegion("cn-wlcb")
req.SetZone("cn-wlcb-01")
resp := &StopCompShareInstanceResponse{}
if err := client.InvokeAction("StopCompShareInstance", req, resp); err != nil {
fmt.Printf("调用失败: RetCode=%d Msg=%s err=%v\n", resp.RetCode, resp.Message, err)
return
}
fmt.Printf("关闭成功: %s\n", resp.UHostId)
}响应示例
{
"Action": "StopCompShareInstanceResponse",
"RetCode": 0,
"UHostId": "uhost-xxxx"
}