1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace OpenStack\Compute\v2\Models; |
4
|
|
|
|
5
|
|
|
use OpenStack\Common\Resource\Creatable; |
6
|
|
|
use OpenStack\Common\Resource\Deletable; |
7
|
|
|
use OpenStack\Common\Resource\HasExtraSpecs; |
8
|
|
|
use OpenStack\Common\Resource\OperatorResource; |
9
|
|
|
use OpenStack\Common\Resource\Listable; |
10
|
|
|
use OpenStack\Common\Resource\Retrievable; |
11
|
|
|
use OpenStack\Common\Transport\Utils; |
12
|
|
|
use Psr\Http\Message\ResponseInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Represents a Compute v2 Flavor. |
16
|
|
|
* |
17
|
|
|
* @property \OpenStack\Compute\v2\Api $api |
18
|
|
|
*/ |
19
|
|
|
class Flavor extends OperatorResource implements Listable, Retrievable, Creatable, Deletable, HasExtraSpecs |
20
|
|
|
{ |
21
|
|
|
/** @var int */ |
22
|
|
|
public $disk; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
public $id; |
26
|
|
|
|
27
|
|
|
/** @var string */ |
28
|
|
|
public $name; |
29
|
|
|
|
30
|
|
|
/** @var int */ |
31
|
|
|
public $ram; |
32
|
|
|
|
33
|
|
|
/** @var int */ |
34
|
|
|
public $swap; |
35
|
|
|
|
36
|
|
|
/** @var int */ |
37
|
|
|
public $vcpus; |
38
|
|
|
|
39
|
|
|
/** @var array */ |
40
|
1 |
|
public $links; |
41
|
|
|
|
42
|
1 |
|
/** @var array */ |
43
|
1 |
|
public $extraSpecs = []; |
44
|
1 |
|
|
45
|
|
|
protected $resourceKey = 'flavor'; |
46
|
|
|
protected $resourcesKey = 'flavors'; |
47
|
|
|
|
48
|
|
|
public function populateFromResponse(ResponseInterface $response): self |
49
|
|
|
{ |
50
|
|
|
parent::populateFromResponse($response); |
51
|
|
|
$this->extraSpecs = $this->parseExtraSpecs($response); |
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritDoc} |
57
|
|
|
*/ |
58
|
|
|
public function retrieve() |
59
|
|
|
{ |
60
|
|
|
$response = $this->execute($this->api->getFlavor(), ['id' => (string)$this->id]); |
61
|
|
|
$this->populateFromResponse($response); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritDoc} |
66
|
|
|
*/ |
67
|
|
|
public function create(array $userOptions): Creatable |
68
|
|
|
{ |
69
|
|
|
$response = $this->execute($this->api->postFlavors(), $userOptions); |
70
|
|
|
return $this->populateFromResponse($response); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritDoc} |
75
|
|
|
*/ |
76
|
|
|
public function delete() |
77
|
|
|
{ |
78
|
|
|
$this->execute($this->api->deleteFlavor(), ['id' => (string)$this->id]); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getExtraSpecs(): array |
82
|
|
|
{ |
83
|
|
|
$response = $this->executeWithState($this->api->getFlavorExtraSpecs()); |
84
|
|
|
$this->extraSpecs = $this->parseExtraSpecs($response); |
85
|
|
|
return $this->extraSpecs; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function mergeExtraSpecs(array $extraSpecs) |
89
|
|
|
{ |
90
|
|
|
$this->execute($this->api->postFlavorExtraSpecs(), ['id' => $this->id, 'extraSpecs' => $extraSpecs]); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function deleteExtraSpec($key) |
94
|
|
|
{ |
95
|
|
|
$this->execute($this->api->deleteFlavorExtraSpecKey(), ['id' => $this->id, 'key' => $key]); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function parseExtraSpecs(ResponseInterface $response): array |
99
|
|
|
{ |
100
|
|
|
$json = Utils::jsonDecode($response); |
101
|
|
|
return isset($json['extra_specs']) ? $json['extra_specs'] : []; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|