1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Vultr PHP library. |
4
|
|
|
* |
5
|
|
|
* (c) Albert Leitato <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace Vultr\Api; |
11
|
|
|
|
12
|
|
|
use Vultr\Entity\ReservedIp as ReservedIpEntity; |
13
|
|
|
use Vultr\Exception\HttpException; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Albert Leitato <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class ReservedIp extends AbstractApi |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* List all the active reserved IPs on this account. |
22
|
|
|
* |
23
|
|
|
* @return ReservedIpEntity[] |
24
|
|
|
*/ |
25
|
|
|
public function list() |
26
|
|
|
{ |
27
|
|
|
$response = $this->adapter->get(\sprintf('%s/reservedip/list', $this->endpoint)); |
28
|
|
|
|
29
|
|
|
$ips = \json_decode($response); |
30
|
|
|
|
31
|
|
|
$this->extractMeta($ips); |
|
|
|
|
32
|
|
|
|
33
|
|
|
return \array_map(function ($ip) { |
34
|
|
|
return new ReservedIpEntity($ip); |
35
|
|
|
}, $ips); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create a new reserved IP. |
40
|
|
|
* |
41
|
|
|
* Reserved IPs can only be used within the same datacenter for which |
42
|
|
|
* they were created. |
43
|
|
|
* |
44
|
|
|
* @param int $dcId |
45
|
|
|
* @param string $ipType |
46
|
|
|
* @param string $label |
47
|
|
|
* |
48
|
|
|
* @throws HttpException |
49
|
|
|
* |
50
|
|
|
* @return FloatingIpEntity |
51
|
|
|
*/ |
52
|
|
|
public function create($dcId, $ipType, $label = null) |
53
|
|
|
{ |
54
|
|
|
$content = [ |
55
|
|
|
'DCID' => $dcId, |
56
|
|
|
'ip_type' => $ipType, |
57
|
|
|
]; |
58
|
|
|
if (null !== $label) { |
59
|
|
|
$content['label'] = $label; |
60
|
|
|
} |
61
|
|
|
$response = $this->adapter->post(\sprintf('%s/reservedip/create', $this->endpoint), $content); |
62
|
|
|
|
63
|
|
|
return \json_decode($response); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Remove a reserved IP from your account. |
68
|
|
|
* |
69
|
|
|
* After making this call, you will not be able to recover the IP address. |
70
|
|
|
* |
71
|
|
|
* @param int $ipAddressipAddress |
72
|
|
|
* |
73
|
|
|
* @throws HttpException |
74
|
|
|
*/ |
75
|
|
|
public function delete($ipAddressipAddress) |
76
|
|
|
{ |
77
|
|
|
$this->adapter->delete(\sprintf('%s/reservedip/destroy', $this->endpoint), ['ip_address' => $ipAddressipAddress]); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Convert an existing IP on a subscription to a reserved IP. |
82
|
|
|
* |
83
|
|
|
* @param int $serverId SUBID of the server that currently has the IP address |
|
|
|
|
84
|
|
|
* @param string $ipAddress IP address you want to convert |
85
|
|
|
* @param string $paramname Label for this reserved IP |
|
|
|
|
86
|
|
|
* |
87
|
|
|
* @throws HttpException |
88
|
|
|
*/ |
89
|
|
|
public function convert($serverIdd, $ipAddress, $label = null) |
90
|
|
|
{ |
91
|
|
|
$content = [ |
92
|
|
|
'SUBID' => $serverIdd, |
93
|
|
|
'ip_address' => $ipAddress, |
94
|
|
|
]; |
95
|
|
|
if (null !== $label) { |
96
|
|
|
$content['label'] = $label; |
97
|
|
|
} |
98
|
|
|
$this->adapter->post(\sprintf('%s/reservedip/conver', $this->endpoint), $content); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Attach a reserved IP to an existing subscription. |
103
|
|
|
* |
104
|
|
|
* @param int $ipAddress Reserved IP to attach to your account |
105
|
|
|
* @param int $serverId Server to attach the reserved IP to |
106
|
|
|
* |
107
|
|
|
* @throws HttpException |
108
|
|
|
* |
109
|
|
|
* @return ActionEntity |
110
|
|
|
*/ |
111
|
|
|
public function attach($ipAddress, $serverId) |
112
|
|
|
{ |
113
|
|
|
return $this->executeAction($ipAddress, $serverId, 'attach'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param int $ipAddress |
118
|
|
|
* @param int $serverId |
119
|
|
|
* |
120
|
|
|
* @throws HttpException |
121
|
|
|
*/ |
122
|
|
|
public function detach($ipAddress, $serverId) |
123
|
|
|
{ |
124
|
|
|
return $this->executeAction($ipAddress, $serverId, 'detach'); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Detach a reserved IP from an existing subscription. |
129
|
|
|
* |
130
|
|
|
* @param string $ipAddress |
131
|
|
|
* @param int $serverId |
132
|
|
|
* @param string $action |
133
|
|
|
* |
134
|
|
|
* @throws HttpException |
135
|
|
|
*/ |
136
|
|
|
private function executeAction($ipAddress, $serverId, $action) |
137
|
|
|
{ |
138
|
|
|
return $this->adapter->post(\sprintf('%s/reservedip/' . $action, $this->endpoint), ['ip_address' => $ipAddress, 'attach_SUBID' => $serverId]); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.