|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenStack\Networking\v2; |
|
4
|
|
|
|
|
5
|
|
|
use OpenStack\Common\Service\AbstractService; |
|
6
|
|
|
use OpenStack\Networking\v2\Models\Network; |
|
7
|
|
|
use OpenStack\Networking\v2\Models\Port; |
|
8
|
|
|
use OpenStack\Networking\v2\Models\Quota; |
|
9
|
|
|
use OpenStack\Networking\v2\Models\Subnet; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Network v2 service for OpenStack. |
|
13
|
|
|
* |
|
14
|
|
|
* @property \OpenStack\Networking\v2\Api $api |
|
15
|
|
|
*/ |
|
16
|
|
|
class Service extends AbstractService |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Create a new network resource. |
|
20
|
|
|
* |
|
21
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postNetwork} |
|
22
|
|
|
* |
|
23
|
|
|
* @return Network |
|
24
|
1 |
|
*/ |
|
25
|
|
|
public function createNetwork(array $options): Network |
|
26
|
1 |
|
{ |
|
27
|
|
|
return $this->model(Network::class)->create($options); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Create a new network resources. |
|
32
|
|
|
* |
|
33
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postNetworks} |
|
34
|
|
|
* |
|
35
|
|
|
* @return array |
|
36
|
1 |
|
*/ |
|
37
|
|
|
public function createNetworks(array $options): array |
|
38
|
1 |
|
{ |
|
39
|
|
|
return $this->model(Network::class)->bulkCreate($options); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Retrieve a network object without calling the remote API. Any values provided in the array will populate the |
|
44
|
|
|
* empty object, allowing you greater control without the expense of network transactions. To call the remote API |
|
45
|
|
|
* and have the response populate the object, call {@see Network::retrieve}. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $id |
|
48
|
|
|
* |
|
49
|
|
|
* @return Network |
|
50
|
1 |
|
*/ |
|
51
|
|
|
public function getNetwork(string $id): Network |
|
52
|
1 |
|
{ |
|
53
|
|
|
return $this->model(Network::class, ['id' => $id]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* List networks. |
|
58
|
|
|
* |
|
59
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::getNetworks} |
|
60
|
|
|
* |
|
61
|
|
|
* @return \Generator |
|
62
|
1 |
|
*/ |
|
63
|
|
|
public function listNetworks(array $options = []): \Generator |
|
64
|
1 |
|
{ |
|
65
|
|
|
return $this->model(Network::class)->enumerate($this->api->getNetworks(), $options); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Create a new subnet resource. |
|
70
|
|
|
* |
|
71
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postSubnet} |
|
72
|
|
|
* |
|
73
|
|
|
* @return Subnet |
|
74
|
1 |
|
*/ |
|
75
|
|
|
public function createSubnet(array $options): Subnet |
|
76
|
1 |
|
{ |
|
77
|
|
|
return $this->model(Subnet::class)->create($options); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Create a new subnet resources. |
|
82
|
|
|
* |
|
83
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postSubnets} |
|
84
|
|
|
* |
|
85
|
|
|
* @return []Subnet |
|
|
|
|
|
|
86
|
1 |
|
*/ |
|
87
|
|
|
public function createSubnets(array $options): array |
|
88
|
1 |
|
{ |
|
89
|
|
|
return $this->model(Subnet::class)->bulkCreate($options); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Retrieve a subnet object without calling the remote API. Any values provided in the array will populate the |
|
94
|
|
|
* empty object, allowing you greater control without the expense of network transactions. To call the remote API |
|
95
|
|
|
* and have the response populate the object, call {@see Subnet::retrieve}. |
|
96
|
|
|
* |
|
97
|
|
|
* @param string $id |
|
98
|
|
|
* |
|
99
|
|
|
* @return Subnet |
|
100
|
1 |
|
*/ |
|
101
|
|
|
public function getSubnet(string $id): Subnet |
|
102
|
1 |
|
{ |
|
103
|
|
|
return $this->model(Subnet::class, ['id' => $id]); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* List subnets. |
|
108
|
|
|
* |
|
109
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::getSubnets} |
|
110
|
|
|
* |
|
111
|
|
|
* @return \Generator |
|
112
|
1 |
|
*/ |
|
113
|
|
|
public function listSubnets(array $options = []): \Generator |
|
114
|
1 |
|
{ |
|
115
|
|
|
return $this->model(Subnet::class)->enumerate($this->api->getSubnets(), $options); |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Create a new port resource. |
|
120
|
|
|
* |
|
121
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postSinglePort} |
|
122
|
|
|
* |
|
123
|
|
|
* @return Port |
|
124
|
1 |
|
*/ |
|
125
|
|
|
public function createPort(array $options): Port |
|
126
|
1 |
|
{ |
|
127
|
|
|
return $this->model(Port::class)->create($options); |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Create new port resources. |
|
132
|
|
|
* |
|
133
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postMultiplePorts} |
|
134
|
|
|
* |
|
135
|
|
|
* @return []Port |
|
|
|
|
|
|
136
|
1 |
|
*/ |
|
137
|
|
|
public function createPorts(array $options): array |
|
138
|
1 |
|
{ |
|
139
|
|
|
return $this->model(Port::class)->bulkCreate($options); |
|
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Retrieve a subnet object without calling the remote API. Any values provided in the array will populate the |
|
144
|
|
|
* empty object, allowing you greater control without the expense of network transactions. To call the remote API |
|
145
|
|
|
* and have the response populate the object, call {@see Port::retrieve}. |
|
146
|
|
|
* |
|
147
|
|
|
* @param string $id |
|
148
|
|
|
* |
|
149
|
|
|
* @return Port |
|
150
|
1 |
|
*/ |
|
151
|
|
|
public function getPort(string $id): Port |
|
152
|
1 |
|
{ |
|
153
|
|
|
return $this->model(Port::class, ['id' => $id]); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* List ports. |
|
158
|
|
|
* |
|
159
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::getPorts} |
|
160
|
|
|
* |
|
161
|
|
|
* @return \Generator |
|
162
|
1 |
|
*/ |
|
163
|
|
|
public function listPorts(array $options = []): \Generator |
|
164
|
1 |
|
{ |
|
165
|
|
|
return $this->model(Port::class)->enumerate($this->api->getPorts(), $options); |
|
|
|
|
|
|
166
|
|
|
} |
|
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
|
|
|
* 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
|
|
|
* |
|
187
|
|
|
* @return Quota |
|
188
|
|
|
*/ |
|
189
|
|
|
public function getQuota(string $tenantId): Quota |
|
190
|
|
|
{ |
|
191
|
|
|
return $this->model(Quota::class, ['tenantId' => $tenantId]); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* Lists default quotas for a project |
|
196
|
|
|
* |
|
197
|
|
|
* @param string $tenantId |
|
198
|
|
|
* |
|
199
|
|
|
* @return Quota |
|
200
|
|
|
*/ |
|
201
|
|
|
public function getDefaultQuota(string $tenantId): Quota |
|
202
|
|
|
{ |
|
203
|
|
|
$quota = $this->model(Quota::class, ['tenantId' => $tenantId]); |
|
204
|
|
|
$quota->populateFromResponse($this->execute($this->api->getQuotaDefault(), ['tenantId' => $tenantId])); |
|
205
|
|
|
|
|
206
|
|
|
return $quota; |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: