Skip to content

Commit abfb803

Browse files
author
Paul McNally
committed
get ip addresses assigned to a nic
1 parent d28debc commit abfb803

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/eCloud/Client.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,12 @@ public function vips()
343343
{
344344
return (new VipClient($this->httpClient))->auth($this->token);
345345
}
346+
347+
/**
348+
* @return BaseClient
349+
*/
350+
public function nics()
351+
{
352+
return (new NicClient($this->httpClient))->auth($this->token);
353+
}
346354
}

src/eCloud/Entities/Nic.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
/**
88
* @property string $id
9+
* @property string $name
910
* @property string $ipAddress
1011
* @property string $macAddress
1112
* @property string $instanceId
1213
* @property string $networkId
14+
* @property string $sync
1315
*/
1416
class Nic extends Entity
1517
{

src/eCloud/NicClient.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
44

55
use UKFast\SDK\Entities\ClientEntityInterface;
66
use UKFast\SDK\eCloud\Entities\Nic;
7+
use UKFast\SDK\Traits\PageItems;
78

89
class NicClient extends Client implements ClientEntityInterface
910
{
11+
use PageItems;
12+
13+
protected $collectionPath = 'v2/nics';
14+
1015
public function getEntityMap()
1116
{
1217
return [
1318
'id' => 'id',
14-
'ip_address' => 'ipAddress',
19+
'name' => 'name',
1520
'mac_address' => 'macAddress',
1621
'instance_id' => 'instanceId',
1722
'network_id' => 'networkId',
23+
'ip_address' => 'ipAddress',
24+
'sync' => 'sync',
1825
'created_at' => 'createdAt',
1926
'updated_at' => 'updatedAt',
2027
];
@@ -26,4 +33,36 @@ public function loadEntity($data)
2633
$this->apiToFriendly($data, $this->getEntityMap())
2734
);
2835
}
36+
37+
/**
38+
* Get the IP address records associated with a NIC
39+
* @param $id
40+
* @return array
41+
*/
42+
public function getIpAddresses($id)
43+
{
44+
$page = $this->paginatedRequest(
45+
$this->collectionPath . '/' . $id . '/ip-addresses',
46+
$currentPage = 1,
47+
$perPage = 15
48+
);
49+
50+
if ($page->totalItems() == 0) {
51+
return [];
52+
}
53+
54+
$items = $page->getItems();
55+
if ($page->totalPages() == 1) {
56+
return $items;
57+
}
58+
59+
while ($page->pageNumber() < $page->totalPages()) {
60+
$page = $this->getPage($page->pageNumber() + 1, $perPage);
61+
$items = array_merge(
62+
$items,
63+
$page->getItems()
64+
);
65+
}
66+
return $items;
67+
}
2968
}

0 commit comments

Comments
 (0)