1 | <?php |
||
21 | class Volume extends AbstractApi |
||
22 | { |
||
23 | /** |
||
24 | * @param string $regionSlug restricts results to volumes available in a specific region |
||
25 | * |
||
26 | * @return VolumeEntity[] Lists all of the Block Storage volumes available |
||
27 | */ |
||
28 | public function getAll($regionSlug = null) |
||
41 | |||
42 | /** |
||
43 | * @param string $driveName restricts results to volumes with the specified name |
||
44 | * @param string $regionSlug restricts results to volumes available in a specific region |
||
45 | * |
||
46 | * @return VolumeEntity[] Lists all of the Block Storage volumes available |
||
47 | */ |
||
48 | public function getByNameAndRegion($driveName, $regionSlug) |
||
60 | |||
61 | /** |
||
62 | * @param string $id |
||
63 | * |
||
64 | * @return VolumeEntity the Block Storage volume with the specified id |
||
65 | */ |
||
66 | public function getById($id) |
||
74 | |||
75 | /** |
||
76 | * Get all volume snapshots. |
||
77 | * |
||
78 | * @param string $id |
||
79 | * |
||
80 | * @return ImageEntity[] |
||
81 | */ |
||
82 | public function getSnapshots($id) |
||
83 | { |
||
84 | $snapshots = $this->adapter->get(sprintf('%s/volumes/%s/snapshots?per_page=%d', $this->endpoint, $id, 200)); |
||
85 | |||
86 | $snapshots = json_decode($snapshots); |
||
87 | |||
88 | $this->meta = $this->extractMeta($snapshots); |
||
89 | |||
90 | return array_map(function ($snapshot) { |
||
91 | $snapshot = new SnapshotEntity($snapshot); |
||
92 | |||
93 | return $snapshot; |
||
94 | }, $snapshots->snapshots); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @param string $name A human-readable name for the Block Storage volume |
||
99 | * @param string $description Free-form text field to describe a Block Storage volume |
||
100 | * @param string $sizeInGigabytes The size of the Block Storage volume in GiB |
||
101 | * @param string $regionSlug The region where the Block Storage volume will be created |
||
102 | * |
||
103 | * @throws HttpException |
||
104 | * |
||
105 | * @return VolumeEntity the Block Storage volume that was created |
||
106 | */ |
||
107 | public function create($name, $description, $sizeInGigabytes, $regionSlug) |
||
122 | |||
123 | /** |
||
124 | * @param string $id |
||
125 | * |
||
126 | * @throws HttpException |
||
127 | */ |
||
128 | public function delete($id) |
||
132 | |||
133 | /** |
||
134 | * @param string $driveName restricts the search to volumes with the specified name |
||
135 | * @param string $regionSlug restricts the search to volumes available in a specific region |
||
136 | * |
||
137 | * @throws HttpException |
||
138 | */ |
||
139 | public function deleteWithNameAndRegion($driveName, $regionSlug) |
||
143 | |||
144 | /** |
||
145 | * @param string $id the id of the volume |
||
146 | * @param int $dropletId the unique identifier for the Droplet the volume will be attached to |
||
147 | * @param string $regionSlug the slug identifier for the region the volume is located in |
||
148 | * |
||
149 | * @return ActionEntity |
||
150 | */ |
||
151 | public function attach($id, $dropletId, $regionSlug) |
||
165 | |||
166 | /** |
||
167 | * @param string $id the id of the volume |
||
168 | * @param int $dropletId the unique identifier for the Droplet the volume will detach from |
||
169 | * @param string $regionSlug the slug identifier for the region the volume is located in |
||
170 | * |
||
171 | * @return ActionEntity |
||
172 | */ |
||
173 | public function detach($id, $dropletId, $regionSlug) |
||
187 | |||
188 | /** |
||
189 | * @param string $id the id of the volume |
||
190 | * @param int $newSize the new size of the Block Storage volume in GiB |
||
191 | * @param string $regionSlug the slug identifier for the region the volume is located in |
||
192 | * |
||
193 | * @return ActionEntity |
||
194 | */ |
||
195 | public function resize($id, $newSize, $regionSlug) |
||
209 | |||
210 | /** |
||
211 | * Create a new snapshot of the volume. |
||
212 | * |
||
213 | * @param string $id the id of the volume |
||
214 | * @param string $name a human-readable name for the volume snapshot |
||
215 | * |
||
216 | * @throws HttpException |
||
217 | * |
||
218 | * @return SnapshotEntity |
||
219 | */ |
||
220 | public function snapshot($id, $name) |
||
221 | { |
||
222 | $data = [ |
||
223 | 'name' => $name, |
||
224 | ]; |
||
225 | |||
226 | $snapshot = $this->adapter->post(sprintf('%s/volumes/%s/snapshots', $this->endpoint, $id), $data); |
||
227 | |||
228 | $snapshot = json_decode($snapshot); |
||
229 | |||
230 | return new SnapshotEntity($snapshot->snapshot); |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * @param string $id |
||
235 | * @param int $actionId |
||
236 | * |
||
237 | * @return ActionEntity |
||
238 | */ |
||
239 | public function getActionById($id, $actionId) |
||
247 | |||
248 | /** |
||
249 | * @param string $id |
||
250 | * |
||
251 | * @return ActionEntity[] |
||
252 | */ |
||
253 | public function getActions($id) |
||
265 | } |
||
266 |