Updated on 2024-10-31 GMT+08:00

Creating a Port

Function

This API is used to create a port.

URI

POST /v2.0/ports

Request Parameters

Table 1 Request parameter

Parameter

Type

Mandatory

Description

port

port object

Yes

Specifies the port object list. For details, see Table 2.

Table 2 port objects

Attribute

Mandatory

Type

Description

name

No

String

Specifies the port name.

network_id

Yes

String

  • Specifies the ID of the network to which the port belongs.
  • The network ID must exist.
NOTE:

To obtain the network ID:

  • Method 1: Log in to the VPC console and click the target subnet on the Subnets page. You can view the network ID on the displayed page.
  • Method 2: Call the API for querying subnets. For details, see Querying Subnets.

admin_state_up

No

Boolean

Specifies the administrative status.

The default value is true.

fixed_ips

No

Array of fixed_ip objects

Specifies the port IP address. For details, see Table 3. For example, the value is "fixed_ips": [{"subnet_id": "4dc70db6-cb7f-4200-9790-a6a910776bba", "ip_address": "192.169.25.79"}].

"fixed_ips": [{"subnet_id": "1fd001aa-6946-4168-86d9-924c7d3ef8fb", "ip_address": "2a07:b980:4030:14::1"}]

security_groups

No

Array of strings

Specifies the UUID of the security group, for example, "security_groups": ["a0608cbf-d047-4f54-8b28-cd7b59853fff"]. This is an extended attribute.

This parameter cannot be left blank.

allowed_address_pairs

No

Array of allowed_address_pairs objects

Specifies the IP address and MAC address pair. This is an extended attribute. For details, see Table 4.

Instructions:

  • The IP address cannot be 0.0.0.0.
  • Configure a dedicated security group for the port if the parameter allowed_address_pairs has a large CIDR block (subnet mask less than 24).
  • If the value of allowed_address_pairs is 1.1.1.1/0, the source/destination check is disabled.
  • In the hardware SDN networking plan, the ip_address attribute value cannot be in CIDR format.
  • To assign a virtual IP address to an ECS, the IP address configured in allowed_address_pairs must be an existing ECS NIC IP address. Otherwise, the virtual IP address cannot be used for communication.
  • Set allowed_address_pairs of the cloud server to 1.1.1.1/0.

extra_dhcp_opts

No

Array of extra_dhcp_opt objects

Specifies the extended DHCP option. This is an extended attribute. For details, see Table 5.

binding:profile

No

Object

  • Specifies the user-defined settings. This is an extended attribute.
  • Instructions:
    • The internal_elb field is in boolean type and is available to common tenants. Set the value of this parameter to true only when you assign a virtual IP address to an internal network load balancer. The value of this field is maintained by the system and cannot be changed. Example:

      {"internal_elb": true}

    • The disable_security_groups field is in boolean type and is available to common tenants. The default value is false. In high-performance communication scenarios, you can set the parameter value to true, which makes this parameter to be available to common tenants. You can specify this parameter when creating a port. Currently, the value of this parameter can only be set to true.

      Example:

      {"disable_security_groups": true }

      Currently, the value can only be set to true. When the value is set to true, the FWaaS function does not take effect.

    • For Consumer Cloud, the values of udp_srvports and tcp_srvports fields are strings. By default, udp_srvports and tcp_srvports are not specified. You can set udp_srvports and tcp_srvports to port numbers, which indicates that the TCP and UDP packets support highly concurrently connections. However, these packets are not protected by network ACLs and security group rules. The udp_srvports and tcp_srvports fields can be updated concurrently.

      Format:

      {"tcp_srvports": "port1 port2 port3", "udp_srvports": "port1 port2 port3"}

      You can enter a maximum of 15 port numbers for each value. Use a space to separate adjacent port numbers. The port number ranges from 1 to 65535.

      Example:

      {"tcp_srvports": "80 443", "udp_srvports": "53"}

      This example indicates that inbound TCP packets to ports 80 and 443, and inbound UDP packets to port 53 support highly concurrent connections. However, these packets are not controlled by network ACL and security group rules.

binding:vnic_type

No

String

Specifies the type of the bound vNIC.

normal: Softswitch

port_security_enabled

No

Boolean

Specifies whether the security option is enabled for the port.

true indicates that security groups can be added and DHCP anti-spoofing is enabled. false indicates that security groups and DHCP anti-spoofing are not applied.

device_owner

No

String

Specifies the device that the port belongs to.

Currently, only "" and neutron:VIP_PORT are supported. neutron:VIP_PORT indicates the port of a virtual IP address.

Table 3 fixed_ip objects

Attribute

Mandatory

Type

Description

subnet_id

No

String

Specifies the ID of the subnet to which the port belongs.

This parameter cannot be updated.

ip_address

No

String

Specifies the port IP address.

This parameter cannot be updated.

Table 4 allowed_address_pairs objects

Parameter

Mandatory

Type

Description

ip_address

Yes

String

  • Specifies the IP address.
  • You cannot set it to 0.0.0.0/0.
  • Configure a dedicated security group for the port if the parameter allowed_address_pairs has a large CIDR block (subnet mask less than 24).
  • If the value of allowed_address_pairs is 1.1.1.1/0, the source/destination check is disabled.
  • Set allowed_address_pairs of the cloud server to 1.1.1.1/0.
  • If the value of parameter allowed_address_pairs is specified, parameter ip_address is mandatory.

mac_address

No

String

Specifies the MAC address. By default, the MAC address of the local port is used.

Table 5 extra_dhcp_opt objects

Attribute

Mandatory

Type

Description

opt_name

No

String

Specifies the option name.

opt_value

No

String

Specifies the option value.

Example Request

Create a port named port-test on network whose ID is 00ae08c5-f727-49ab-ad4b-b069398aa171.

POST https://{Endpoint}/v2.0/ports

{
    "port": {
       "admin_state_up": true,
        "network_id": "00ae08c5-f727-49ab-ad4b-b069398aa171",
        "name": "port-test"
    }
}

Response Parameters

Table 6 Response parameter

Parameter

Type

Description

port

port object

Specifies the port information. For details, see Table 7.

Table 7 port objects

Attribute

Type

Description

id

String

Specifies the port ID. A maximum of 255 characters are allowed.

This parameter is not mandatory when you query ports.

name

String

Specifies the port name.

network_id

String

Specifies the ID of the network to which the port belongs.

admin_state_up

Boolean

Specifies the administrative status.

The default value is true.

mac_address

String

Specifies the port MAC address. For example, "mac_address": "fa:16:3e:9e:ff:55".

This value can only be dynamically assigned by the system.

fixed_ips

Array of fixed_ip objects

Specifies the port IP address. For details, see Table 8. For example, the value is "fixed_ips": [{"subnet_id": "4dc70db6-cb7f-4200-9790-a6a910776bba", "ip_address": "192.169.25.79"}].

"fixed_ips": [{"subnet_id": "1fd001aa-6946-4168-86d9-924c7d3ef8fb", "ip_address": "2a07:b980:4030:14::1"}]

device_id

String

Specifies the device ID.

This value is automatically maintained by the system and cannot be set or updated manually. The port with this field specified cannot be deleted.

device_owner

String

Specifies the DHCP, router or Nova to which a device belongs.

The value can be network:dhcp, network:router_interface_distributed, compute:xxx, neutron:VIP_PORT, neutron:LOADBALANCERV2, neutron:LOADBALANCERV3, network:endpoint_interface, network:nat_gateway, or network:ucmp. (In value compute:xxx, xxx specifies the AZ name, for example, compute:aa-bb-cc indicates that the private IP address is used by an ECS in the aa-bb-cc AZ).

This parameter value cannot be updated. You can only set device_owner to neutron:VIP_PORT for a virtual IP address port during port creation. If this parameter of a port is not left blank, the port can only be deleted when this parameter value is neutron:VIP_PORT.

The port with this field specified cannot be deleted.

tenant_id

String

Specifies the project ID.

status

String

Specifies the port status. The value can be ACTIVE, BUILD, or DOWN.

The status of a HANA SR-IOV VM port is always DOWN.

security_groups

Array of strings

Specifies the UUID of the security group, for example, "security_groups": ["a0608cbf-d047-4f54-8b28-cd7b59853fff"]. This is an extended attribute.

This parameter cannot be left blank.

allowed_address_pairs

Array of allowed_address_pairs objects

Specifies the IP address and MAC address pair. This is an extended attribute. For details, see Table 9.

Instructions:

  • The IP address cannot be 0.0.0.0.
  • Configure a dedicated security group for the port if the parameter allowed_address_pairs has a large CIDR block (subnet mask less than 24).
  • If the value of allowed_address_pairs is 1.1.1.1/0, the source/destination check is disabled.
  • In the hardware SDN networking plan, the ip_address attribute value cannot be in CIDR format.
  • To assign a virtual IP address to an ECS, the IP address configured in allowed_address_pairs must be an existing ECS NIC IP address. Otherwise, the virtual IP address cannot be used for communication.
  • Set allowed_address_pairs of the cloud server to 1.1.1.1/0.

extra_dhcp_opts

Array of extra_dhcp_opt objects

Specifies the extended DHCP option. This is an extended attribute. For details, see Table 10.

binding:vif_details

binding:vif_details object

For details, see Table 11.

binding:profile

Object

  • Specifies the user-defined settings. This is an extended attribute.
  • Instructions:
    • The internal_elb field is in boolean type and is available to common tenants. Set the value of this parameter to true only when you assign a virtual IP address to an internal network load balancer. The value of this field is maintained by the system and cannot be changed. Example:

      {"internal_elb": true}

    • The disable_security_groups field is in boolean type and is available to common tenants. The default value is false. In high-performance communication scenarios, you can set the parameter value to true, which makes this parameter to be available to common tenants. You can specify this parameter when creating a port. Currently, the value of this parameter can only be set to true.

      Example:

      {"disable_security_groups": true }

      Currently, the value can only be set to true. When the value is set to true, the FWaaS function does not take effect.

    • For Consumer Cloud, the values of udp_srvports and tcp_srvports fields are strings. By default, udp_srvports and tcp_srvports are not specified. You can set udp_srvports and tcp_srvports to port numbers, which indicates that the TCP and UDP packets support highly concurrently connections. However, these packets are not protected by network ACLs and security group rules. The udp_srvports and tcp_srvports fields can be updated concurrently.

      Format:

      {"tcp_srvports": "port1 port2 port3", "udp_srvports": "port1 port2 port3"}

      You can enter a maximum of 15 port numbers for each value. Use a space to separate adjacent port numbers. The port number ranges from 1 to 65535.

      Example:

      {"tcp_srvports": "80 443", "udp_srvports": "53"}

      This example indicates that inbound TCP packets to ports 80 and 443, and inbound UDP packets to port 53 support highly concurrent connections. However, these packets are not controlled by network ACL and security group rules.

binding:vnic_type

String

Specifies the type of the bound vNIC.

normal: Softswitch

port_security_enabled

Boolean

Specifies whether the security option is enabled for the port. If the option is not enabled, the security group and DHCP snooping do not take effect.

dns_assignment

Array of dns_assignment objects

Specifies the default private network domain name information of the primary NIC. This is an extended attribute.

The system automatically sets this parameter, and you are not allowed to configure or change the parameter value.

  • hostname: dns_name value of the NIC
  • ip_address: Private IPv4 address of the NIC
  • fqdn: Default private network fully qualified domain name (FQDN) of the IP address

dns_name

String

Specifies the default private network DNS name of the primary NIC. This is an extended attribute.

The system automatically sets this parameter, and you are not allowed to configure or change the parameter value. Before accessing the default private network domain name, ensure that the subnet uses the DNS provided by the current system.

project_id

String

Specifies the project ID. For details about how to obtain a project ID, see Obtaining a Project ID.

created_at

String

Specifies the time (UTC) when the port is created.

Format: yyyy-MM-ddTHH:mm:ss

updated_at

String

Specifies the time (UTC) when the port is updated.

Format: yyyy-MM-ddTHH:mm:ss

Table 8 fixed_ip objects

Attribute

Type

Description

subnet_id

String

Specifies the ID of the subnet to which the port belongs.

This parameter cannot be updated.

ip_address

String

Specifies the port IP address.

This parameter cannot be updated.

Table 9 allowed_address_pairs objects

Attribute

Type

Description

ip_address

String

Specifies the IP address.

This parameter cannot be 0.0.0.0.

mac_address

String

Specifies the MAC address.

Table 10 extra_dhcp_opt objects

Attribute

Type

Description

opt_name

String

Specifies the option name.

opt_value

String

Specifies the option value.

Table 11 binding:vif_details object

Parameter

Type

Description

primary_interface

Boolean

If the value is true, this is the primary NIC.

port_filter

Boolean

Specifies the port used for filtering in security groups to protect against MAC or IP spoofing.

ovs_hybrid_plug

Boolean

Specifies that OVS hybrid plug should be used by Nova APIs.

Table 12 dns_assignment object

Parameter

Type

Description

hostname

String

Specifies the host name of the port.

ip_address

String

Specifies the port IP address.

fqdn

String

Specifies the private network fully qualified domain name (FQDN) of the port.

Example Response

{
    "port": {
        "id": "a7d98f3c-b42f-460b-96a1-07601e145961",
        "name": "port-test",
        "status": "DOWN",
        "admin_state_up": true,
        "fixed_ips": [],
        "mac_address": "fa:16:3e:01:f7:90",
        "network_id": "00ae08c5-f727-49ab-ad4b-b069398aa171",
        "tenant_id": "db82c9e1415a464ea68048baa8acc6b8",
        "project_id": "db82c9e1415a464ea68048baa8acc6b8",
        "device_id": "",
        "device_owner": "",
        "security_groups": [
            "d0d58aa9-cda9-414c-9c52-6c3daf8534e6"
        ],
        "extra_dhcp_opts": [],
        "allowed_address_pairs": [],
        "binding:vnic_type": "normal",
        "binding:vif_details": {},
        "binding:profile": {},
        "port_security_enabled": true,
        "created_at": "2018-09-20T01:45:26",
        "updated_at": "2018-09-20T01:45:26"
    }
}

Status Code

See Status Codes.

Error Code

See Error Codes.