端口转发相关接口
创建端口转发规则(CreatePortForwardingRule)
API请求
URLs
POST zstack/v1/port-forwardingHeaders
Authorization: OAuth the-session-uuidBody
{
"params": {
"vipUuid": "214cf4f562bf40b98a7c954081f94f03",
"vipPortStart": 22.0,
"protocolType": "TCP",
"vmNicUuid": "84590db8896d4e498bf69d35239a31cc",
"name": "pf1"
},
"systemTags": [],
"userTags": []
}Note: 上述示例中
systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"vipUuid":"1c4824bb6043388cac7499dd481ecaa4","vipPortStart":22.0,"protocolType":"TCP","vmNicUuid":"0611006103d335dfbfc0f9bb2a46d541","name":"pf1"}}' \
http://localhost:8080/zstack/v1/port-forwarding
参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| vipUuid | String | body(包含在params结构中) | VIP UUID | 0.6 | |
| vipPortStart | Integer | body(包含在params结构中) | VIP的起始端口号 | 0.6 | |
| vipPortEnd (可选) | Integer | body(包含在params结构中) | VIP的结束端口号; 如果忽略不设置, 会默认设置为vipPortStart | 0.6 | |
| privatePortStart (可选) | Integer | body(包含在params结构中) | 客户IP(虚拟机网卡的IP地址)的起始端口号; 如果忽略不设置, 会默认设置为vipPortStart | 0.6 | |
| privatePortEnd (可选) | Integer | body(包含在params结构中) | 客户IP(虚拟机网卡的IP地址)的结束端口号; 如果忽略不设置, 会默认设置为vipPortEnd | 0.6 | |
| protocolType | String | body(包含在params结构中) | 网络流量协议类型 |
|
0.6 |
| vmNicUuid (可选) | String | body(包含在params结构中) | 云主机网卡UUID | 0.6 | |
| allowedCidr (可选) | String | body(包含在params结构中) | 源CIDR; 端口转发规则只作用于源CIDR的流量; 如果忽略不设置, 会默认设置为to 0.0.0.0/0 | 0.6 | |
| name | String | body(包含在params结构中) | 资源名称 | 0.6 | |
| description (可选) | String | body(包含在params结构中) | 资源的详细描述 | 0.6 | |
| resourceUuid (可选) | String | body(包含在params结构中) | 用户指定的资源UUID,若指定,系统不会为该资源随机分配UUID | 0.6 | |
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
返回示例
{
"inventory": {
"uuid": "895a8ce93d274db78e2ef1462f8b8a29",
"name": "TestAttachRule",
"description": "test atatch rule",
"vipIp": "192.168.0.187",
"guestIp": "10.0.0.244",
"vipUuid": "6151c96fd2ac4d6cbd8f8eedffc06de5",
"vipPortStart": 33.0,
"vipPortEnd": 33.0,
"privatePortStart": 33.0,
"privatePortEnd": 33.0,
"vmNicUuid": "581ea3b08aef4096ac24e160f1ab0f8e",
"protocolType": "TCP",
"state": "Enabled",
"allowedCidr": "0.0.0.0/0",
"createDate": "Jun 7, 2017 9:20:10 PM",
"lastOpDate": "Jun 7, 2017 9:20:10 PM"
}
}#error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| name | String | 资源名称 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| vipIp | String | VIP的IP地址 | 0.6 |
| guestIp | String | 虚拟机网卡的IP地址 | 0.6 |
| vipUuid | String | VIP UUID | 0.6 |
| vipPortStart | Integer | VIP的起始端口号 | 0.6 |
| vipPortEnd | Integer | VIP的结束端口号 | 0.6 |
| privatePortStart | Integer | 客户IP的起始端口号 | 0.6 |
| privatePortEnd | Integer | 客户IP的结束端口号 | 0.6 |
| vmNicUuid | String | 云主机网卡UUID | 0.6 |
| protocolType | String | 网络流量的协议类型 | 0.6 |
| state | String | 规则可用状态 | 0.6 |
| allowedCidr | String | 源CIDR; 端口转发规则只作用于源CIDR的流量 | 0.6 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
SDK示例
Java
SDK
CreatePortForwardingRuleAction action = new CreatePortForwardingRuleAction();
action.vipUuid = "966f9f294e094243bcfaf7eeee70aeae";
action.vipPortStart = 22.0;
action.protocolType = "TCP";
action.vmNicUuid = "ace8c962d59248e38fadac5df9a108a7";
action.name = "pf1";
action.sessionId = "5f4df8c7fae44602b5f7e5d376904d6b";
CreatePortForwardingRuleAction.Result res = action.call();
Python
SDK
CreatePortForwardingRuleAction action = CreatePortForwardingRuleAction()
action.vipUuid = "1d130b0bb1e44aafa76d6280479f5399"
action.vipPortStart = 22.0
action.protocolType = "TCP"
action.vmNicUuid = "78c6172984874e5e9cdd3bf0248080ca"
action.name = "pf1"
action.sessionId = "4a3371ccd0cc4cdfa75ae46aeec14f41"
CreatePortForwardingRuleAction.Result res = action.call()删除端口转发规则(DeletePortForwardingRule)
API请求
URLs
DELETE zstack/v1/port-forwarding/{uuid}?deleteMode={deleteMode}Headers
Authorization: OAuth the-session-uuidCurl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 064a2c25381042d6b623c12e26418e78" \
-X DELETE http://localhost:8080/zstack/v1/port-forwarding/495b48a2bcf745e1ac584be6e366f0ab?deleteMode=Permissive参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| uuid | String | url | 资源的UUID,唯一标示该资源 | 0.6 | |
| deleteMode (可选) | String | body |
|
0.6 | |
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
该API成功时返回一个空的JSON结构
{},出错时返回的JSON结构包含一个error字段,例如:{
"error": {
"code": "SYS.1001",
"description": "A message or a operation timeout",
"details": "Create VM on KVM timeout after 300s"
}
}SDK示例
Java
SDK
DeletePortForwardingRuleAction action = new DeletePortForwardingRuleAction();
action.uuid = "42154ff320ea407dbc8b48088e541dcb";
action.deleteMode = "Permissive";
action.sessionId = "2b5cb5c82fb846669cd2c5e557bb140e";
DeletePortForwardingRuleAction.Result res = action.call();Python
SDK
DeletePortForwardingRuleAction action = DeletePortForwardingRuleAction()
action.uuid = "a8ac2d430d71487ea47419950e39ee4a"
action.deleteMode = "Permissive"
action.sessionId = "156eb3cd301546828a925386f331eb34"
DeletePortForwardingRuleAction.Result res = action.call()查询端口转发规则(QueryPortForwardingRule)
API请求
URLs
GET zstack/v1/port-forwarding
GET zstack/v1/port-forwarding/{uuid}Headers
Authorization: OAuth the-session-uuidCurl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 959a6d98336c4575a31212834d8ccc4d" \
-X GET http://localhost:8080/zstack/v1/port-forwarding?q=name=pf1&q=state=Enabledcurl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 0389ba8bf3c44bf8a9c5ee89d066fbdc" \
-X GET http://localhost:8080/zstack/v1/port-forwarding/3d9c9dbbea944e039d55e706aacb6899可查询字段
运行CLI命令行工具,输入QueryPortForwardingRule并按Tab键查看所有可查询字段以及可跨表查询的资源名。
API返回
返回示例
{
"inventories": [
{
"uuid": "c5cf6d7df3164418b3fe5c7569eb1dea",
"name": "TestAttachRule",
"description": "test atatch rule",
"vipIp": "192.168.0.187",
"guestIp": "10.0.0.244",
"vipUuid": "b5166a0c9adb4aaf8088022b5336209a",
"vipPortStart": 33.0,
"vipPortEnd": 33.0,
"privatePortStart": 33.0,
"privatePortEnd": 33.0,
"vmNicUuid": "8aa417eb4537475b815b289240e0c0c2",
"protocolType": "TCP",
"state": "Enabled",
"allowedCidr": "0.0.0.0/0",
"createDate": "Jun 7, 2017 9:21:17 PM",
"lastOpDate": "Jun 7, 2017 9:21:17 PM"
}
]
}| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 0.6 |
| inventories | List | 详情参考inventories | 0.6 |
#error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
#inventories
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| name | String | 资源名称 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| vipIp | String | VIP的IP地址 | 0.6 |
| guestIp | String | 虚拟机网卡的IP地址 | 0.6 |
| vipUuid | String | VIP UUID | 0.6 |
| vipPortStart | Integer | VIP的起始端口号 | 0.6 |
| vipPortEnd | Integer | VIP的结束端口号 | 0.6 |
| privatePortStart | Integer | 客户IP的起始端口号 | 0.6 |
| privatePortEnd | Integer | 客户IP的结束端口号 | 0.6 |
| vmNicUuid | String | 云主机网卡UUID | 0.6 |
| protocolType | String | 网络流量的协议类型 | 0.6 |
| state | String | 规则可用状态 | 0.6 |
| allowedCidr | String | 源CIDR; 端口转发规则只作用于源CIDR的流量 | 0.6 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
SDK示例
Java
SDK
QueryPortForwardingRuleAction action = new QueryPortForwardingRuleAction();
action.conditions = asList("name=pf1","state=Enabled");
action.sessionId = "4311e616ca8b4bb19d0792be1e08f3b8";
QueryPortForwardingRuleAction.Result res = action.call();Python
SDK
QueryPortForwardingRuleAction action = QueryPortForwardingRuleAction()
action.conditions = ["name=pf1","state=Enabled"]
action.sessionId = "b9745425f62d43289db77d9bfd117b35"
QueryPortForwardingRuleAction.Result res = action.call()更新端口转发规则(UpdatePortForwardingRule)
API请求
URLs
PUT zstack/v1/port-forwarding/{uuid}/actionsHeaders
Authorization: OAuth the-session-uuidBody
{
"updatePortForwardingRule": {
"name": "pf2",
"description": "new rule"
},
"systemTags": [],
"userTags": []
}Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"updatePortForwardingRule":{"name":"pf2","description":"new rule"}}' \
http://localhost:8080/zstack/v1/port-forwarding/07eb042c2f5837a99f4018c3ee7e4137/actions参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| uuid | String | url | 资源的UUID,唯一标示该资源 | 0.6 | |
| name (可选) | String | body(包含在updatePortForwardingRule结构中) | 资源名称 | 0.6 | |
| description (可选) | String | body(包含在updatePortForwardingRule结构中) | 资源的详细描述 | 0.6 | |
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
返回示例
{
"inventory": {
"uuid": "420edb331ec34871a416e570fa4faf8b",
"name": "TestAttachRule",
"description": "test atatch rule",
"vipIp": "192.168.0.187",
"guestIp": "10.0.0.244",
"vipUuid": "8282dbb28b70416790bd83d08d3718ba",
"vipPortStart": 33.0,
"vipPortEnd": 33.0,
"privatePortStart": 33.0,
"privatePortEnd": 33.0,
"vmNicUuid": "2e63ec7524074e9dad1255d5e02f0697",
"protocolType": "TCP",
"state": "Enabled",
"allowedCidr": "0.0.0.0/0",
"createDate": "Jun 7, 2017 9:20:38 PM",
"lastOpDate": "Jun 7, 2017 9:20:38 PM"
}
}#error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| name | String | 资源名称 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| vipIp | String | VIP的IP地址 | 0.6 |
| guestIp | String | 虚拟机网卡的IP地址 | 0.6 |
| vipUuid | String | VIP UUID | 0.6 |
| vipPortStart | Integer | VIP的起始端口号 | 0.6 |
| vipPortEnd | Integer | VIP的结束端口号 | 0.6 |
| privatePortStart | Integer | 客户IP的起始端口号 | 0.6 |
| privatePortEnd | Integer | 客户IP的结束端口号 | 0.6 |
| vmNicUuid | String | 云主机网卡UUID | 0.6 |
| protocolType | String | 网络流量的协议类型 | 0.6 |
| state | String | 规则可用状态 | 0.6 |
| allowedCidr | String | 源CIDR; 端口转发规则只作用于源CIDR的流量 | 0.6 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
SDK示例
Java
SDK
UpdatePortForwardingRuleAction action = new UpdatePortForwardingRuleAction();
action.uuid = "b180491f86cd4de4befd11df26ebc4b1";
action.name = "pf2";
action.description = "new rule";
action.sessionId = "1130b06d95ed438386c8199cfae9e55b";
UpdatePortForwardingRuleAction.Result res = action.call();Python
SDK
UpdatePortForwardingRuleAction action = UpdatePortForwardingRuleAction()
action.uuid = "fe896714482549eaac0cd07a6661664a"
action.name = "pf2"
action.description = "new rule"
action.sessionId = "0992d35c275a4def8bcbb013653b65f9"
UpdatePortForwardingRuleAction.Result res = action.call()改变端口转发规则的状态(ChangePortForwardingRuleState)
API请求
URLs
PUT zstack/v1/port-forwarding/{uuid}/actionsHeaders
Authorization: OAuth the-session-uuidBody
{
"changePortForwardingRuleState": {
"stateEvent": "disable"
},
"systemTags": [],
"userTags": []
}Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"changePortForwardingRuleState":{"stateEvent":"disable"}}' \
http://localhost:8080/zstack/v1/port-forwarding/d391cd5c4b57369daa48190ec0e193f6/actions参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| uuid | String | url | 资源的UUID,唯一标示该资源 | 0.6 | |
| stateEvent | String | body(包含在changePortForwardingRuleState结构中) | 端口转发规则的状态 |
|
0.6 |
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
返回示例
{
"inventory": {
"uuid": "59d724e1f8e8417693fbc14d124ce801",
"name": "TestAttachRule",
"description": "test atatch rule",
"vipIp": "192.168.0.187",
"guestIp": "10.0.0.244",
"vipUuid": "f9c5cbc8662d43408dc704003d4f70ad",
"vipPortStart": 33.0,
"vipPortEnd": 33.0,
"privatePortStart": 33.0,
"privatePortEnd": 33.0,
"vmNicUuid": "1b41288698ac45149f352ab6c8de2531",
"protocolType": "TCP",
"state": "Enabled",
"allowedCidr": "0.0.0.0/0",
"createDate": "Jun 7, 2017 9:20:26 PM",
"lastOpDate": "Jun 7, 2017 9:20:26 PM"
}
}#error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| name | String | 资源名称 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| vipIp | String | VIP的IP地址 | 0.6 |
| guestIp | String | 虚拟机网卡的IP地址 | 0.6 |
| vipUuid | String | VIP UUID | 0.6 |
| vipPortStart | Integer | VIP的起始端口号 | 0.6 |
| vipPortEnd | Integer | VIP的结束端口号 | 0.6 |
| privatePortStart | Integer | 客户IP的起始端口号 | 0.6 |
| privatePortEnd | Integer | 客户IP的结束端口号 | 0.6 |
| vmNicUuid | String | 云主机网卡UUID | 0.6 |
| protocolType | String | 网络流量的协议类型 | 0.6 |
| state | String | 规则可用状态 | 0.6 |
| allowedCidr | String | 源CIDR; 端口转发规则只作用于源CIDR的流量 | 0.6 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
SDK示例
Java
SDK
ChangePortForwardingRuleStateAction action = new ChangePortForwardingRuleStateAction();
action.uuid = "4a721a0136d94428951072e3314b5187";
action.stateEvent = "disable";
action.sessionId = "ce7e78520ff34fbd8dcc181fba226ee0";
ChangePortForwardingRuleStateAction.Result res = action.call();Python
SDK
ChangePortForwardingRuleStateAction action = ChangePortForwardingRuleStateAction()
action.uuid = "a694cfa2057e4bd087a076e6f970f8cf"
action.stateEvent = "disable"
action.sessionId = "abbfa65e2f3040038dc85a68ffa37c8b"
ChangePortForwardingRuleStateAction.Result res = action.call()获取云主机网卡列表(GetPortForwardingAttachableVmNics)
获取可应用端口转发规则的云主机网卡列表。
API请求
URLs
GET zstack/v1/port-forwarding/{ruleUuid}/vm-instances/candidate-nicsHeaders
Authorization: OAuth the-session-uuidCurl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b6d8f8edb4aa48f388591c2dc83fabe9" \
-X GET http://localhost:8080/zstack/v1/port-forwarding/039e99f4cf9741adabaf972914fa9a30/vm-instances/candidate-nics参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| ruleUuid | String | url | 规则的uuid | 0.6 | |
| systemTags (可选) | List | query | 系统标签 | 0.6 | |
| userTags (可选) | List | query | 用户标签 | 0.6 |
API返回
返回示例
{
"inventories": [
{
"uuid": "2eb90e57e12f400ba8349742840eb9f9",
"vmInstanceUuid": "efa24e175ba34c1196f9818ea6f56e5f",
"l3NetworkUuid": "39e4eeeb2b1e4bb885922cb5c6585277",
"ip": "192.168.0.123",
"mac": "fa:ef:34:5c:6c:00",
"netmask": "255.255.255.0",
"gateway": "192.168.0.1",
"internalName": "eth0",
"deviceId": 0.0
}
]
}| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 0.6 |
| inventories | List | 详情参考inventories | 0.6 |
#error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
#inventories
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| vmInstanceUuid | String | 云主机UUID | 0.6 |
| l3NetworkUuid | String | 三层网络UUID | 0.6 |
| ip | String | 0.6 | |
| mac | String | 0.6 | |
| netmask | String | 0.6 | |
| gateway | String | 0.6 | |
| metaData | String | 0.6 | |
| deviceId | Integer | 0.6 | |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
SDK示例
Java
SDK
GetPortForwardingAttachableVmNicsAction action = new GetPortForwardingAttachableVmNicsAction();
action.ruleUuid = "5980282a68024f039ddfe379b43e49b1";
action.sessionId = "e309fcb7cb0545a3b802a21acfa4b397";
GetPortForwardingAttachableVmNicsAction.Result res = action.call();Python
SDK
GetPortForwardingAttachableVmNicsAction action = GetPortForwardingAttachableVmNicsAction()
action.ruleUuid = "530c24831aaf4ff6bda365c774952576"
action.sessionId = "595b1267d25d4c709c081ecb3ea2f00e"
GetPortForwardingAttachableVmNicsAction.Result res = action.call()挂载规则到虚拟机网卡上(AttachPortForwardingRule)
API请求
URLs
POST zstack/v1/port-forwarding/{ruleUuid}/vm-instances/nics/{vmNicUuid}Headers
Authorization: OAuth the-session-uuidBody
{
"params": {},
"systemTags": [],
"userTags": []
}
Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{}}' http://localhost:8080/zstack/v1/port-forwarding/4c74c079f5b836e1912d20914953d722/vm-instances/nics/05c384cc720e32e4b57e93daea1c5b91参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| ruleUuid | String | url | 规则的uuid | 0.6 | |
| vmNicUuid | String | url | 云主机网卡UUID | 0.6 | |
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
返回示例
{
"inventory": {
"uuid": "8727976deceb42e898d9efc50863564a",
"name": "TestAttachRule",
"description": "test atatch rule",
"vipIp": "192.168.0.187",
"guestIp": "10.0.0.244",
"vipUuid": "2aa6a4055ce94c319894dfddc330376f",
"vipPortStart": 33,
"vipPortEnd": 33,
"privatePortStart": 33,
"privatePortEnd": 33,
"vmNicUuid": "39f90e4259784eee880e1cbef31c88da",
"protocolType": "TCP",
"state": "Enabled",
"allowedCidr": "0.0.0.0/0",
"createDate": "Jun 7, 2017 9:20:32 PM",
"lastOpDate": "Jun 7, 2017 9:20:32 PM"
}
}#error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| name | String | 资源名称 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| vipIp | String | VIP的IP地址 | 0.6 |
| guestIp | String | 虚拟机网卡的IP地址 | 0.6 |
| vipUuid | String | VIP UUID | 0.6 |
| vipPortStart | Integer | VIP的起始端口号 | 0.6 |
| vipPortEnd | Integer | VIP的结束端口号 | 0.6 |
| privatePortStart | Integer | 客户IP的起始端口号 | 0.6 |
| privatePortEnd | Integer | 客户IP的结束端口号 | 0.6 |
| vmNicUuid | String | 云主机网卡UUID | 0.6 |
| protocolType | String | 网络流量的协议类型 | 0.6 |
| state | String | 规则可用状态 | 0.6 |
| allowedCidr | String | 源CIDR; 端口转发规则只作用于源CIDR的流量 | 0.6 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
SDK示例
Java
SDK
AttachPortForwardingRuleAction action = new AttachPortForwardingRuleAction();
action.ruleUuid = "b34b406cf94f432eb0755a9201798d1f";
action.vmNicUuid = "be5e6e16b1f0428a833d3152699766ea";
action.sessionId = "14dc12a577f14f1b9622850e00f06884";
AttachPortForwardingRuleAction.Result res = action.call();Python
SDK
AttachPortForwardingRuleAction action = AttachPortForwardingRuleAction()
action.ruleUuid = "3b83c27e561643778396b003a6294cea"
action.vmNicUuid = "4892663d34c642f8854306188276e890"
action.sessionId = "e1b52fc03d0f479c8da456abd4fd6e6b"
AttachPortForwardingRuleAction.Result res = action.call()从虚拟机网卡卸载规则(DetachPortForwardingRule)
API请求
URLs
DELETE/v1/port-forwarding/{uuid}/vm-instances/nicsHeaders
Authorization: OAuth the-session-uuidCurl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth a6a2c933ccf449c99bd49481e9636751" \
-X DELETE http://localhost:8080/zstack/v1/port-forwarding/484d4bed50ab4c18a670982952ccfe61/vm-instances/nics?参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| uuid | String | url | 资源的UUID,唯一标示该资源 | 0.6 | |
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
返回示例
{
"inventory": {
"uuid": "dc6ec21666fb42e6be62455f8e5a7307",
"name": "TestAttachRule",
"description": "test atatch rule",
"vipIp": "192.168.0.187",
"guestIp": "10.0.0.244",
"vipUuid": "72dfbe63f95147048a98e514ecbd3ee8",
"vipPortStart": 33.0,
"vipPortEnd": 33.0,
"privatePortStart": 33.0,
"privatePortEnd": 33.0,
"vmNicUuid": "f06654fb4bd6485ebfba84398c98966f",
"protocolType": "TCP",
"state": "Enabled",
"allowedCidr": "0.0.0.0/0",
"createDate": "Jun 7, 2017 9:20:02 PM",
"lastOpDate": "Jun 7, 2017 9:20:02 PM"
}
}#error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| name | String | 资源名称 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| vipIp | String | VIP的IP地址 | 0.6 |
| guestIp | String | 虚拟机网卡的IP地址 | 0.6 |
| vipUuid | String | VIP UUID | 0.6 |
| vipPortStart | Integer | VIP的起始端口号 | 0.6 |
| vipPortEnd | Integer | VIP的结束端口号 | 0.6 |
| privatePortStart | Integer | 客户IP的起始端口号 | 0.6 |
| privatePortEnd | Integer | 客户IP的结束端口号 | 0.6 |
| vmNicUuid | String | 云主机网卡UUID | 0.6 |
| protocolType | String | 网络流量的协议类型 | 0.6 |
| state | String | 规则可用状态 | 0.6 |
| allowedCidr | String | 源CIDR; 端口转发规则只作用于源CIDR的流量 | 0.6 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
SDK示例
Java
SDK
DetachPortForwardingRuleAction action = new DetachPortForwardingRuleAction();
action.uuid = "307d4bf5fed34a859ade0af30c6720f9";
action.sessionId = "8c78997bf11344d79b49a2254ab88bb8";
DetachPortForwardingRuleAction.Result res = action.call();Python
SDK
DetachPortForwardingRuleAction action = DetachPortForwardingRuleAction()
action.uuid = "c284fc4425ea4467b81dad21df147a8e"
action.sessionId = "545a07392cb2409e9888f8737da4ddfc"
DetachPortForwardingRuleAction.Result res = action.call()