Skip to content

Commit 300958b

Browse files
committed
Compute v2 QuotaSet api
1 parent ee95afe commit 300958b

File tree

5 files changed

+268
-12
lines changed

5 files changed

+268
-12
lines changed

src/Compute/v2/Api.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,4 +668,52 @@ public function getHypervisor(): array
668668
'params' => ['id' => $this->params->urlId('hypervisor')]
669669
];
670670
}
671+
672+
public function getQuotaSet()
673+
{
674+
return [
675+
'method' => 'GET',
676+
'path' => 'os-quota-sets/{tenantId}',
677+
'params' => [
678+
'tenantId' => $this->params->urlId('quota-sets')
679+
]
680+
];
681+
}
682+
683+
public function getQuotaSetDetail()
684+
{
685+
return [
686+
'method' => 'GET',
687+
'path' => 'os-quota-sets/{tenantId}/detail',
688+
'jsonKey' => 'quota_set',
689+
'params' => [
690+
'tenantId' => $this->params->urlId('quota-sets')
691+
]
692+
];
693+
}
694+
695+
public function deleteQuotaSet()
696+
{
697+
return [
698+
'method' => 'DELETE',
699+
'path' => 'os-quota-sets/{tenantId}',
700+
'jsonKey' => 'quota_set',
701+
'params' => [
702+
'tenantId' => $this->params->urlId('quota-sets')
703+
]
704+
];
705+
}
706+
707+
public function putQuotaSet()
708+
{
709+
return [
710+
'method' => 'PUT',
711+
'path' => 'os-quota-sets/{tenantId}',
712+
'jsonKey' => 'quota_set',
713+
'params' => [
714+
'tenantId' => $this->params->idPath(),
715+
'instances' => $this->params->quotaSetLimitInstances()
716+
]
717+
];
718+
}
671719
}

src/Compute/v2/Models/QuotaSet.php

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace OpenStack\Compute\v2\Models;
4+
5+
use OpenStack\Common\Resource\Deletable;
6+
use OpenStack\Common\Resource\OperatorResource;
7+
use OpenStack\Common\Resource\Retrievable;
8+
use OpenStack\Common\Resource\Updateable;
9+
10+
/**
11+
* Represents a Compute v2 Quota Set
12+
*
13+
* @property \OpenStack\Compute\v2\Api $api
14+
*/
15+
class QuotaSet extends OperatorResource implements Retrievable, Updateable, Deletable
16+
{
17+
/**
18+
* The number of allowed instance cores for each tenant.
19+
*
20+
* @var int|array
21+
*/
22+
public $cores;
23+
24+
/**
25+
* The number of allowed fixed IP addresses for each tenant.
26+
* Must be equal to or greater than the number of allowed instances.
27+
*
28+
* @deprecated Since 2.35
29+
* @var int|object
30+
*/
31+
public $fixedIps;
32+
33+
/**
34+
* The number of allowed floating IP addresses for each tenant.
35+
*
36+
* @deprecated Since 2.35
37+
* @var int|array
38+
*/
39+
public $floatingIps;
40+
41+
/**
42+
* The UUID of the tenant/user the quotas listed for.
43+
*
44+
* @var string
45+
*/
46+
public $tenantId;
47+
48+
/**
49+
* The number of allowed bytes of content for each injected file.
50+
*
51+
* @var int|array
52+
*/
53+
public $injectedFileContentBytes;
54+
55+
/**
56+
* The number of allowed bytes for each injected file path.
57+
*
58+
* @var int|array
59+
*/
60+
public $injectedFilePathBytes;
61+
62+
/**
63+
* The number of allowed injected files for each tenant.
64+
*
65+
* @var int|array
66+
*/
67+
public $injectedFiles;
68+
69+
/**
70+
* The number of allowed instances for each tenant.
71+
*
72+
* @var int|array
73+
*/
74+
public $instances;
75+
76+
/**
77+
* The number of allowed key pairs for each user.
78+
*
79+
* @var int|array
80+
*/
81+
public $keyPairs;
82+
83+
/**
84+
* The number of allowed metadata items for each instance.
85+
*
86+
* @var int|array
87+
*/
88+
public $metadataItems;
89+
90+
/**
91+
* The amount of allowed instance RAM, in MB, for each tenant.
92+
*
93+
* @var int|array
94+
*/
95+
public $ram;
96+
97+
/**
98+
* The number of allowed rules for each security group.
99+
*
100+
* @deprecated Since 2.35
101+
* @var int|array
102+
*/
103+
public $securityGroupRules;
104+
105+
/**
106+
* The number of allowed security groups for each tenant.
107+
*
108+
* @deprecated Since 2.35
109+
* @var int|array
110+
*/
111+
public $securityGroups;
112+
113+
/**
114+
* The number of allowed server groups for each tenant.
115+
*
116+
* @var int|array
117+
*/
118+
public $serverGroups;
119+
120+
/**
121+
* The number of allowed members for each server group.
122+
*
123+
* @var int|object
124+
*/
125+
public $serverGroupMembers;
126+
127+
protected $resourceKey = 'quota_set';
128+
129+
protected $aliases = [
130+
'id' => 'tenantId',
131+
'fixed_ips' => 'fixedIps',
132+
'floating_ips' => 'floatingIps',
133+
'injected_file_content_bytes' => 'injectedFileContentBytes',
134+
'injected_file_path_bytes' => 'injectedFilePathBytes',
135+
'injected_files' => 'injectedFiles',
136+
'key_pairs' => 'keyPairs',
137+
'metadata_items' => 'metadataItems',
138+
'security_group_rules' => 'securityGroupRules',
139+
'security_groups' => 'securityGroups',
140+
'server_group_members' => 'serverGroupMembers',
141+
'server_groups' => 'serverGroups',
142+
];
143+
144+
/**
145+
* @inheritdoc
146+
*/
147+
public function retrieve()
148+
{
149+
$response = $this->execute($this->api->getQuotaSet(), ['tenantId' => (string)$this->tenantId]);
150+
$this->populateFromResponse($response);
151+
}
152+
153+
/**
154+
* @inheritdoc
155+
*/
156+
public function delete()
157+
{
158+
$response = $this->executeWithState($this->api->putQuotaSet());
159+
$this->populateFromResponse($response);
160+
}
161+
162+
/**
163+
* @inheritdoc
164+
*/
165+
public function update()
166+
{
167+
$response = $this->executeWithState($this->api->putQuotaSet());
168+
$this->populateFromResponse($response);
169+
}
170+
}

src/Compute/v2/Params.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,19 @@ public function consoleType(): array
454454
'required' => true
455455
];
456456
}
457+
458+
protected function quotaSetLimit($sentAs, $description): array
459+
{
460+
return [
461+
'type' => self::INT_TYPE,
462+
'location' => self::JSON,
463+
'sentAs' => $sentAs,
464+
'description' => $description
465+
];
466+
}
467+
468+
public function quotaSetLimitInstances(): array
469+
{
470+
return $this->quotaSetLimit('instances', 'The number of allowed instance cores for each tenant.');
471+
}
457472
}

src/Compute/v2/Service.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use OpenStack\Compute\v2\Models\Image;
99
use OpenStack\Compute\v2\Models\Keypair;
1010
use OpenStack\Compute\v2\Models\Limit;
11+
use OpenStack\Compute\v2\Models\QuotaSet;
1112
use OpenStack\Compute\v2\Models\Server;
1213
use OpenStack\Compute\v2\Models\Hypervisor;
1314

@@ -34,10 +35,10 @@ public function createServer(array $options): Server
3435
/**
3536
* List servers.
3637
*
37-
* @param bool $detailed Determines whether detailed information will be returned. If FALSE is specified, only
38+
* @param bool $detailed Determines whether detailed information will be returned. If FALSE is specified, only
3839
* the ID, name and links attributes are returned, saving bandwidth.
39-
* @param array $options {@see \OpenStack\Compute\v2\Api::getServers}
40-
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
40+
* @param array $options {@see \OpenStack\Compute\v2\Api::getServers}
41+
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
4142
*
4243
* @return \Generator
4344
*/
@@ -69,8 +70,8 @@ public function getServer(array $options = []): Server
6970
/**
7071
* List flavors.
7172
*
72-
* @param array $options {@see \OpenStack\Compute\v2\Api::getFlavors}
73-
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
73+
* @param array $options {@see \OpenStack\Compute\v2\Api::getFlavors}
74+
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
7475
*
7576
* @return \Generator
7677
*/
@@ -111,8 +112,8 @@ public function createFlavor(array $options = []): Flavor
111112
/**
112113
* List images.
113114
*
114-
* @param array $options {@see \OpenStack\Compute\v2\Api::getImages}
115-
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
115+
* @param array $options {@see \OpenStack\Compute\v2\Api::getImages}
116+
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
116117
*
117118
* @return \Generator
118119
*/
@@ -141,8 +142,8 @@ public function getImage(array $options = []): Image
141142
/**
142143
* List key pairs.
143144
*
144-
* @param array $options {@see \OpenStack\Compute\v2\Api::getKeyPairs}
145-
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
145+
* @param array $options {@see \OpenStack\Compute\v2\Api::getKeyPairs}
146+
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
146147
*
147148
* @return \Generator
148149
*/
@@ -204,10 +205,10 @@ public function getHypervisorStatistics(): HypervisorStatistic
204205
/**
205206
* List hypervisors.
206207
*
207-
* @param bool $detailed Determines whether detailed information will be returned. If FALSE is specified, only
208+
* @param bool $detailed Determines whether detailed information will be returned. If FALSE is specified, only
208209
* the ID, name and links attributes are returned, saving bandwidth.
209-
* @param array $options {@see \OpenStack\Compute\v2\Api::getHypervisors}
210-
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
210+
* @param array $options {@see \OpenStack\Compute\v2\Api::getHypervisors}
211+
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
211212
*
212213
* @return \Generator
213214
*/
@@ -229,4 +230,20 @@ public function getHypervisor(array $options = []): Hypervisor
229230
$hypervisor = $this->model(Hypervisor::class);
230231
return $hypervisor->populateFromArray($options);
231232
}
233+
234+
/**
235+
* Shows A Quota for a tenant
236+
*
237+
* @param string $tenantId
238+
* @param bool $detailed
239+
*
240+
* @return QuotaSet
241+
*/
242+
public function getQuotaSet(string $tenantId, bool $detailed = false): QuotaSet
243+
{
244+
$quotaSet = $this->model(QuotaSet::class);
245+
$quotaSet->populateFromResponse($this->execute($detailed ? $this->api->getQuotaSetDetail() : $this->api->getQuotaSet(), ['tenantId' => $tenantId]));
246+
247+
return $quotaSet;
248+
}
232249
}

src/Networking/v2/Service.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ public function listQuotas(): \Generator
178178
/**
179179
* Lists quotas for a project.
180180
*
181+
* Retrieve a quota object without calling the remote API. Any values provided in the array will populate the
182+
* empty object, allowing you greater control without the expense of network transactions. To call the remote API
183+
* and have the response populate the object, call {@see Quota::retrieve}.
184+
*
185+
* @param string $tenantId
186+
*
181187
* @return Quota
182188
*/
183189
public function getQuota(string $tenantId): Quota

0 commit comments

Comments
 (0)