|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenStack\BlockStorage\v2; |
|
4
|
|
|
|
|
5
|
|
|
use OpenStack\BlockStorage\v2\Models\QuotaSet; |
|
6
|
|
|
use OpenStack\BlockStorage\v2\Models\Snapshot; |
|
7
|
|
|
use OpenStack\BlockStorage\v2\Models\Volume; |
|
8
|
|
|
use OpenStack\BlockStorage\v2\Models\VolumeType; |
|
9
|
|
|
use OpenStack\Common\Service\AbstractService; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @property \OpenStack\BlockStorage\v2\Api $api |
|
13
|
|
|
*/ |
|
14
|
|
|
class Service extends AbstractService |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Provisions a new bootable volume, based either on an existing volume, image or snapshot. |
|
18
|
|
|
* You must have enough volume storage quota remaining to create a volume of size requested. |
|
19
|
|
|
* |
|
20
|
|
|
* @param array $userOptions {@see Api::postVolumes} |
|
21
|
|
|
* |
|
22
|
1 |
|
* @return Volume |
|
23
|
|
|
*/ |
|
24
|
1 |
|
public function createVolume(array $userOptions): Volume |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->model(Volume::class)->create($userOptions); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Lists all available volumes. |
|
31
|
|
|
* |
|
32
|
|
|
* @param bool $detail If set to TRUE, more information will be returned. |
|
33
|
|
|
* @param array $userOptions {@see Api::getVolumes} |
|
34
|
|
|
* |
|
35
|
1 |
|
* @return \Generator |
|
36
|
|
|
*/ |
|
37
|
1 |
|
public function listVolumes(bool $detail = false, array $userOptions = []): \Generator |
|
38
|
1 |
|
{ |
|
39
|
|
|
$def = ($detail === true) ? $this->api->getVolumesDetail() : $this->api->getVolumes(); |
|
40
|
|
|
return $this->model(Volume::class)->enumerate($def, $userOptions); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param string $volumeId The UUID of the volume being retrieved. |
|
45
|
|
|
* |
|
46
|
1 |
|
* @return Volume |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function getVolume(string $volumeId): Volume |
|
49
|
1 |
|
{ |
|
50
|
1 |
|
$volume = $this->model(Volume::class); |
|
51
|
|
|
$volume->populateFromArray(['id' => $volumeId]); |
|
52
|
|
|
return $volume; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param array $userOptions {@see Api::postTypes} |
|
57
|
|
|
* |
|
58
|
1 |
|
* @return VolumeType |
|
59
|
|
|
*/ |
|
60
|
1 |
|
public function createVolumeType(array $userOptions): VolumeType |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->model(VolumeType::class)->create($userOptions); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
1 |
|
* @return \Generator |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function listVolumeTypes(): \Generator |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->model(VolumeType::class)->enumerate($this->api->getTypes(), []); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $typeId |
|
75
|
|
|
* |
|
76
|
1 |
|
* @return VolumeType |
|
77
|
|
|
*/ |
|
78
|
1 |
|
public function getVolumeType(string $typeId): VolumeType |
|
79
|
1 |
|
{ |
|
80
|
1 |
|
$type = $this->model(VolumeType::class); |
|
81
|
|
|
$type->populateFromArray(['id' => $typeId]); |
|
82
|
|
|
return $type; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param array $userOptions {@see Api::postSnapshots} |
|
87
|
|
|
* |
|
88
|
1 |
|
* @return Snapshot |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function createSnapshot(array $userOptions): Snapshot |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->model(Snapshot::class)->create($userOptions); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
1 |
|
* @return \Generator |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function listSnapshots(bool $detail = false, array $userOptions = []): \Generator |
|
99
|
1 |
|
{ |
|
100
|
|
|
$def = ($detail === true) ? $this->api->getSnapshotsDetail() : $this->api->getSnapshots(); |
|
101
|
|
|
return $this->model(Snapshot::class)->enumerate($def, $userOptions); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param string $snapshotId |
|
106
|
|
|
* |
|
107
|
1 |
|
* @return Snapshot |
|
108
|
|
|
*/ |
|
109
|
1 |
|
public function getSnapshot(string $snapshotId): Snapshot |
|
110
|
1 |
|
{ |
|
111
|
1 |
|
$snapshot = $this->model(Snapshot::class); |
|
112
|
|
|
$snapshot->populateFromArray(['id' => $snapshotId]); |
|
113
|
|
|
return $snapshot; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Shows A Quota for a tenant |
|
118
|
|
|
* |
|
119
|
|
|
* @param string $tenantId |
|
120
|
|
|
* |
|
121
|
|
|
* @return QuotaSet |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getQuotaSet(string $tenantId): QuotaSet |
|
124
|
|
|
{ |
|
125
|
|
|
$quotaSet = $this->model(QuotaSet::class); |
|
126
|
|
|
$quotaSet->populateFromResponse($this->execute($this->api->getQuotaSet(), ['tenantId' => $tenantId])); |
|
127
|
|
|
|
|
128
|
|
|
return $quotaSet; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: