curl --request PUT \
--url https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports \
--header 'Content-Type: application/json' \
--data '
{
"ports": [
{
"vm_port": 32768,
"protocol": "tcp",
"source_cidrs": [
"<string>"
],
"description": "<string>",
"host_port": 14000,
"nic_index": 0
}
],
"confirm_restart": false
}
'import requests
url = "https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports"
payload = {
"ports": [
{
"vm_port": 32768,
"protocol": "tcp",
"source_cidrs": ["<string>"],
"description": "<string>",
"host_port": 14000,
"nic_index": 0
}
],
"confirm_restart": False
}
headers = {"Content-Type": "application/json"}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
ports: [
{
vm_port: 32768,
protocol: 'tcp',
source_cidrs: ['<string>'],
description: '<string>',
host_port: 14000,
nic_index: 0
}
],
confirm_restart: false
})
};
fetch('https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'ports' => [
[
'vm_port' => 32768,
'protocol' => 'tcp',
'source_cidrs' => [
'<string>'
],
'description' => '<string>',
'host_port' => 14000,
'nic_index' => 0
]
],
'confirm_restart' => false
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports"
payload := strings.NewReader("{\n \"ports\": [\n {\n \"vm_port\": 32768,\n \"protocol\": \"tcp\",\n \"source_cidrs\": [\n \"<string>\"\n ],\n \"description\": \"<string>\",\n \"host_port\": 14000,\n \"nic_index\": 0\n }\n ],\n \"confirm_restart\": false\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports")
.header("Content-Type", "application/json")
.body("{\n \"ports\": [\n {\n \"vm_port\": 32768,\n \"protocol\": \"tcp\",\n \"source_cidrs\": [\n \"<string>\"\n ],\n \"description\": \"<string>\",\n \"host_port\": 14000,\n \"nic_index\": 0\n }\n ],\n \"confirm_restart\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"ports\": [\n {\n \"vm_port\": 32768,\n \"protocol\": \"tcp\",\n \"source_cidrs\": [\n \"<string>\"\n ],\n \"description\": \"<string>\",\n \"host_port\": 14000,\n \"nic_index\": 0\n }\n ],\n \"confirm_restart\": false\n}"
response = http.request(request)
puts response.read_body[
{
"id": "pm_0123abcd",
"host_port": 123,
"vm_port": 123,
"protocol": "<string>",
"host_address": "<string>",
"nic_index": 0,
"source_cidrs": [
"<string>"
],
"description": "<string>",
"public_host": "<string>",
"forwarding_backend": "vmm_hostfwd",
"restart_required": false,
"guest_ip": "<string>"
}
]{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Set port mappings
Bulk-replace all port mappings for this CVM. Admins with two-factor authentication enabled may specify host_port within the node’s managed range; other callers cannot pin ports. Omitted or null host_port keeps an existing allocation or randomly allocates a new one. User-NIC port changes require restart confirmation; bridge-NIC rules apply live.
curl --request PUT \
--url https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports \
--header 'Content-Type: application/json' \
--data '
{
"ports": [
{
"vm_port": 32768,
"protocol": "tcp",
"source_cidrs": [
"<string>"
],
"description": "<string>",
"host_port": 14000,
"nic_index": 0
}
],
"confirm_restart": false
}
'import requests
url = "https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports"
payload = {
"ports": [
{
"vm_port": 32768,
"protocol": "tcp",
"source_cidrs": ["<string>"],
"description": "<string>",
"host_port": 14000,
"nic_index": 0
}
],
"confirm_restart": False
}
headers = {"Content-Type": "application/json"}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
ports: [
{
vm_port: 32768,
protocol: 'tcp',
source_cidrs: ['<string>'],
description: '<string>',
host_port: 14000,
nic_index: 0
}
],
confirm_restart: false
})
};
fetch('https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'ports' => [
[
'vm_port' => 32768,
'protocol' => 'tcp',
'source_cidrs' => [
'<string>'
],
'description' => '<string>',
'host_port' => 14000,
'nic_index' => 0
]
],
'confirm_restart' => false
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports"
payload := strings.NewReader("{\n \"ports\": [\n {\n \"vm_port\": 32768,\n \"protocol\": \"tcp\",\n \"source_cidrs\": [\n \"<string>\"\n ],\n \"description\": \"<string>\",\n \"host_port\": 14000,\n \"nic_index\": 0\n }\n ],\n \"confirm_restart\": false\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports")
.header("Content-Type", "application/json")
.body("{\n \"ports\": [\n {\n \"vm_port\": 32768,\n \"protocol\": \"tcp\",\n \"source_cidrs\": [\n \"<string>\"\n ],\n \"description\": \"<string>\",\n \"host_port\": 14000,\n \"nic_index\": 0\n }\n ],\n \"confirm_restart\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://cloud-api.phala.com/api/v1/cvms/{cvm_id}/ports")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"ports\": [\n {\n \"vm_port\": 32768,\n \"protocol\": \"tcp\",\n \"source_cidrs\": [\n \"<string>\"\n ],\n \"description\": \"<string>\",\n \"host_port\": 14000,\n \"nic_index\": 0\n }\n ],\n \"confirm_restart\": false\n}"
response = http.request(request)
puts response.read_body[
{
"id": "pm_0123abcd",
"host_port": 123,
"vm_port": 123,
"protocol": "<string>",
"host_address": "<string>",
"nic_index": 0,
"source_cidrs": [
"<string>"
],
"description": "<string>",
"public_host": "<string>",
"forwarding_backend": "vmm_hostfwd",
"restart_required": false,
"guest_ip": "<string>"
}
]{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Path Parameters
Body
Bulk-replace all port mappings for a CVM.
Adding or removing a user-NIC mapping, or changing its host_port, requires
a CVM restart. Bridge-NIC mappings are applied live. Set
confirm_restart=True to accept the restart; otherwise the server
responds with HTTP 409 and the detailed change list so the client can
prompt the user before retrying.
Response
Updated port mappings
A hashed identifier that maps to an internal database ID
^pm_.+"pm_0123abcd"
Node-level public DNS/IP; None when the node is not publicly reachable.
"vmm_hostfwd" when QEMU forwards the port on a user-mode NIC, "netd_forward" when teescope-netd DNATs it to a bridge-mode NIC, "unknown" when the node has not reported its default network mode.
Whether adding or removing this rule needs a CVM restart. Always false for netd_forward rules: netd installs them on the live host.
Guest address a netd_forward rule currently resolves to, read back from the node. None for vmm_hostfwd rules and when the node was not reachable. Empty string means the NIC's DHCP reservation is gone and the rule is inert.
Was this page helpful?

