Skip to content

Commit a1bd463

Browse files
authored
Merge pull request #50 from ukfast/master
Merge in UKFast master
2 parents e3560da + 0030fc7 commit a1bd463

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/eCloud/IpAddressesClient.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,35 @@ public function loadEntity($data)
2424
$this->apiToFriendly($data, $this->getEntityMap())
2525
);
2626
}
27+
28+
public function getNics($id)
29+
{
30+
$page = $this->paginatedRequest(
31+
$this->collectionPath . '/' . $id . '/nics',
32+
$currentPage = 1,
33+
$perPage = 15
34+
);
35+
if ($page->totalItems() == 0) {
36+
return [];
37+
}
38+
$nicClient = new NicClient();
39+
$page->serializeWith(function ($item) use ($nicClient) {
40+
return $nicClient->loadEntity($item);
41+
});
42+
$items = $page->getItems();
43+
if ($page->totalPages() == 1) {
44+
return $items;
45+
}
46+
while ($page->pageNumber() < $page->totalPages()) {
47+
$page = $this->getPage($page->pageNumber() + 1, $perPage);
48+
$page->serializeWith(function ($item) use ($nicClient) {
49+
return $nicClient->loadEntity($item);
50+
});
51+
$items = array_merge(
52+
$items,
53+
$page->getItems()
54+
);
55+
}
56+
return $items;
57+
}
2758
}

src/eCloud/NicClient.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ public function loadEntity($data)
3434
);
3535
}
3636

37+
/**
38+
* Assigns an IP address with a NIC
39+
* @param $id
40+
* @param $ipAddressId
41+
* @return bool
42+
*/
43+
public function assignIpAddress($id, $ipAddressId)
44+
{
45+
$response = $this->post(
46+
$this->collectionPath . '/' . $id . '/ip-addresses',
47+
json_encode([ 'ip_address_id' => $ipAddressId ])
48+
);
49+
return $response->getStatusCode() == 202;
50+
}
51+
52+
/**
53+
* Detaches an IP address from a NIC
54+
* @param $id
55+
* @param $ipAddressId
56+
* @return bool
57+
*/
58+
public function detachIpAddress($id, $ipAddressId)
59+
{
60+
$response = $this->delete($this->collectionPath . '/' . $id . '/ip-addresses/' . $ipAddressId);
61+
return $response->getStatusCode() == 202;
62+
}
63+
3764
/**
3865
* Get the IP address records associated with a NIC
3966
* @param $id
@@ -51,13 +78,22 @@ public function getIpAddresses($id)
5178
return [];
5279
}
5380

81+
$ipAddressClient = new IpAddressesClient();
82+
$page->serializeWith(function ($item) use ($ipAddressClient) {
83+
return $ipAddressClient->loadEntity($item);
84+
});
85+
86+
5487
$items = $page->getItems();
5588
if ($page->totalPages() == 1) {
5689
return $items;
5790
}
5891

5992
while ($page->pageNumber() < $page->totalPages()) {
6093
$page = $this->getPage($page->pageNumber() + 1, $perPage);
94+
$page->serializeWith(function ($item) use ($ipAddressClient) {
95+
return $ipAddressClient->loadEntity($item);
96+
});
6197
$items = array_merge(
6298
$items,
6399
$page->getItems()

0 commit comments

Comments
 (0)