|
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\Entity; |
|
15
|
|
|
use Linode\Internal\AbstractRepository; |
|
16
|
|
|
use Linode\LinodeClient; |
|
17
|
|
|
use Linode\LinodeInstances\LinodeConfig; |
|
18
|
|
|
use Linode\LinodeInstances\LinodeConfigInterface; |
|
19
|
|
|
use Linode\LinodeInstances\LinodeConfigRepositoryInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
|
23
|
|
|
*/ |
|
24
|
|
|
class LinodeConfigRepository extends AbstractRepository implements LinodeConfigRepositoryInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @param int $linodeId ID of the Linode to look up Configuration profiles for. |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(LinodeClient $client, protected int $linodeId) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct($client); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function addLinodeConfig(array $parameters = []): LinodeConfig |
|
35
|
|
|
{ |
|
36
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
|
37
|
|
|
$contents = $response->getBody()->getContents(); |
|
38
|
|
|
$json = json_decode($contents, true); |
|
39
|
|
|
|
|
40
|
|
|
return new LinodeConfig($this->client, $json); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function updateLinodeConfig(int $configId, array $parameters = []): LinodeConfig |
|
44
|
|
|
{ |
|
45
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $configId), $parameters); |
|
46
|
|
|
$contents = $response->getBody()->getContents(); |
|
47
|
|
|
$json = json_decode($contents, true); |
|
48
|
|
|
|
|
49
|
|
|
return new LinodeConfig($this->client, $json); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function deleteLinodeConfig(int $configId): void |
|
53
|
|
|
{ |
|
54
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $configId)); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getLinodeConfigInterfaces(int $configId): array |
|
58
|
|
|
{ |
|
59
|
|
|
$response = $this->client->get(sprintf('%s/%s/interfaces', $this->getBaseUri(), $configId)); |
|
60
|
|
|
$contents = $response->getBody()->getContents(); |
|
61
|
|
|
$json = json_decode($contents, true); |
|
62
|
|
|
|
|
63
|
|
|
return array_map(fn ($data) => new LinodeConfigInterface($this->client, $data), $json); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getLinodeConfigInterface(int $configId, int $interfaceId): LinodeConfigInterface |
|
67
|
|
|
{ |
|
68
|
|
|
$response = $this->client->get(sprintf('%s/%s/interfaces/%s', $this->getBaseUri(), $configId, $interfaceId)); |
|
69
|
|
|
$contents = $response->getBody()->getContents(); |
|
70
|
|
|
$json = json_decode($contents, true); |
|
71
|
|
|
|
|
72
|
|
|
return new LinodeConfigInterface($this->client, $json); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function addLinodeConfigInterface(int $configId, array $parameters = []): LinodeConfigInterface |
|
76
|
|
|
{ |
|
77
|
|
|
$response = $this->client->post(sprintf('%s/%s/interfaces', $this->getBaseUri(), $configId), $parameters); |
|
78
|
|
|
$contents = $response->getBody()->getContents(); |
|
79
|
|
|
$json = json_decode($contents, true); |
|
80
|
|
|
|
|
81
|
|
|
return new LinodeConfigInterface($this->client, $json); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function updateLinodeConfigInterface(int $configId, int $interfaceId, array $parameters = []): LinodeConfigInterface |
|
85
|
|
|
{ |
|
86
|
|
|
$response = $this->client->put(sprintf('%s/%s/interfaces/%s', $this->getBaseUri(), $configId, $interfaceId), $parameters); |
|
87
|
|
|
$contents = $response->getBody()->getContents(); |
|
88
|
|
|
$json = json_decode($contents, true); |
|
89
|
|
|
|
|
90
|
|
|
return new LinodeConfigInterface($this->client, $json); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function deleteLinodeConfigInterface(int $configId, int $interfaceId): void |
|
94
|
|
|
{ |
|
95
|
|
|
$this->client->delete(sprintf('%s/%s/interfaces/%s', $this->getBaseUri(), $configId, $interfaceId)); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function orderLinodeConfigInterfaces(int $configId, array $parameters = []): void |
|
99
|
|
|
{ |
|
100
|
|
|
$this->client->post(sprintf('%s/%s/interfaces/order', $this->getBaseUri(), $configId), $parameters); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
protected function getBaseUri(): string |
|
104
|
|
|
{ |
|
105
|
|
|
return sprintf('/linode/instances/%s/configs', $this->linodeId); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
protected function getSupportedFields(): array |
|
109
|
|
|
{ |
|
110
|
|
|
return [ |
|
111
|
|
|
LinodeConfig::FIELD_ID, |
|
112
|
|
|
LinodeConfig::FIELD_LABEL, |
|
113
|
|
|
LinodeConfig::FIELD_KERNEL, |
|
114
|
|
|
LinodeConfig::FIELD_COMMENTS, |
|
115
|
|
|
LinodeConfig::FIELD_MEMORY_LIMIT, |
|
116
|
|
|
LinodeConfig::FIELD_RUN_LEVEL, |
|
117
|
|
|
LinodeConfig::FIELD_VIRT_MODE, |
|
118
|
|
|
LinodeConfig::FIELD_INTERFACES, |
|
119
|
|
|
LinodeConfig::FIELD_HELPERS, |
|
120
|
|
|
LinodeConfig::FIELD_DEVICES, |
|
121
|
|
|
LinodeConfig::FIELD_ROOT_DEVICE, |
|
122
|
|
|
]; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
protected function jsonToEntity(array $json): Entity |
|
126
|
|
|
{ |
|
127
|
|
|
return new LinodeConfig($this->client, $json); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|