Creates a VSwitch in a VPC.

Note the following before you call this action:
  • Up to 24 VSwitches can be created in a VPC.

  • The first and last three IP addresses of the VSwitch are reserved by the system. For example, if the CIDR block of a VSwitch is 192.168.1.0/24, IP addresses 192.168.1.0, 192.168.1.253, 192.168.1.254, and 192.168.1.255 are reserved.

  • The number of cloud product instances under the VSwitch cannot exceed the remaining capacity of the VPC (subtract the current number of cloud product instances from 15,000).

  • A cloud product instance can only belong to one VSwitch.

  • VSwitches do not support broadcasting or multicasting.

After a VSwitch is created, you cannot modify its CIDR block.

Debug

By using API Explorer, you can easily debug APIs, automatically generate SDK code examples, and quickly search for APIs.

Request parameters

Parameter Type Required? Example value Description
Action String Yes CreateVSwitch

The name of this action. Value:

CreateVSwitch

CidrBlock String Yes 172.16.0.0/24

The CIDR block of VSwitch. The IP address range must meet the following requirements:

  • The length of the subnet mask for the VSwitch must be in the range of /16 to /29.
  • The CIDR block of the VSwitch must belong to the CIDR block of the VPC.
  • The CIDR block of the VSwitch cannot be the same as any destination CIDR block in route entries of the VPC, but can be the subnet of the destination CIDR block.
  • If the network segment of the switch is the same as the network segment of the same VPC, there can be only one switch for the VPC.
VpcId String Yes vpc-257gq6nxxxxxxx

The ID of the VPC to which the VSwitch belongs.

ZoneId String Yes cn-hangzhou-b

The ID of the zone to which the switch belongs.

To query the region ID, call DescribeZones.

RegionId String Yes cn-hangzhou

The ID of the region to which the VSwitch belongs.

Ipv6CidrBlock Integer No 0

The IPv6 CIDR block of the VSwitch. You can customize the last eight bits of an IPv6 CIDR block. Value range: 0 to 255.

By default, the length of the IPv6 CIDK mask is /64.

Description String No This is my vswitch.

The description of the VSwitch.

The description must be 2 to 256 characters in length and must start with a letter. It cannot start with http:// or https://.

VSwitchName String No VSwitch-1

The name of the VSwitch.

The name must be 1 to 128 characters in length and must start with a letter. It cannot start with http:// or https://.

ClientToken String No dhueeuxxxxxxdde

A client token used to guarantee the idempotence of requests.

This parameter value is generated by the client and must be unique. It must be 1 to 64 ASCII characters in length.

OwnerAccount String No N/A

The owner account.

Response parameters

Parameter Type Example value Description
RequestId String 861E6630-AEC0-4B2D-B214-6CB5E44B7F04 The ID of the request.
VSwitchId String vsw-25naue4gz The ID of the switch.

Examples

Request example


https://vpc.aliyuncs.com/?Action=CreateVSwitch
&CidrBlock=172.16.0.0/24
&VpcId=vpc-257gq6nxxxxxxx
&ZoneId=cn-hangzhou-b
&<CommonParameters>
Response example
  • XML format

    <CreateVSwitchResponse>
      <RequestId>0ED8D006-F706-4D23-88ED-E11ED28DCAC0</RequestId>
      <VSwitchId>vsw-25naue4gz</VSwitchId>
    </CreateVSwitchResponse>
    
  • JSON format

    {
    	"RequestId":"0ED8D006-F706-4D23-88ED-E11ED28DCAC0",
    	"VSwitchId":"vsw-25naue4gz"
    }

Error codes

HTTP status code Error code Error message Description
404 InvalidZoneId.NotFound Specified zone does not exist. The ID of the zone is incorrect.
404 InvalidVpcId.NotFound Specified VPC does not exist. The specified VPC does not exist.
400 InvalidVSwitchName.Malformed Specified virtual switch name is not valid. The format of the name of the specified VSwitch is invalid.
400 ResourceNotAvailable Resource you requested is not available in this region or zone. The resource that you requested is not available in this region or zone.
400 InvalidParameter Specified CIDR block is not valid in VPC. The specified CIDR block does not belong to the CIDR block of the VPC.
400 InvalidCidrBlock.Overlapped Specified CIDR block overlapped with other subnets. The specified CIDR block overlaps the CIDR block of another VSwitch or the destination CIDK block of an existing customer route. Select a CIDR block that is not used.
400 InvalidCidrBlock.Overlapped Specified CIDR block overlapped with other entry. The specified CIDR block overlaps with the CIDR block of another VSwitch, or the destination CIDK block of an existing customer route. Select a CIDR block that is not used.
400 QuotaExceeded.VSwitch Virtual switch quota exceeded. The maximum number of VSwitches was exceeded.
400 IncorrectRouteEntryStatus Some route entry status blocked this operation. The route table includes entries in the Pending or Modifying status.
400 IncorrectVSwitchStatus Some virtual switch is modifying within the same VPC. The VPC has multiple VSwitches that are in the Modifying status. Please try again later.
400 InvalidCirdrBlock.MaskLength Specified CIDR block is not valid . The form of the CIDR block is invalid.
400 IncorrectVpcStatus Current VPC status does not support this operation. The current status of VPC does not support the action.
400 MissingParameter Miss mandatory parameter. The required parameters are missing.
400 IncorrectVSwitchStatus VSwitch Creation simultaneously is not supported. You cannot create VSwitches because the VPC includes VSwitches in the Creating status.
400 Forbidden.VpcNotFound Specified VPC can not found. The specified VPC does not exist.

See common error codes