Subnets

A block of IP addresses and associated configuration state. This is also known as the native IPAM (IP Address Management) provided by the networking service for both project and provider networks. Subnets are used to allocate IP addresses when new ports are created on a network.

More information can be found in the official documentation.

In order to work with subnets you have to create the service first.

Create

$networking = $openstack->networkingV2();

$options = [
    'name'      => '{subnetName}',
    'networkId' => '{networkId}',
    'ipVersion' => 4,
    'cidr'      => '192.168.199.0/24'
];

// Create the subnet
$subnet = $networking->createSubnet($options);

With gateway IP

$service = $openstack->networkingV2();

$subnet = $service->createSubnet([
    'name'      => '{subnetName}',
    'networkId' => '{networkId}',
    'ipVersion' => 4,
    'cidr'      => '192.168.199.0/25',
    'gatewayIp' => '192.168.199.128',
]);

With host routes

$service = $openstack->networkingV2();

$subnet = $service->createSubnet([
    'name'       => '{subnetName}',
    'networkId'  => '{networkId}',
    'ipVersion'  => 4,
    'cidr'       => '192.168.199.0/24',
    'hostRoutes' => [[
        'destination' => '1.1.1.0/24',
        'nexthop'     => '192.168.19.20'
    ]]
]);

Read

$service = $openstack->networkingV2();
$subnet = $service->getSubnet('{subnetId}');

$subnet->retrieve();

Update

$service = $openstack->networkingV2();
$subnet = $service->getSubnet('{subnetId}');

$subnet->name = '{newName}';
$subnet->update();

Delete

$service = $openstack->networkingV2();
$subnet = $service->getSubnet('{subnetId}');

$subnet->delete();