|
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 <http://opensource.org/licenses/MIT>. |
|
9
|
|
|
// |
|
10
|
|
|
// --------------------------------------------------------------------- |
|
11
|
|
|
|
|
12
|
|
|
namespace Linode\Internal\Linode; |
|
13
|
|
|
|
|
14
|
|
|
use Linode\Entity\Entity; |
|
15
|
|
|
use Linode\Entity\Linode\Disk; |
|
16
|
|
|
use Linode\Internal\AbstractRepository; |
|
17
|
|
|
use Linode\LinodeClient; |
|
18
|
|
|
use Linode\Repository\Linode\DiskRepositoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
class DiskRepository extends AbstractRepository implements DiskRepositoryInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @param int $linodeId The ID of the Linode whose Disk to look up |
|
24
|
|
|
*/ |
|
25
|
10 |
|
public function __construct(LinodeClient $client, protected int $linodeId) |
|
26
|
|
|
{ |
|
27
|
10 |
|
parent::__construct($client); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
public function create(array $parameters): Disk |
|
31
|
|
|
{ |
|
32
|
1 |
|
$this->checkParametersSupport($parameters); |
|
33
|
|
|
|
|
34
|
1 |
|
$response = $this->client->api($this->client::REQUEST_POST, $this->getBaseUri(), $parameters); |
|
35
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
36
|
1 |
|
$json = json_decode($contents, true); |
|
37
|
|
|
|
|
38
|
1 |
|
return new Disk($this->client, $json); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
1 |
|
public function update(int $id, array $parameters): Disk |
|
42
|
|
|
{ |
|
43
|
1 |
|
$this->checkParametersSupport($parameters); |
|
44
|
|
|
|
|
45
|
1 |
|
$response = $this->client->api($this->client::REQUEST_PUT, sprintf('%s/%s', $this->getBaseUri(), $id), $parameters); |
|
46
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
47
|
1 |
|
$json = json_decode($contents, true); |
|
48
|
|
|
|
|
49
|
1 |
|
return new Disk($this->client, $json); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
public function delete(int $id): void |
|
53
|
|
|
{ |
|
54
|
1 |
|
$this->client->api($this->client::REQUEST_DELETE, sprintf('%s/%s', $this->getBaseUri(), $id)); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
public function clone(int $id): Disk |
|
58
|
|
|
{ |
|
59
|
1 |
|
$response = $this->client->api($this->client::REQUEST_POST, sprintf('%s/%s/clone', $this->getBaseUri(), $id)); |
|
60
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
61
|
1 |
|
$json = json_decode($contents, true); |
|
62
|
|
|
|
|
63
|
1 |
|
return new Disk($this->client, $json); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
public function resize(int $id, int $size): void |
|
67
|
|
|
{ |
|
68
|
1 |
|
$parameters = [ |
|
69
|
1 |
|
'size' => $size, |
|
70
|
1 |
|
]; |
|
71
|
|
|
|
|
72
|
1 |
|
$this->client->api($this->client::REQUEST_POST, sprintf('%s/%s/resize', $this->getBaseUri(), $id), $parameters); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
public function resetPassword(int $id, string $password): void |
|
76
|
|
|
{ |
|
77
|
1 |
|
$parameters = [ |
|
78
|
1 |
|
'password' => $password, |
|
79
|
1 |
|
]; |
|
80
|
|
|
|
|
81
|
1 |
|
$this->client->api($this->client::REQUEST_POST, sprintf('%s/%s/password', $this->getBaseUri(), $id), $parameters); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
7 |
|
protected function getBaseUri(): string |
|
85
|
|
|
{ |
|
86
|
7 |
|
return sprintf('/linode/instances/%s/disks', $this->linodeId); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
3 |
|
protected function getSupportedFields(): array |
|
90
|
|
|
{ |
|
91
|
3 |
|
return [ |
|
92
|
3 |
|
Disk::FIELD_ID, |
|
93
|
3 |
|
Disk::FIELD_LABEL, |
|
94
|
3 |
|
Disk::FIELD_STATUS, |
|
95
|
3 |
|
Disk::FIELD_SIZE, |
|
96
|
3 |
|
Disk::FIELD_FILESYSTEM, |
|
97
|
3 |
|
Disk::FIELD_CREATED, |
|
98
|
3 |
|
Disk::FIELD_UPDATED, |
|
99
|
3 |
|
Disk::FIELD_READ_ONLY, |
|
100
|
3 |
|
Disk::FIELD_IMAGE, |
|
101
|
3 |
|
Disk::FIELD_ROOT_PASS, |
|
102
|
3 |
|
Disk::FIELD_AUTHORIZED_KEYS, |
|
103
|
3 |
|
Disk::FIELD_AUTHORIZED_USERS, |
|
104
|
3 |
|
Disk::FIELD_STACKSCRIPT_ID, |
|
105
|
3 |
|
Disk::FIELD_STACKSCRIPT_DATA, |
|
106
|
3 |
|
]; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
1 |
|
protected function jsonToEntity(array $json): Entity |
|
110
|
|
|
{ |
|
111
|
1 |
|
return new Disk($this->client, $json); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|