-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathService.php
More file actions
115 lines (96 loc) · 3.34 KB
/
Service.php
File metadata and controls
115 lines (96 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
declare(strict_types=1);
namespace OpenStack\BlockStorage\v2;
use OpenStack\BlockStorage\v2\Models\QuotaSet;
use OpenStack\BlockStorage\v2\Models\Snapshot;
use OpenStack\BlockStorage\v2\Models\Volume;
use OpenStack\BlockStorage\v2\Models\VolumeType;
use OpenStack\Common\Service\AbstractService;
/**
* @property Api $api
*/
class Service extends AbstractService
{
/**
* Provisions a new bootable volume, based either on an existing volume, image or snapshot.
* You must have enough volume storage quota remaining to create a volume of size requested.
*
* @param array $userOptions {@see Api::postVolumes}
*/
public function createVolume(array $userOptions): Volume
{
return $this->model(Volume::class)->create($userOptions);
}
/**
* Lists all available volumes.
*
* @param bool $detail if set to TRUE, more information will be returned
* @param array $userOptions {@see Api::getVolumes}
*
* @return \Generator<mixed, \OpenStack\BlockStorage\v2\Models\Volume>
*/
public function listVolumes(bool $detail = false, array $userOptions = []): \Generator
{
$def = (true === $detail) ? $this->api->getVolumesDetail() : $this->api->getVolumes();
return $this->model(Volume::class)->enumerate($def, $userOptions);
}
/**
* @param string $volumeId the UUID of the volume being retrieved
*/
public function getVolume(string $volumeId): Volume
{
$volume = $this->model(Volume::class);
$volume->populateFromArray(['id' => $volumeId]);
return $volume;
}
/**
* @param array $userOptions {@see Api::postTypes}
*/
public function createVolumeType(array $userOptions): VolumeType
{
return $this->model(VolumeType::class)->create($userOptions);
}
/**
* @return \Generator<mixed, \OpenStack\BlockStorage\v2\Models\VolumeType>
*/
public function listVolumeTypes(): \Generator
{
return $this->model(VolumeType::class)->enumerate($this->api->getTypes(), []);
}
public function getVolumeType(string $typeId): VolumeType
{
$type = $this->model(VolumeType::class);
$type->populateFromArray(['id' => $typeId]);
return $type;
}
/**
* @param array $userOptions {@see Api::postSnapshots}
*/
public function createSnapshot(array $userOptions): Snapshot
{
return $this->model(Snapshot::class)->create($userOptions);
}
/**
* @return \Generator<mixed, \OpenStack\BlockStorage\v2\Models\Snapshot>
*/
public function listSnapshots(bool $detail = false, array $userOptions = []): \Generator
{
$def = (true === $detail) ? $this->api->getSnapshotsDetail() : $this->api->getSnapshots();
return $this->model(Snapshot::class)->enumerate($def, $userOptions);
}
public function getSnapshot(string $snapshotId): Snapshot
{
$snapshot = $this->model(Snapshot::class);
$snapshot->populateFromArray(['id' => $snapshotId]);
return $snapshot;
}
/**
* Shows A Quota for a tenant.
*/
public function getQuotaSet(string $tenantId): QuotaSet
{
$quotaSet = $this->model(QuotaSet::class);
$quotaSet->populateFromResponse($this->execute($this->api->getQuotaSet(), ['tenantId' => $tenantId]));
return $quotaSet;
}
}