|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// --------------------------------------------------------------------- |
|
4
|
|
|
// |
|
5
|
|
|
// Copyright (C) 2018-2024 Artem Rodygin |
|
6
|
|
|
// |
|
7
|
|
|
// You should have received a copy of the MIT License along with |
|
8
|
|
|
// this file. If not, see <https://opensource.org/licenses/MIT>. |
|
9
|
|
|
// |
|
10
|
|
|
// --------------------------------------------------------------------- |
|
11
|
|
|
|
|
12
|
|
|
namespace Linode\Networking\Repository; |
|
13
|
|
|
|
|
14
|
|
|
use Linode\Entity; |
|
15
|
|
|
use Linode\Internal\AbstractRepository; |
|
16
|
|
|
use Linode\Networking\IPAddress; |
|
17
|
|
|
use Linode\Networking\IPAddressRepositoryInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
|
21
|
|
|
*/ |
|
22
|
|
|
class IPAddressRepository extends AbstractRepository implements IPAddressRepositoryInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public function allocateIP(array $parameters = []): IPAddress |
|
25
|
|
|
{ |
|
26
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
|
27
|
|
|
$contents = $response->getBody()->getContents(); |
|
28
|
|
|
$json = json_decode($contents, true); |
|
29
|
|
|
|
|
30
|
|
|
return new IPAddress($this->client, $json); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function updateIP(string $address, array $parameters = []): IPAddress |
|
34
|
|
|
{ |
|
35
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $address), $parameters); |
|
36
|
|
|
$contents = $response->getBody()->getContents(); |
|
37
|
|
|
$json = json_decode($contents, true); |
|
38
|
|
|
|
|
39
|
|
|
return new IPAddress($this->client, $json); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function assignIPs(array $parameters = []): void |
|
43
|
|
|
{ |
|
44
|
|
|
$this->client->post(sprintf('%s/assign', $this->getBaseUri()), $parameters); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function shareIPs(array $parameters = []): void |
|
48
|
|
|
{ |
|
49
|
|
|
$this->client->post(sprintf('%s/share', $this->getBaseUri()), $parameters); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function assignIPv4s(array $parameters = []): void |
|
53
|
|
|
{ |
|
54
|
|
|
$this->client->post('/networking/ipv4/assign', $parameters); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function shareIPv4s(array $parameters = []): void |
|
58
|
|
|
{ |
|
59
|
|
|
$this->client->post('/networking/ipv4/share', $parameters); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
protected function getBaseUri(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return '/networking/ips'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function getSupportedFields(): array |
|
68
|
|
|
{ |
|
69
|
|
|
return [ |
|
70
|
|
|
IPAddress::FIELD_ADDRESS, |
|
71
|
|
|
IPAddress::FIELD_TYPE, |
|
72
|
|
|
IPAddress::FIELD_PUBLIC, |
|
73
|
|
|
IPAddress::FIELD_RDNS, |
|
74
|
|
|
IPAddress::FIELD_REGION, |
|
75
|
|
|
IPAddress::FIELD_LINODE_ID, |
|
76
|
|
|
IPAddress::FIELD_GATEWAY, |
|
77
|
|
|
IPAddress::FIELD_SUBNET_MASK, |
|
78
|
|
|
IPAddress::FIELD_PREFIX, |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
protected function jsonToEntity(array $json): Entity |
|
83
|
|
|
{ |
|
84
|
|
|
return new IPAddress($this->client, $json); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|