Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| SnapshotService | |
100.00% |
8 / 8 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
| getSnapshots | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getSnapshot | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createSnapshot | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createSnapshotFromURL | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| deleteSnapshot | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Vultr\VultrPhp\Services\Snapshots; |
| 6 | |
| 7 | use Vultr\VultrPhp\Services\VultrService; |
| 8 | use Vultr\VultrPhp\Util\ListOptions; |
| 9 | |
| 10 | /** |
| 11 | * Snapshot service handler, for all snapshots endpoints. |
| 12 | * |
| 13 | * @see https://www.vultr.com/api/#tag/snapshot |
| 14 | */ |
| 15 | class SnapshotService extends VultrService |
| 16 | { |
| 17 | /** |
| 18 | * @param $description - string|null - Filter via description of the snapshots on the account. |
| 19 | * @param $options - ListOptions|null - Interact via reference. |
| 20 | * @throws SnapshotException |
| 21 | * @return Snapshot[] |
| 22 | */ |
| 23 | public function getSnapshots(?string $description = null, ?ListOptions &$options = null) : array |
| 24 | { |
| 25 | $params = []; |
| 26 | if ($description !== null) |
| 27 | { |
| 28 | $params['description'] = $description; |
| 29 | } |
| 30 | |
| 31 | return $this->getListObjects('snapshots', new Snapshot(), $options, $params); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @param $snapshot_id - string - UUID of the snapshot |
| 36 | * @throws SnapshotException |
| 37 | * @throws VultrException |
| 38 | * @return Snapshot |
| 39 | */ |
| 40 | public function getSnapshot(string $snapshot_id) : Snapshot |
| 41 | { |
| 42 | return $this->getObject('snapshots/'.$snapshot_id, new Snapshot()); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param $instance_id - string - UUID of the instance that will have the snapshot taken of. |
| 47 | * @param $description - string - What shall you name your snapshot? |
| 48 | * @throws SnapshotException |
| 49 | * @throws VultrException |
| 50 | * @return Snapshot |
| 51 | */ |
| 52 | public function createSnapshot(string $instance_id, string $description = '') : Snapshot |
| 53 | { |
| 54 | return $this->createObject('snapshots', new Snapshot(), [ |
| 55 | 'instance_id' => $instance_id, |
| 56 | 'description' => $description |
| 57 | ]); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @param $url - string - Full URL of your raw snapshot. Ex https://www.vultr.com/your-amazing-disk-image.raw |
| 62 | * @param $description - string - What shall you name your snapshot? |
| 63 | * @throws SnapshotException |
| 64 | * @return Snapshot |
| 65 | */ |
| 66 | public function createSnapshotFromURL(string $url, string $description = '') : Snapshot |
| 67 | { |
| 68 | return $this->createObject('snapshots/create-from-url', new Snapshot(), [ |
| 69 | 'url' => $url, |
| 70 | 'description' => $description |
| 71 | ]); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @param $snapshot_id - string - UUID of snapshot. |
| 76 | * @throws SnapshotException |
| 77 | * @return void |
| 78 | */ |
| 79 | public function deleteSnapshot(string $snapshot_id) : void |
| 80 | { |
| 81 | $this->deleteObject('snapshots/'.$snapshot_id, new Snapshot()); |
| 82 | } |
| 83 | } |