-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathFlavor.php
More file actions
103 lines (84 loc) · 2.57 KB
/
Flavor.php
File metadata and controls
103 lines (84 loc) · 2.57 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
<?php declare(strict_types=1);
namespace OpenStack\Compute\v2\Models;
use OpenStack\Common\Resource\Creatable;
use OpenStack\Common\Resource\Deletable;
use OpenStack\Common\Resource\HasExtraSpecs;
use OpenStack\Common\Resource\OperatorResource;
use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\Retrievable;
use OpenStack\Common\Transport\Utils;
use Psr\Http\Message\ResponseInterface;
/**
* Represents a Compute v2 Flavor.
*
* @property \OpenStack\Compute\v2\Api $api
*/
class Flavor extends OperatorResource implements Listable, Retrievable, Creatable, Deletable, HasExtraSpecs
{
/** @var int */
public $disk;
/** @var string */
public $id;
/** @var string */
public $name;
/** @var int */
public $ram;
/** @var int */
public $swap;
/** @var int */
public $vcpus;
/** @var array */
public $links;
/** @var array */
public $extraSpecs = [];
protected $resourceKey = 'flavor';
protected $resourcesKey = 'flavors';
public function populateFromResponse(ResponseInterface $response): self
{
parent::populateFromResponse($response);
$this->extraSpecs = $this->parseExtraSpecs($response);
return $this;
}
/**
* {@inheritDoc}
*/
public function retrieve()
{
$response = $this->execute($this->api->getFlavor(), ['id' => (string)$this->id]);
$this->populateFromResponse($response);
}
/**
* {@inheritDoc}
*/
public function create(array $userOptions): Creatable
{
$response = $this->execute($this->api->postFlavors(), $userOptions);
return $this->populateFromResponse($response);
}
/**
* {@inheritDoc}
*/
public function delete()
{
$this->execute($this->api->deleteFlavor(), ['id' => (string)$this->id]);
}
public function getExtraSpecs(): array
{
$response = $this->executeWithState($this->api->getFlavorExtraSpecs());
$this->extraSpecs = $this->parseExtraSpecs($response);
return $this->extraSpecs;
}
public function mergeExtraSpecs(array $extraSpecs)
{
$this->execute($this->api->postFlavorExtraSpecs(), ['id' => $this->id, 'extraSpecs' => $extraSpecs]);
}
public function deleteExtraSpec($key)
{
$this->execute($this->api->deleteFlavorExtraSpecKey(), ['id' => $this->id, 'key' => $key]);
}
public function parseExtraSpecs(ResponseInterface $response): array
{
$json = Utils::jsonDecode($response);
return isset($json['extra_specs']) ? $json['extra_specs'] : [];
}
}