Skip to content

Commit aaa3cab

Browse files
author
Jamie Hannaford
authored
Merge pull request #113 from haphan/project-quotas
[rfr] Project quotas
2 parents 4c0d0e3 + 3305ea9 commit aaa3cab

File tree

14 files changed

+836
-3
lines changed

14 files changed

+836
-3
lines changed

src/Compute/v2/Api.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,4 +668,62 @@ public function getHypervisor(): array
668668
'params' => ['id' => $this->params->urlId('hypervisor')]
669669
];
670670
}
671+
672+
public function getQuotaSet(): array
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(): array
684+
{
685+
$data = $this->getQuotaSet();
686+
$data['path'] += '/detail';
687+
688+
return $data;
689+
}
690+
691+
public function deleteQuotaSet(): array
692+
{
693+
return [
694+
'method' => 'DELETE',
695+
'path' => 'os-quota-sets/{tenantId}',
696+
'jsonKey' => 'quota_set',
697+
'params' => [
698+
'tenantId' => $this->params->urlId('quota-sets')
699+
]
700+
];
701+
}
702+
703+
public function putQuotaSet(): array
704+
{
705+
return [
706+
'method' => 'PUT',
707+
'path' => 'os-quota-sets/{tenantId}',
708+
'jsonKey' => 'quota_set',
709+
'params' => [
710+
'tenantId' => $this->params->idPath(),
711+
'force' => $this->notRequired($this->params->quotaSetLimitForce()),
712+
'instances' => $this->notRequired($this->params->quotaSetLimitInstances()),
713+
'cores' => $this->notRequired($this->params->quotaSetLimitCores()),
714+
'fixedIps' => $this->notRequired($this->params->quotaSetLimitFixedIps()),
715+
'floatingIps' => $this->notRequired($this->params->quotaSetLimitFloatingIps()),
716+
'injectedFileContentBytes' => $this->notRequired($this->params->quotaSetLimitInjectedFileContentBytes()),
717+
'injectedFilePathBytes' => $this->notRequired($this->params->quotaSetLimitInjectedFilePathBytes()),
718+
'injectedFiles' => $this->notRequired($this->params->quotaSetLimitInjectedFiles()),
719+
'keyPairs' => $this->notRequired($this->params->quotaSetLimitKeyPairs()),
720+
'metadataItems' => $this->notRequired($this->params->quotaSetLimitMetadataItems()),
721+
'ram' => $this->notRequired($this->params->quotaSetLimitRam()),
722+
'securityGroupRules' => $this->notRequired($this->params->quotaSetLimitSecurityGroupRules()),
723+
'securityGroups' => $this->notRequired($this->params->quotaSetLimitSecurityGroups()),
724+
'serverGroups' => $this->notRequired($this->params->quotaSetLimitServerGroups()),
725+
'serverGroupMembers' => $this->notRequired($this->params->quotaSetLimitServerGroupMembers()),
726+
]
727+
];
728+
}
671729
}

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 Nova v2.35. This attribute will eventually move to Neutron, it is advised you do not use this.
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 Nova v2.35. This attribute will eventually move to Neutron, it is advised you do not use this.
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 Nova v2.35. This attribute will eventually move to Neutron, it is advised you do not use this.
101+
* @var int|array
102+
*/
103+
public $securityGroupRules;
104+
105+
/**
106+
* The number of allowed security groups for each tenant.
107+
*
108+
* @deprecated Since Nova v2.35. This attribute will eventually move to Neutron, it is advised you do not use this.
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->deleteQuotaSet());
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: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function blockDeviceMapping(): array
253253
'items' => [
254254
'type' => self::OBJECT_TYPE,
255255
'properties' => [
256-
'uuid' => [
256+
'uuid' => [
257257
'type' => self::STRING_TYPE,
258258
'description' => 'The unique ID for the volume which the server is to be booted from.',
259259
],
@@ -393,7 +393,7 @@ public function keypairPublicKey(): array
393393
public function keypairName(): array
394394
{
395395
return [
396-
'location' => self::URL,
396+
'location' => self::URL,
397397
];
398398
}
399399

@@ -449,9 +449,99 @@ public function attachmentId(): array
449449
public function consoleType(): array
450450
{
451451
return [
452-
'type' => self::STRING_TYPE,
452+
'type' => self::STRING_TYPE,
453453
'location' => self::JSON,
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 quotaSetLimitForce(): array
469+
{
470+
return [
471+
'type' => self::BOOLEAN_TYPE,
472+
'location' => self::JSON,
473+
'sentAs' => 'force',
474+
'description' => 'You can force the update even if the quota has already been used and the reserved quota exceeds the new quota'
475+
];
476+
}
477+
478+
public function quotaSetLimitInstances(): array
479+
{
480+
return $this->quotaSetLimit('instances', 'The number of allowed instances for each tenant.');
481+
}
482+
483+
public function quotaSetLimitCores(): array
484+
{
485+
return $this->quotaSetLimit('cores', 'The number of allowed instance cores for each tenant.');
486+
}
487+
488+
public function quotaSetLimitFixedIps(): array
489+
{
490+
return $this->quotaSetLimit('fixed_ips', 'The number of allowed fixed IP addresses for each tenant. Must be equal to or greater than the number of allowed instances.');
491+
}
492+
493+
public function quotaSetLimitFloatingIps(): array
494+
{
495+
return $this->quotaSetLimit('floating_ips', 'The number of allowed floating IP addresses for each tenant.');
496+
}
497+
498+
public function quotaSetLimitInjectedFileContentBytes(): array
499+
{
500+
return $this->quotaSetLimit('injected_file_content_bytes', 'The number of allowed bytes of content for each injected file.');
501+
}
502+
503+
public function quotaSetLimitInjectedFilePathBytes(): array
504+
{
505+
return $this->quotaSetLimit('injected_file_path_bytes', 'The number of allowed bytes for each injected file path.');
506+
}
507+
508+
public function quotaSetLimitInjectedFiles(): array
509+
{
510+
return $this->quotaSetLimit('injected_files', 'The number of allowed injected files for each tenant.');
511+
}
512+
513+
public function quotaSetLimitKeyPairs(): array
514+
{
515+
return $this->quotaSetLimit('key_pairs', 'The number of allowed key pairs for each user.');
516+
}
517+
518+
public function quotaSetLimitMetadataItems(): array
519+
{
520+
return $this->quotaSetLimit('metadata_items', 'The number of allowed metadata items for each instance.');
521+
}
522+
523+
public function quotaSetLimitRam(): array
524+
{
525+
return $this->quotaSetLimit('ram', 'The amount of allowed instance RAM (in MB) for each tenant.');
526+
}
527+
528+
public function quotaSetLimitSecurityGroupRules(): array
529+
{
530+
return $this->quotaSetLimit('security_group_rules', 'The number of allowed rules for each security group.');
531+
}
532+
533+
public function quotaSetLimitSecurityGroups(): array
534+
{
535+
return $this->quotaSetLimit('security_groups', 'The number of allowed security groups for each tenant.');
536+
}
537+
538+
public function quotaSetLimitServerGroups(): array
539+
{
540+
return $this->quotaSetLimit('server_groups', 'The number of allowed server groups for each tenant.');
541+
}
542+
543+
public function quotaSetLimitServerGroupMembers(): array
544+
{
545+
return $this->quotaSetLimit('server_group_members', 'The number of allowed members for each server group.');
546+
}
457547
}

src/Compute/v2/Service.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OpenStack\Compute\v2\Models\Limit;
1111
use OpenStack\Compute\v2\Models\Server;
1212
use OpenStack\Compute\v2\Models\Hypervisor;
13+
use OpenStack\Compute\v2\Models\QuotaSet;
1314

1415
/**
1516
* Compute v2 service for OpenStack.
@@ -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
}

0 commit comments

Comments
 (0)