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或 TCP23,服务端会自动追加(Jupyter / 业务入口与 SSH 入口,与创建 Pod 时一致)。 - 数量上限:每种协议(HTTP / TCP )最多 10 个端口(含默认的 8888 / 23)。
- 实例状态:实例须存在、归属当前账号且处于
Normal状态;系统盘跨节点迁移进行中时不可调用。 - 重装后保留端口:实例 ReinstallCompShareInstance 后若需保留自定义端口,需再次调用本接口。
请求参数
| 名称 | 类型 | 必填 | 描述 | 示例值 |
|---|---|---|---|---|
| Action | String | 是 | 接口名称 | UpdateCompShareInstancePorts |
| Region | String | 是 | 地域 | cn-wlcb |
| Zone | String | 是 | Pod 可用区 | cn-wlcb-01 |
| UHostId | String | 是 | 实例 ID | uhost-xxxx |
| HttpPorts | Array of Integer | 否 | HTTP 端口全量列表(容器内端口)。JSON 数组或扁平参数 HttpPorts.0、HttpPorts.1 … 二选一;JSON 数组优先 | [8888, 8188] |
| TcpPorts | Array of Integer | 否 | TCP 端口全量列表(容器内端口)。JSON 数组或 TcpPorts.N 扁平参数 | [23, 2222] |
传参说明:若请求体中已包含
HttpPorts/TcpPortsJSON 数组且非空,则直接使用;否则按HttpPorts.0、TcpPorts.1等扁平键解析,按序号排序。
响应参数
| 名称 | 类型 | 描述 | 示例值 |
|---|---|---|---|
| Action | String | 响应名称 | UpdateCompShareInstancePortsResponse |
| RetCode | Integer | 返回码,0 为成功 | 0 |
| UHostId | String | 实例 ID | uhost-xxxx |
SSH 连接示例:ssh -p <ExternalPort> root@<ExternalHost>,其中 ExternalPort / ExternalHost 取自 TcpForwards 中 InternalPort=23 的条目。
更新后的端口集合也可通过 DescribeCompShareInstance 的 Ports、TcpForwards 字段查询。
请求示例
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"
}