Subnets

Create subnet

Show auth code
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => [
        'id'       => '{userId}',
        'password' => '{password}'
    ],
    'scope' => ['project' => ['id' => '{projectId}']]
]);
$networking = $openstack->networkingV2();

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

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

To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.

To create a subnet with gateway IP:

Show auth code
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => [
        'id'       => '{userId}',
        'password' => '{password}'
    ],
    'scope' => [
        'project' => [
            'id' => '{projectId}'
        ]
    ]
]);
$networking = $openstack->networkingV2();

$options = [
    'name'      => 'My subnet',
    'networkId' => '{networkId}',
    'ipVersion' => 4,
    'cidr'      => '192.168.199.0/25',
    'gatewayIp' => '192.168.199.128'
];

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

To create a subnet with host routes:

Show auth code
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => [
        'id'       => '{userId}',
        'password' => '{password}'
    ],
    'scope' => [
        'project' => [
            'id' => '{projectId}'
        ]
    ]
]);
$networking = $openstack->networkingV2();

$options = [
    'name'       => 'My subnet',
    'networkId'  => '{networkId}',
    'ipVersion'  => 4,
    'cidr'       => '192.168.199.0/24',
    'hostRoutes' => [[
        'destination' => '1.1.1.0/24',
        'nexthop'     => '192.168.19.20'
    ]]
];

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

Get subnet

Show auth code
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => [
        'id'       => '{userId}',
        'password' => '{password}'
    ],
    'scope' => [
        'project' => [
            'id' => '{projectId}'
        ]
    ]
]);
$networking = $openstack->networkingV2();

$subnet = $networking->getSubnet('{subnetId}');

// By default, this will return an empty Subnet object and NOT hit the API.
// This is convenient for when you want to use the object for operations
// that do not require an initial GET request. To retrieve the subnet's details,
// run the following, which *will* call the API with a GET request:

$subnet->retrieve();

To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.

Update subnet

Show auth code
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => [
        'id'       => '{userId}',
        'password' => '{password}'
    ],
    'scope'   => [
        'project' => [
            'id' => '{projectId}'
        ]
    ]
]);
$networking = $openstack->networkingV2();

$subnet = $networking->getSubnet('{subnetId}');

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

To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.

Delete subnet

Show auth code
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => [
        'id'       => '{userId}',
        'password' => '{password}'
    ],
    'scope' => [
        'project' => [
            'id' => '{projectId}'
        ]
    ]
]);
$networking = $openstack->networkingV2();

$subnet = $networking->getSubnet('{subnetId}');

$subnet->delete();

To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.