Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Stubbing out net IP availability integration
  • Loading branch information
clwells committed Aug 31, 2017
commit 929fead1167271e15cb3607a5962c3417bc20a42
21 changes: 21 additions & 0 deletions src/Networking/v2/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,25 @@ public function deleteLoadBalancerHealthMonitor() : array
]
];
}

public function getNetworkIpAvailability() : array
{
return [
'method' => 'GET',
'path' => $this->pathPrefix . '/network-ip-availability/{id}',
'params' => ['id' => $this->params->idPath()],
];
}

public function getNetworkIpAvailabilities(): array
{
return [
'method' => 'GET',
'path' => $this->pathPrefix . '/network-ip-availabilities',
'params' => [
'tenantId' => $this->params->queryTenantId()
],
];
}

}
62 changes: 62 additions & 0 deletions src/Networking/v2/Models/NetworkIpAvailability.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php declare(strict_types=1);

namespace OpenStack\Networking\v2\Models;

use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\HasWaiterTrait;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\Retrievable;

/**
* Represents a Networking v2 Network.
*
* @property \OpenStack\Networking\v2\Api $api
*/
class NetworkIpAvailability extends OperatorResource implements Listable, Retrievable
{
use HasWaiterTrait;

/** @var string */
public $networkId;

/** @var string */
public $networkName;

/** @var string */
public $tenantId;

/** @var string */
public $projectId;

/** @var int */
public $totalIps;

/** @var int */
public $usedIps;

/** @var array */
public $subnetIpAvailability;

protected $aliases = [
'network_id' => 'networkId',
'network_name' => 'networkName',
'tenant_id' => 'tenantId',
'project_id' => 'projectId',
'total_ips' => 'totalIps',
'used_ips' => 'usedIps',
'subnet_ip_availability' => 'subnetIpAvailability'
];

protected $resourceKey = 'network_ip_availability';
protected $resourcesKey = 'network_ip_availabilities';
protected $markerKey = 'network_id';

/**
* {@inheritDoc}
*/
public function retrieve()
{
$response = $this->execute($this->api->getNetworkIpAvailability(), ['newtork_id' => (string)$this->networkId]);
$this->populateFromResponse($response);
}
}
28 changes: 28 additions & 0 deletions src/Networking/v2/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use OpenStack\Networking\v2\Models\LoadBalancerMember;
use OpenStack\Networking\v2\Models\LoadBalancerPool;
use OpenStack\Networking\v2\Models\Network;
use OpenStack\Networking\v2\Models\NetworkIpAvailability;
use OpenStack\Networking\v2\Models\Pool;
use OpenStack\Networking\v2\Models\Port;
use OpenStack\Networking\v2\Models\Quota;
Expand Down Expand Up @@ -383,4 +384,31 @@ public function createLoadBalancerHealthMonitor(array $options): LoadBalancerHea
{
return $this->model(LoadBalancerHealthMonitor::class)->create($options);
}

/**
* Retrieve a network IP availability object without calling the remote API. Any values provided in the array will populate the
* empty object, allowing you greater control without the expense of network transactions. To call the remote API
* and have the response populate the object, call {@see NetworkIpAvailabilities::retrieve}.
*
* @param string $network_id
*
* @return NetworkIpAvailability
*/
public function getNetworkIpAvailability(string $network_id): NetworkIpAvailability
{
return $this->model(NetworkIpAvailability::class, ['network_id' => $network_id]);
}

/**
* List network IP availability(es)
*
* @param array $options {@see \OpenStack\Networking\v2\Api::getNetworkIpAvailabilities()
*
* @return \Generator
*/
public function listNetworkIpAvailabilities(array $options = []): \Generator
{
return $this->model(NetworkIpAvailability::class)->enumerate($this->api->getNetworkIpAvailabilities(), $options);
}

}