|
1
|
|
|
<?php |
|
2
|
|
|
namespace OpenStack\BlockStorage\v2\Models; |
|
3
|
|
|
|
|
4
|
|
|
use OpenStack\Common\Resource\AbstractResource; |
|
5
|
|
|
use OpenStack\Common\Resource\Creatable; |
|
6
|
|
|
use OpenStack\Common\Resource\Deletable; |
|
7
|
|
|
use OpenStack\Common\Resource\HasMetadata; |
|
8
|
|
|
use OpenStack\Common\Resource\HasWaiterTrait; |
|
9
|
|
|
use OpenStack\Common\Resource\Listable; |
|
10
|
|
|
use OpenStack\Common\Resource\Retrievable; |
|
11
|
|
|
use OpenStack\Common\Resource\Updateable; |
|
12
|
|
|
use OpenStack\Common\Transport\Utils; |
|
13
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @property \OpenStack\BlockStorage\v2\Api $api |
|
17
|
|
|
*/ |
|
18
|
|
|
class Volume extends AbstractResource implements Creatable, Listable, Updateable, Deletable, Retrievable, HasMetadata |
|
19
|
|
|
{ |
|
20
|
|
|
use HasWaiterTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
public $id; |
|
24
|
|
|
|
|
25
|
|
|
/** @var int */ |
|
26
|
|
|
public $size; |
|
27
|
|
|
|
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
public $status; |
|
30
|
|
|
|
|
31
|
|
|
/** @var string */ |
|
32
|
|
|
public $name; |
|
33
|
|
|
|
|
34
|
|
|
/** @var array */ |
|
35
|
|
|
public $attachments; |
|
36
|
|
|
|
|
37
|
|
|
/** @var string */ |
|
38
|
|
|
public $availabilityZone; |
|
39
|
|
|
|
|
40
|
|
|
/** @var \DateTimeImmutable */ |
|
41
|
|
|
public $createdAt; |
|
42
|
|
|
|
|
43
|
|
|
/** @var string */ |
|
44
|
|
|
public $description; |
|
45
|
|
|
|
|
46
|
|
|
/** @var string */ |
|
47
|
|
|
public $volumeTypeName; |
|
48
|
|
|
|
|
49
|
|
|
/** @var string */ |
|
50
|
|
|
public $snapshotId; |
|
51
|
|
|
|
|
52
|
|
|
/** @var string */ |
|
53
|
|
|
public $sourceVolumeId; |
|
54
|
|
|
|
|
55
|
|
|
/** @var array */ |
|
56
|
|
|
public $metadata = []; |
|
57
|
|
|
|
|
58
|
|
|
protected $resourceKey = 'volume'; |
|
59
|
|
|
protected $resourcesKey = 'volumes'; |
|
60
|
|
|
protected $aliases = [ |
|
61
|
|
|
'availability_zone' => 'availabilityZone', |
|
62
|
|
|
'source_volid' => 'sourceVolumeId', |
|
63
|
|
|
'snapshot_id' => 'snapshotId', |
|
64
|
|
|
'created_at' => 'createdAt', |
|
65
|
|
|
'volume_type' => 'volumeTypeName', |
|
66
|
|
|
]; |
|
67
|
|
|
|
|
68
|
3 |
|
public function populateFromResponse(ResponseInterface $response) |
|
69
|
|
|
{ |
|
70
|
3 |
|
parent::populateFromResponse($response); |
|
71
|
3 |
|
$this->metadata = $this->parseMetadata($response); |
|
72
|
3 |
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
public function retrieve() |
|
76
|
|
|
{ |
|
77
|
1 |
|
$response = $this->executeWithState($this->api->getVolume()); |
|
78
|
1 |
|
return $this->populateFromResponse($response); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param array $userOptions {@see \OpenStack\BlockStorage\v2\Api::postVolumes} |
|
83
|
|
|
* |
|
84
|
|
|
* @return self |
|
85
|
|
|
*/ |
|
86
|
1 |
|
public function create(array $userOptions) |
|
87
|
|
|
{ |
|
88
|
1 |
|
$response = $this->execute($this->api->postVolumes(), $userOptions); |
|
89
|
1 |
|
return $this->populateFromResponse($response); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return self |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function update() |
|
96
|
|
|
{ |
|
97
|
1 |
|
$response = $this->executeWithState($this->api->putVolume()); |
|
98
|
1 |
|
return $this->populateFromResponse($response); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
|
public function delete() |
|
102
|
|
|
{ |
|
103
|
1 |
|
$this->executeWithState($this->api->deleteVolume()); |
|
104
|
1 |
|
} |
|
105
|
|
|
|
|
106
|
1 |
|
public function getMetadata() |
|
107
|
|
|
{ |
|
108
|
1 |
|
$response = $this->executeWithState($this->api->getVolumeMetadata()); |
|
109
|
1 |
|
$this->metadata = $this->parseMetadata($response); |
|
|
|
|
|
|
110
|
1 |
|
return $this->metadata; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
1 |
|
public function mergeMetadata(array $metadata) |
|
114
|
|
|
{ |
|
115
|
1 |
|
$this->getMetadata(); |
|
116
|
1 |
|
$this->metadata = array_merge($this->metadata, $metadata); |
|
117
|
1 |
|
$this->executeWithState($this->api->putVolumeMetadata()); |
|
118
|
1 |
|
} |
|
119
|
|
|
|
|
120
|
1 |
|
public function resetMetadata(array $metadata) |
|
121
|
|
|
{ |
|
122
|
1 |
|
$this->metadata = $metadata; |
|
123
|
1 |
|
$this->executeWithState($this->api->putVolumeMetadata()); |
|
124
|
1 |
|
} |
|
125
|
|
|
|
|
126
|
4 |
|
public function parseMetadata(ResponseInterface $response) |
|
127
|
|
|
{ |
|
128
|
4 |
|
$json = Utils::jsonDecode($response); |
|
129
|
4 |
|
return isset($json['metadata']) ? $json['metadata'] : []; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.