Skip to content

Commit 36157e7

Browse files
committed
Neutron project quotas api
1 parent b2ffa73 commit 36157e7

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed

src/Networking/v2/Models/Quota.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace OpenStack\Networking\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+
use OpenStack\Networking\v2\Api;
10+
11+
/**
12+
* Represents a Nova v2 Quota
13+
*
14+
* @property Api $api
15+
*/
16+
class Quota extends OperatorResource implements Retrievable, Updateable, Deletable
17+
{
18+
/**
19+
* @var int
20+
*/
21+
public $subnet;
22+
23+
/**
24+
* @var int
25+
*/
26+
public $network;
27+
28+
/**
29+
* @var int
30+
*/
31+
public $floatingip;
32+
33+
/**
34+
* @var string
35+
*/
36+
public $tenantId;
37+
38+
/**
39+
* @var int
40+
*/
41+
public $subnetpool;
42+
43+
44+
/**
45+
* @var int
46+
*/
47+
public $securityGroupRule;
48+
49+
/**
50+
* @var int
51+
*/
52+
public $securityGroup;
53+
54+
/**
55+
* @var int
56+
*/
57+
public $router;
58+
59+
/**
60+
* @var int
61+
*/
62+
public $rbacPolicy;
63+
64+
/**
65+
* @var int
66+
*/
67+
public $port;
68+
69+
protected $resourcesKey = 'quotas';
70+
protected $resourceKey = 'quota';
71+
72+
protected $aliases = [
73+
'tenant_id' => 'tenantId',
74+
'security_group_rule' => 'securityGroupRule',
75+
'security_group' => 'securityGroup',
76+
'rbac_policy' => 'rbacPolicy',
77+
];
78+
79+
/**
80+
* {@inheritDoc}
81+
*/
82+
public function retrieve()
83+
{
84+
$response = $this->execute($this->api->getQuota(), ['tenantId' => (string)$this->tenantId]);
85+
$this->populateFromResponse($response);
86+
}
87+
88+
/**
89+
* {@inheritDoc}
90+
*/
91+
public function update()
92+
{
93+
$response = $this->executeWithState($this->api->putQuota());
94+
$this->populateFromResponse($response);
95+
}
96+
97+
/**
98+
* {@inheritDoc}
99+
*/
100+
public function delete()
101+
{
102+
$this->executeWithState($this->api->deleteQuota());
103+
}
104+
}

src/Networking/v2/Params.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,59 @@ public function routerAccessibleJson(): array
419419
'description' => 'Indicates whether this network is externally accessible.',
420420
];
421421
}
422+
423+
protected function quotaLimit(string $sentAs, string $description): array
424+
{
425+
return [
426+
'type' => self::INT_TYPE,
427+
'location' => self::JSON,
428+
'sentAs' => $sentAs,
429+
'description' => $description
430+
];
431+
}
432+
433+
public function quotaLimitFloatingIp(): array
434+
{
435+
return $this->quotaLimit('floatingip', 'The number of floating IP addresses allowed for each project. A value of -1 means no limit.');
436+
}
437+
438+
public function quotaLimitNetwork(): array
439+
{
440+
return $this->quotaLimit('network', 'The number of networks allowed for each project. A value of -1 means no limit.');
441+
}
442+
443+
public function quotaLimitPort(): array
444+
{
445+
return $this->quotaLimit('port', 'The number of ports allowed for each project. A value of -1 means no limit.');
446+
}
447+
448+
public function quotaLimitRbacPolicy(): array
449+
{
450+
return $this->quotaLimit('rbac_policy', 'The number of role-based access control (RBAC) policies for each project. A value of -1 means no limit.');
451+
}
452+
453+
public function quotaLimitRouter(): array
454+
{
455+
return $this->quotaLimit('router', 'The number of routers allowed for each project. A value of -1 means no limit.');
456+
}
457+
458+
public function quotaLimitSecurityGroup(): array
459+
{
460+
return $this->quotaLimit('security_group', 'The number of security groups allowed for each project. A value of -1 means no limit.');
461+
}
462+
463+
public function quotaLimitSecurityGroupRule(): array
464+
{
465+
return $this->quotaLimit('security_group_rule', 'The number of security group rules allowed for each project. A value of -1 means no limit.');
466+
}
467+
468+
public function quotaLimitSubnet(): array
469+
{
470+
return $this->quotaLimit('subnet', 'The number of subnets allowed for each project. A value of -1 means no limit.');
471+
}
472+
473+
public function quotaLimitSubnetPool(): array
474+
{
475+
return $this->quotaLimit('subnetpool', 'The number of subnet pools allowed for each project. A value of -1 means no limit.');
476+
}
422477
}

src/Networking/v2/Service.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use OpenStack\Common\Service\AbstractService;
66
use OpenStack\Networking\v2\Models\Network;
77
use OpenStack\Networking\v2\Models\Port;
8+
use OpenStack\Networking\v2\Models\Quota;
89
use OpenStack\Networking\v2\Models\Subnet;
910

1011
/**
@@ -163,4 +164,39 @@ public function listPorts(array $options = []): \Generator
163164
{
164165
return $this->model(Port::class)->enumerate($this->api->getPorts(), $options);
165166
}
167+
168+
/**
169+
* Lists quotas for projects with non-default quota values.
170+
*
171+
* @return \Generator
172+
*/
173+
public function listQuotas(): \Generator
174+
{
175+
return $this->model(Quota::class)->enumerate($this->api->getQuotas(), []);
176+
}
177+
178+
/**
179+
* Lists quotas for a project.
180+
*
181+
* @return Quota
182+
*/
183+
public function getQuota(string $tenantId): Quota
184+
{
185+
return $this->model(Quota::class, ['tenantId' => $tenantId]);
186+
}
187+
188+
/**
189+
* Lists default quotas for a project
190+
*
191+
* @param string $tenantId
192+
*
193+
* @return Quota
194+
*/
195+
public function getDefaultQuota(string $tenantId): Quota
196+
{
197+
$quota = $this->model(Quota::class, ['tenantId' => $tenantId]);
198+
$quota->populateFromResponse($this->execute($this->api->getQuotaDefault(), ['tenantId' => $tenantId]));
199+
200+
return $quota;
201+
}
166202
}

0 commit comments

Comments
 (0)