|
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\LinodeInstances\Repository; |
|
13
|
|
|
|
|
14
|
|
|
use Linode\Account\Transfer; |
|
15
|
|
|
use Linode\Entity; |
|
16
|
|
|
use Linode\Internal\AbstractRepository; |
|
17
|
|
|
use Linode\LinodeInstances\Linode; |
|
18
|
|
|
use Linode\LinodeInstances\LinodeRepositoryInterface; |
|
19
|
|
|
use Linode\LinodeInstances\LinodeStats; |
|
20
|
|
|
use Linode\Networking\Firewall; |
|
21
|
|
|
use Linode\NodeBalancers\NodeBalancer; |
|
22
|
|
|
use Linode\Volumes\Volume; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
|
26
|
|
|
*/ |
|
27
|
|
|
class LinodeRepository extends AbstractRepository implements LinodeRepositoryInterface |
|
28
|
|
|
{ |
|
29
|
|
|
public function createLinodeInstance(array $parameters = []): Linode |
|
30
|
|
|
{ |
|
31
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
|
32
|
|
|
$contents = $response->getBody()->getContents(); |
|
33
|
|
|
$json = json_decode($contents, true); |
|
34
|
|
|
|
|
35
|
|
|
return new Linode($this->client, $json); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function updateLinodeInstance(int $linodeId, array $parameters = []): Linode |
|
39
|
|
|
{ |
|
40
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $linodeId), $parameters); |
|
41
|
|
|
$contents = $response->getBody()->getContents(); |
|
42
|
|
|
$json = json_decode($contents, true); |
|
43
|
|
|
|
|
44
|
|
|
return new Linode($this->client, $json); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function deleteLinodeInstance(int $linodeId): void |
|
48
|
|
|
{ |
|
49
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $linodeId)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function bootLinodeInstance(int $linodeId, array $parameters = []): void |
|
53
|
|
|
{ |
|
54
|
|
|
$this->client->post(sprintf('%s/%s/boot', $this->getBaseUri(), $linodeId), $parameters); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function cloneLinodeInstance(int $linodeId, array $parameters = []): Linode |
|
58
|
|
|
{ |
|
59
|
|
|
$response = $this->client->post(sprintf('%s/%s/clone', $this->getBaseUri(), $linodeId), $parameters); |
|
60
|
|
|
$contents = $response->getBody()->getContents(); |
|
61
|
|
|
$json = json_decode($contents, true); |
|
62
|
|
|
|
|
63
|
|
|
return new Linode($this->client, $json); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function migrateLinodeInstance(int $linodeId, array $parameters = []): void |
|
67
|
|
|
{ |
|
68
|
|
|
$this->client->post(sprintf('%s/%s/migrate', $this->getBaseUri(), $linodeId), $parameters); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function mutateLinodeInstance(int $linodeId, array $parameters = []): void |
|
72
|
|
|
{ |
|
73
|
|
|
$this->client->post(sprintf('%s/%s/mutate', $this->getBaseUri(), $linodeId), $parameters); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function resetLinodePassword(int $linodeId, array $parameters = []): void |
|
77
|
|
|
{ |
|
78
|
|
|
$this->client->post(sprintf('%s/%s/password', $this->getBaseUri(), $linodeId), $parameters); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function rebootLinodeInstance(int $linodeId, array $parameters = []): void |
|
82
|
|
|
{ |
|
83
|
|
|
$this->client->post(sprintf('%s/%s/reboot', $this->getBaseUri(), $linodeId), $parameters); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function rebuildLinodeInstance(int $linodeId, array $parameters = []): Linode |
|
87
|
|
|
{ |
|
88
|
|
|
$response = $this->client->post(sprintf('%s/%s/rebuild', $this->getBaseUri(), $linodeId), $parameters); |
|
89
|
|
|
$contents = $response->getBody()->getContents(); |
|
90
|
|
|
$json = json_decode($contents, true); |
|
91
|
|
|
|
|
92
|
|
|
return new Linode($this->client, $json); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function rescueLinodeInstance(int $linodeId, array $parameters = []): void |
|
96
|
|
|
{ |
|
97
|
|
|
$this->client->post(sprintf('%s/%s/rescue', $this->getBaseUri(), $linodeId), $parameters); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function resizeLinodeInstance(int $linodeId, array $parameters = []): void |
|
101
|
|
|
{ |
|
102
|
|
|
$this->client->post(sprintf('%s/%s/resize', $this->getBaseUri(), $linodeId), $parameters); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function shutdownLinodeInstance(int $linodeId): void |
|
106
|
|
|
{ |
|
107
|
|
|
$this->client->post(sprintf('%s/%s/shutdown', $this->getBaseUri(), $linodeId)); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getLinodeStats(int $linodeId): LinodeStats |
|
111
|
|
|
{ |
|
112
|
|
|
$response = $this->client->get(sprintf('%s/%s/stats', $this->getBaseUri(), $linodeId)); |
|
113
|
|
|
$contents = $response->getBody()->getContents(); |
|
114
|
|
|
$json = json_decode($contents, true); |
|
115
|
|
|
|
|
116
|
|
|
return new LinodeStats($this->client, $json); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function getLinodeStatsByYearMonth(int $linodeId, int $year, int $month): LinodeStats |
|
120
|
|
|
{ |
|
121
|
|
|
$response = $this->client->get(sprintf('%s/%s/stats/%s/%s', $this->getBaseUri(), $linodeId, $year, $month)); |
|
122
|
|
|
$contents = $response->getBody()->getContents(); |
|
123
|
|
|
$json = json_decode($contents, true); |
|
124
|
|
|
|
|
125
|
|
|
return new LinodeStats($this->client, $json); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function getLinodeTransfer(int $linodeId): Transfer |
|
129
|
|
|
{ |
|
130
|
|
|
$response = $this->client->get(sprintf('%s/%s/transfer', $this->getBaseUri(), $linodeId)); |
|
131
|
|
|
$contents = $response->getBody()->getContents(); |
|
132
|
|
|
$json = json_decode($contents, true); |
|
133
|
|
|
|
|
134
|
|
|
return new Transfer($this->client, $json); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function getLinodeTransferByYearMonth(int $linodeId, int $year, int $month): Transfer |
|
138
|
|
|
{ |
|
139
|
|
|
$response = $this->client->get(sprintf('%s/%s/transfer/%s/%s', $this->getBaseUri(), $linodeId, $year, $month)); |
|
140
|
|
|
$contents = $response->getBody()->getContents(); |
|
141
|
|
|
$json = json_decode($contents, true); |
|
142
|
|
|
|
|
143
|
|
|
return new Transfer($this->client, $json); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function getLinodeFirewalls(int $linodeId): array |
|
147
|
|
|
{ |
|
148
|
|
|
$response = $this->client->get(sprintf('%s/%s/firewalls', $this->getBaseUri(), $linodeId)); |
|
149
|
|
|
$contents = $response->getBody()->getContents(); |
|
150
|
|
|
$json = json_decode($contents, true); |
|
151
|
|
|
|
|
152
|
|
|
return array_map(fn ($data) => new Firewall($this->client, $data), $json['data']); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
public function getLinodeNodeBalancers(int $linodeId): array |
|
156
|
|
|
{ |
|
157
|
|
|
$response = $this->client->get(sprintf('%s/%s/nodebalancers', $this->getBaseUri(), $linodeId)); |
|
158
|
|
|
$contents = $response->getBody()->getContents(); |
|
159
|
|
|
$json = json_decode($contents, true); |
|
160
|
|
|
|
|
161
|
|
|
return array_map(fn ($data) => new NodeBalancer($this->client, $data), $json['data']); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function getLinodeVolumes(int $linodeId): array |
|
165
|
|
|
{ |
|
166
|
|
|
$response = $this->client->get(sprintf('%s/%s/volumes', $this->getBaseUri(), $linodeId)); |
|
167
|
|
|
$contents = $response->getBody()->getContents(); |
|
168
|
|
|
$json = json_decode($contents, true); |
|
169
|
|
|
|
|
170
|
|
|
return array_map(fn ($data) => new Volume($this->client, $data), $json['data']); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
protected function getBaseUri(): string |
|
174
|
|
|
{ |
|
175
|
|
|
return '/linode/instances'; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
protected function getSupportedFields(): array |
|
179
|
|
|
{ |
|
180
|
|
|
return [ |
|
181
|
|
|
Linode::FIELD_ID, |
|
182
|
|
|
Linode::FIELD_LABEL, |
|
183
|
|
|
Linode::FIELD_REGION, |
|
184
|
|
|
Linode::FIELD_TYPE, |
|
185
|
|
|
Linode::FIELD_IMAGE, |
|
186
|
|
|
Linode::FIELD_STATUS, |
|
187
|
|
|
Linode::FIELD_IPV4, |
|
188
|
|
|
Linode::FIELD_IPV6, |
|
189
|
|
|
Linode::FIELD_GROUP, |
|
190
|
|
|
Linode::FIELD_TAGS, |
|
191
|
|
|
Linode::FIELD_HYPERVISOR, |
|
192
|
|
|
Linode::FIELD_WATCHDOG_ENABLED, |
|
193
|
|
|
Linode::FIELD_CREATED, |
|
194
|
|
|
Linode::FIELD_UPDATED, |
|
195
|
|
|
Linode::FIELD_SPECS, |
|
196
|
|
|
Linode::FIELD_ALERTS, |
|
197
|
|
|
Linode::FIELD_BACKUPS, |
|
198
|
|
|
Linode::FIELD_HOST_UUID, |
|
199
|
|
|
Linode::FIELD_HAS_USER_DATA, |
|
200
|
|
|
]; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
protected function jsonToEntity(array $json): Entity |
|
204
|
|
|
{ |
|
205
|
|
|
return new Linode($this->client, $json); |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
|