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\Disk; |
18
|
|
|
use Linode\LinodeInstances\DiskRepositoryInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
22
|
|
|
*/ |
23
|
|
|
class DiskRepository extends AbstractRepository implements DiskRepositoryInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param int $linodeId ID of the Linode to look up. |
27
|
|
|
*/ |
28
|
|
|
public function __construct(LinodeClient $client, protected int $linodeId) |
29
|
|
|
{ |
30
|
|
|
parent::__construct($client); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function addLinodeDisk(array $parameters = []): Disk |
34
|
|
|
{ |
35
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
36
|
|
|
$contents = $response->getBody()->getContents(); |
37
|
|
|
$json = json_decode($contents, true); |
38
|
|
|
|
39
|
|
|
return new Disk($this->client, $json); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function updateDisk(int $diskId, array $parameters = []): Disk |
43
|
|
|
{ |
44
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $diskId), $parameters); |
45
|
|
|
$contents = $response->getBody()->getContents(); |
46
|
|
|
$json = json_decode($contents, true); |
47
|
|
|
|
48
|
|
|
return new Disk($this->client, $json); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function deleteDisk(int $diskId): void |
52
|
|
|
{ |
53
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $diskId)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function cloneLinodeDisk(int $diskId): Disk |
57
|
|
|
{ |
58
|
|
|
$response = $this->client->post(sprintf('%s/%s/clone', $this->getBaseUri(), $diskId)); |
59
|
|
|
$contents = $response->getBody()->getContents(); |
60
|
|
|
$json = json_decode($contents, true); |
61
|
|
|
|
62
|
|
|
return new Disk($this->client, $json); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function resetDiskPassword(int $diskId, string $password): void |
66
|
|
|
{ |
67
|
|
|
$parameters = [ |
68
|
|
|
'password' => $password, |
69
|
|
|
]; |
70
|
|
|
|
71
|
|
|
$this->client->post(sprintf('%s/%s/password', $this->getBaseUri(), $diskId), $parameters); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function resizeDisk(int $diskId, int $size): void |
75
|
|
|
{ |
76
|
|
|
$parameters = [ |
77
|
|
|
'size' => $size, |
78
|
|
|
]; |
79
|
|
|
|
80
|
|
|
$this->client->post(sprintf('%s/%s/resize', $this->getBaseUri(), $diskId), $parameters); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function getBaseUri(): string |
84
|
|
|
{ |
85
|
|
|
return sprintf('/linode/instances/%s/disks', $this->linodeId); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected function getSupportedFields(): array |
89
|
|
|
{ |
90
|
|
|
return [ |
91
|
|
|
Disk::FIELD_ID, |
92
|
|
|
Disk::FIELD_LABEL, |
93
|
|
|
Disk::FIELD_STATUS, |
94
|
|
|
Disk::FIELD_SIZE, |
95
|
|
|
Disk::FIELD_FILESYSTEM, |
96
|
|
|
Disk::FIELD_CREATED, |
97
|
|
|
Disk::FIELD_UPDATED, |
98
|
|
|
]; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
protected function jsonToEntity(array $json): Entity |
102
|
|
|
{ |
103
|
|
|
return new Disk($this->client, $json); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|