Create L2 Network Service

L2 Network is required to link resources in the tenant.
You can create the Network, Subnet, and Port resources required to link resources by following these steps.

Create Network

Network provides an L2 network and L2 connectivity between any resources in the tenant.
You can create a new Network with the following API call. See Network for more information on the API.
$ curl -sS \
    -H "Content-Type: application/json" \
    -H "X-Auth-Token: {TOKEN}" \
    -X POST -d @network.json {api_endpoint}/v2.0/networks
  • Sample Request Body (network.json)
{
  "network": {
    "name": "Example network 1",
    "admin_state_up": true,
    "plane": "data"
  }
}
  • Sample Response Body
{
  "network": {
    "admin_state_up": true,
    "description": "",
    "id": "8bd9afc9-6d7f-496f-a2e2-7e50a9340292",
    "name": "Example network 1",
    "plane": "data",
    "shared": false,
    "status": "PENDING_CREATE",
    "subnets": [],
    "tags": {},
    "tenant_id": "6c0bdafab1914ab2b2b6c415477defc7"
  }
}

The id parameter in the Response is the uuid of the newly created Network, and is used as the network_id parameter in the Create Subnet and Create Port.

Show Network

As discussed in Section 1.4, you should verify that the Network was created correctly before running Create Subnet in Section 2.2. Here's how to check.
You can get the Network information specified in the following API call. Use the uuid of Network created earlier and specify it.
See Network for more information on the API.
After executing the API call, verify that the value of status in Response is other than PENDING_XXX .
Check status in the same way from this section onward before running the next section.
$ curl -sS \
    -H "Content-Type: application/json" \
    -H "X-Auth-Token: {TOKEN}" \
    -X GET {api_endpoint}/v2.0/networks/8bd9afc9-6d7f-496f-a2e2-7e50a9340292
  • Sample Response Body
{
  "network": {
    "admin_state_up": true,
    "description": "",
    "id": "8bd9afc9-6d7f-496f-a2e2-7e50a9340292",
    "name": "Example network 1",
    "plane": "data",
    "shared": false,
    "status": "ACTIVE",
    "subnets": [],
    "tags": {},
    "tenant_id": "6c0bdafab1914ab2b2b6c415477defc7"
  }
}

Create Subnet

Subnet provides the ability to manage common settings (Network gateway IP, DNS server, etc.) for resources connecting to Network .
You can create a new Subnet with the following API call. See Subnet for more information on the API.
$ curl -sS \
    -H "Content-Type: application/json" \
    -H "X-Auth-Token: {TOKEN}" \
    -X POST -d @subnet.json {api_endpoint}/v2.0/subnets
  • Sample Request Body (subnet.json)
{
  "subnet": {
    "name": "Example subnet 1",
    "allocation_pools": [
      {
        "end": "192.168.1.254",
        "start": "192.168.1.2"
      }
    ],
    "cidr": "192.168.1.0/24",
    "dns_nameservers": [
      "8.8.8.8"
    ],
    "enable_dhcp": true,
    "gateway_ip": "192.168.1.1",
    "ip_version": 4,
    "network_id": "8661dd5f-e76c-4b23-af2b-2d6f2a1f5ad6"
  }
}
  • Sample Response Body
{
  "subnet": {
    "allocation_pools": [
      {
        "end": "192.168.1.254",
        "start": "192.168.10.2"
      }
    ],
    "cidr": "192.168.1.0/24",
    "description": "",
    "dns_nameservers": [
      "8.8.8.8"
    ],
    "enable_dhcp": true,
    "gateway_ip": "192.168.1.1",
    "host_routes": [],
    "id": "165fb4f5-dabc-4943-8467-3ae548797d93",
    "ip_version": 4,
    "name": "Example subnet 1",
    "network_id": "8bd9afc9-6d7f-496f-a2e2-7e50a9340292",
    "ntp_servers": [],
    "status": "PENDING_CREATE",
    "tags": {},
    "tenant_id": "6c0bdafab1914ab2b2b6c415477defc7"
  }
}

The id parameter in the Response is the uuid of the newly created Subnet and is used as the subnet_id parameter in the Create Port.

Create Port

Port provides the ability to manage the individual settings (IP address, MAC address, etc.) of the resources to which it is connected.
You can create a new Port with the following API call. See Port for more information on the API.
$ curl -sS \
    -H "Content-Type: application/json" \
    -H "X-Auth-Token: {TOKEN}" \
    -X POST -d @port.json {api_endpoint}/v2.0/ports
  • Sample Request Body (port.json)
{
  "port": {
    "name": "Example port 1",
    "admin_state_up": true,
    "fixed_ips": [
      {
        "subnet_id": "2d654ad9-bcfe-4799-82f3-44b2b093d920"
      }
    ],
    "network_id": "8661dd5f-e76c-4b23-af2b-2d6f2a1f5ad6"
  }
}
  • Sample Response Body
{
  "port": {
    "admin_state_up": true,
    "allowed_address_pairs": [],
    "description": "",
    "device_id": "",
    "device_owner": "",
    "fixed_ips": [
      {
        "ip_address": "192.168.1.3",
        "subnet_id": "165fb4f5-dabc-4943-8467-3ae548797d93"
      }
    ],
    "id": "e131b837-d9ba-4d35-be04-d4b923747a1b",
    "mac_address": "fa:16:3e:61:6d:4f",
    "name": "Example port 1",
    "network_id": "8bd9afc9-6d7f-496f-a2e2-7e50a9340292",
    "segmentation_id": 0,
    "segmentation_type": "flat",
    "status": "PENDING_CREATE",
    "tags": {},
    "tenant_id": "6c0bdafab1914ab2b2b6c415477defc7"
  }
}