Ports

A port is a connection point for attaching a single device, such as the NIC of a virtual server, to a virtual network. The port also describes the associated network configuration, such as the MAC and IP addresses to be used on that port.

More information can be found in the official documentation.

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

Create

$service = $openstack->networkingV2();

$port = $service->createPort([
    'name'         => '{portName}',
    'networkId'    => '{networkId}',
    'adminStateUp' => true,
]);

Batch

To create multiple ports in a single request, use the following code:

$service = $openstack->networkingV2();

$ports = $service->createPorts([
    [
        'name'         => '{name1}',
        'networkId'    => '{networkId1}',
        'adminStateUp' => true,
    ],
    [
        'name'         => '{name2}',
        'networkId'    => '{networkId2}',
        'adminStateUp' => true,
    ],
]);

Read

$networking = $openstack->networkingV2();
$port = $networking->getPort('{portId}');

$port->retrieve();

Update

$service = $openstack->networkingV2();
$port = $service->getPort('{portId}');

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

Delete

$service = $openstack->networkingV2();
$port = $service->getPort('{portId}');

$port->delete();