GPU接口文档
GPU实例
更新Pod实例端口

UpdateCompShareInstancePorts — 更新Pod实例端口

接口说明

更新 Pod 模式 GPU 实例对外开放的端口集合。HTTP 端口通过 Ingress 暴露,TCP 端口(含 SSH)通过 ingress-nginx 的 TCP ConfigMap 转发。

调用方需传入期望的全量端口列表(全量 diff 语义):未出现在请求中的端口会被删除;本接口不修改 Pod 容器本身,仅调整 Service / Ingress / ConfigMap。

使用限制

  • 仅 Pod 机型可用:请求中的 Zone 须为 Pod 可用区(可通过 DescribeCompShareSupportZone 确认)。传统 UHost 虚机不支持此接口。
  • 全量替换:每次调用应传入完整的 HTTP / TCP 端口列表,而非增量追加或删除。
  • 默认端口自动补齐:若未传入 HTTP 8888 或 TCP 23,服务端会自动追加(Jupyter / 业务入口与 SSH 入口,与创建 Pod 时一致)。
  • 数量上限:每种协议(HTTP / TCP )最多 10 个端口(含默认的 8888 / 23)。
  • 实例状态:实例须存在、归属当前账号且处于 Normal 状态;系统盘跨节点迁移进行中时不可调用。
  • 重装后保留端口:实例 ReinstallCompShareInstance 后若需保留自定义端口,需再次调用本接口。

请求参数

名称类型必填描述示例值
ActionString接口名称UpdateCompShareInstancePorts
RegionString地域cn-wlcb
ZoneStringPod 可用区cn-wlcb-01
UHostIdString实例 IDuhost-xxxx
HttpPortsArray of IntegerHTTP 端口全量列表(容器内端口)。JSON 数组或扁平参数 HttpPorts.0HttpPorts.1 … 二选一;JSON 数组优先[8888, 8188]
TcpPortsArray of IntegerTCP 端口全量列表(容器内端口)。JSON 数组或 TcpPorts.N 扁平参数[23, 2222]

传参说明:若请求体中已包含 HttpPorts / TcpPorts JSON 数组且非空,则直接使用;否则按 HttpPorts.0TcpPorts.1 等扁平键解析,按序号排序。


响应参数

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

SSH 连接示例:ssh -p <ExternalPort> root@<ExternalHost>,其中 ExternalPort / ExternalHost 取自 TcpForwardsInternalPort=23 的条目。

更新后的端口集合也可通过 DescribeCompShareInstancePortsTcpForwards 字段查询。


请求示例

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().update_comp_share_instance_ports({
            "Zone": "cn-wlcb-01",
            "UHostId": "uhost-xxxx",
            "HttpPorts": [8888, 8188],
            "TcpPorts": [23, 2222],
        })
        print("更新成功:", resp.get("UHostId"))
        print("TCP 转发:", resp.get("TcpForwards"))
        print("Ingress 主机:", resp.get("IngressHosts"))
    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/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.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.NewUpdateCompShareInstancePortsRequest()
	req.UHostId = ucloud.String("uhost-xxxx")
	req.HttpPorts = []int{8888, 8188}
	req.TcpPorts = []int{23, 2222}
 
	resp, err := client.UpdateCompShareInstancePorts(req)
	if err != nil {
		fmt.Printf("更新失败: %s\n", err)
		return
	}
	fmt.Printf("更新成功: %s\n", resp.UHostId)
	fmt.Printf("TcpForwards: %+v\n", resp.TcpForwards)
}

扁平参数示例(HTTP 表单 / Query)

未使用 JSON 数组时,可传:

HttpPorts.0=8888
HttpPorts.1=8188
TcpPorts.0=23
TcpPorts.1=2222

响应示例

{
  "Action": "UpdateCompShareInstancePortsResponse",
  "RetCode": 0,
  "UHostId": "uhost-xxxx"
}
Copyright © 2026 沪ICP备12020087号-61