|
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\LoadBalancer; |
|
7
|
|
|
use OpenStack\Networking\v2\Models\LoadBalancerHealthMonitor; |
|
8
|
|
|
use OpenStack\Networking\v2\Models\LoadBalancerListener; |
|
9
|
|
|
use OpenStack\Networking\v2\Models\LoadBalancerMember; |
|
10
|
|
|
use OpenStack\Networking\v2\Models\LoadBalancerPool; |
|
11
|
|
|
use OpenStack\Networking\v2\Models\Network; |
|
12
|
|
|
use OpenStack\Networking\v2\Models\Pool; |
|
13
|
|
|
use OpenStack\Networking\v2\Models\Port; |
|
14
|
|
|
use OpenStack\Networking\v2\Models\Quota; |
|
15
|
|
|
use OpenStack\Networking\v2\Models\Subnet; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Network v2 service for OpenStack. |
|
19
|
|
|
* |
|
20
|
|
|
* @property \OpenStack\Networking\v2\Api $api |
|
21
|
|
|
*/ |
|
22
|
|
|
class Service extends AbstractService |
|
23
|
|
|
{ |
|
24
|
1 |
|
/** |
|
25
|
|
|
* Create a new network resource. |
|
26
|
1 |
|
* |
|
27
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postNetwork} |
|
28
|
|
|
* |
|
29
|
|
|
* @return Network |
|
30
|
|
|
*/ |
|
31
|
|
|
public function createNetwork(array $options): Network |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->model(Network::class)->create($options); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
/** |
|
37
|
|
|
* Create a new network resources. |
|
38
|
1 |
|
* |
|
39
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postNetworks} |
|
40
|
|
|
* |
|
41
|
|
|
* @return array |
|
42
|
|
|
*/ |
|
43
|
|
|
public function createNetworks(array $options): array |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->model(Network::class)->bulkCreate($options); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Retrieve a network object without calling the remote API. Any values provided in the array will populate the |
|
50
|
1 |
|
* empty object, allowing you greater control without the expense of network transactions. To call the remote API |
|
51
|
|
|
* and have the response populate the object, call {@see Network::retrieve}. |
|
52
|
1 |
|
* |
|
53
|
|
|
* @param string $id |
|
54
|
|
|
* |
|
55
|
|
|
* @return Network |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getNetwork(string $id): Network |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->model(Network::class, ['id' => $id]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
/** |
|
63
|
|
|
* List networks. |
|
64
|
1 |
|
* |
|
65
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::getNetworks} |
|
66
|
|
|
* |
|
67
|
|
|
* @return \Generator |
|
68
|
|
|
*/ |
|
69
|
|
|
public function listNetworks(array $options = []): \Generator |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->model(Network::class)->enumerate($this->api->getNetworks(), $options); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
/** |
|
75
|
|
|
* Create a new subnet resource. |
|
76
|
1 |
|
* |
|
77
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postSubnet} |
|
78
|
|
|
* |
|
79
|
|
|
* @return Subnet |
|
80
|
|
|
*/ |
|
81
|
|
|
public function createSubnet(array $options): Subnet |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->model(Subnet::class)->create($options); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
/** |
|
87
|
|
|
* Create a new subnet resources. |
|
88
|
1 |
|
* |
|
89
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postSubnets} |
|
90
|
|
|
* |
|
91
|
|
|
* @return []Subnet |
|
|
|
|
|
|
92
|
|
|
*/ |
|
93
|
|
|
public function createSubnets(array $options): array |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->model(Subnet::class)->bulkCreate($options); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Retrieve a subnet object without calling the remote API. Any values provided in the array will populate the |
|
100
|
1 |
|
* empty object, allowing you greater control without the expense of network transactions. To call the remote API |
|
101
|
|
|
* and have the response populate the object, call {@see Subnet::retrieve}. |
|
102
|
1 |
|
* |
|
103
|
|
|
* @param string $id |
|
104
|
|
|
* |
|
105
|
|
|
* @return Subnet |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getSubnet(string $id): Subnet |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->model(Subnet::class, ['id' => $id]); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
1 |
|
/** |
|
113
|
|
|
* List subnets. |
|
114
|
1 |
|
* |
|
115
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::getSubnets} |
|
116
|
|
|
* |
|
117
|
|
|
* @return \Generator |
|
118
|
|
|
*/ |
|
119
|
|
|
public function listSubnets(array $options = []): \Generator |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->model(Subnet::class)->enumerate($this->api->getSubnets(), $options); |
|
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
1 |
|
/** |
|
125
|
|
|
* Create a new port resource. |
|
126
|
1 |
|
* |
|
127
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postSinglePort} |
|
128
|
|
|
* |
|
129
|
|
|
* @return Port |
|
130
|
|
|
*/ |
|
131
|
|
|
public function createPort(array $options): Port |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->model(Port::class)->create($options); |
|
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
1 |
|
/** |
|
137
|
|
|
* Create new port resources. |
|
138
|
1 |
|
* |
|
139
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postMultiplePorts} |
|
140
|
|
|
* |
|
141
|
|
|
* @return []Port |
|
|
|
|
|
|
142
|
|
|
*/ |
|
143
|
|
|
public function createPorts(array $options): array |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->model(Port::class)->bulkCreate($options); |
|
|
|
|
|
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Retrieve a subnet object without calling the remote API. Any values provided in the array will populate the |
|
150
|
1 |
|
* empty object, allowing you greater control without the expense of network transactions. To call the remote API |
|
151
|
|
|
* and have the response populate the object, call {@see Port::retrieve}. |
|
152
|
1 |
|
* |
|
153
|
|
|
* @param string $id |
|
154
|
|
|
* |
|
155
|
|
|
* @return Port |
|
156
|
|
|
*/ |
|
157
|
|
|
public function getPort(string $id): Port |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->model(Port::class, ['id' => $id]); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
1 |
|
/** |
|
163
|
|
|
* List ports. |
|
164
|
1 |
|
* |
|
165
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::getPorts} |
|
166
|
|
|
* |
|
167
|
|
|
* @return \Generator |
|
168
|
|
|
*/ |
|
169
|
|
|
public function listPorts(array $options = []): \Generator |
|
170
|
|
|
{ |
|
171
|
|
|
return $this->model(Port::class)->enumerate($this->api->getPorts(), $options); |
|
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Lists quotas for projects with non-default quota values. |
|
176
|
|
|
* |
|
177
|
|
|
* @return \Generator |
|
178
|
|
|
*/ |
|
179
|
|
|
public function listQuotas(): \Generator |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->model(Quota::class)->enumerate($this->api->getQuotas(), []); |
|
|
|
|
|
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Lists quotas for a project. |
|
186
|
|
|
* |
|
187
|
|
|
* Retrieve a quota object without calling the remote API. Any values provided in the array will populate the |
|
188
|
|
|
* empty object, allowing you greater control without the expense of network transactions. To call the remote API |
|
189
|
|
|
* and have the response populate the object, call {@see Quota::retrieve}. |
|
190
|
|
|
* |
|
191
|
|
|
* @param string $tenantId |
|
192
|
|
|
* |
|
193
|
|
|
* @return Quota |
|
194
|
|
|
*/ |
|
195
|
|
|
public function getQuota(string $tenantId): Quota |
|
196
|
|
|
{ |
|
197
|
|
|
return $this->model(Quota::class, ['tenantId' => $tenantId]); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Lists default quotas for a project |
|
202
|
|
|
* |
|
203
|
|
|
* @param string $tenantId |
|
204
|
|
|
* |
|
205
|
|
|
* @return Quota |
|
206
|
|
|
*/ |
|
207
|
|
View Code Duplication |
public function getDefaultQuota(string $tenantId): Quota |
|
|
|
|
|
|
208
|
|
|
{ |
|
209
|
|
|
$quota = $this->model(Quota::class, ['tenantId' => $tenantId]); |
|
210
|
|
|
$quota->populateFromResponse($this->execute($this->api->getQuotaDefault(), ['tenantId' => $tenantId])); |
|
211
|
|
|
|
|
212
|
|
|
return $quota; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Lists loadbalancers for projects |
|
217
|
|
|
* |
|
218
|
|
|
* @return \Generator |
|
219
|
|
|
*/ |
|
220
|
|
|
public function listLoadBalancers(): \Generator |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->model(LoadBalancer::class)->enumerate($this->api->getLoadBalancers()); |
|
|
|
|
|
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Retrieve an instance of a LoadBalancer object |
|
227
|
|
|
* |
|
228
|
|
|
* @param string $id |
|
229
|
|
|
* |
|
230
|
|
|
* @return LoadBalancer |
|
231
|
|
|
*/ |
|
232
|
|
|
public function getLoadBalancer(string $id): LoadBalancer |
|
233
|
|
|
{ |
|
234
|
|
|
return $this->model(LoadBalancer::class, ['id' => $id]); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* Create a new loadbalancer resource. |
|
239
|
|
|
* |
|
240
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postLoadBalancer} |
|
241
|
|
|
* |
|
242
|
|
|
* @return LoadBalancer |
|
243
|
|
|
*/ |
|
244
|
|
|
public function createLoadBalancer(array $options): LoadBalancer |
|
245
|
|
|
{ |
|
246
|
|
|
return $this->model(LoadBalancer::class)->create($options); |
|
|
|
|
|
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* Lists loadbalancer listeners |
|
251
|
|
|
* |
|
252
|
|
|
* @return \Generator |
|
253
|
|
|
*/ |
|
254
|
|
|
public function listLoadBalancerListeners(): \Generator |
|
255
|
|
|
{ |
|
256
|
|
|
return $this->model(LoadBalancerListener::class)->enumerate($this->api->getLoadBalancerListeners()); |
|
|
|
|
|
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Retrieve an instance of a loadbalancer listener object |
|
261
|
|
|
* |
|
262
|
|
|
* @param string $id |
|
263
|
|
|
* |
|
264
|
|
|
* @return LoadBalancerListener |
|
265
|
|
|
*/ |
|
266
|
|
|
public function getLoadBalancerListener(string $id): LoadBalancerListener |
|
267
|
|
|
{ |
|
268
|
|
|
return $this->model(LoadBalancerListener::class, ['id' => $id]); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Create a new loadbalancer Listener resource. |
|
273
|
|
|
* |
|
274
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postLoadBalancerListener} |
|
275
|
|
|
* |
|
276
|
|
|
* @return LoadBalancerListener |
|
277
|
|
|
*/ |
|
278
|
|
|
public function createLoadBalancerListener(array $options): LoadBalancerListener |
|
279
|
|
|
{ |
|
280
|
|
|
return $this->model(LoadBalancerListener::class)->create($options); |
|
|
|
|
|
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* Lists loadbalancer pools |
|
285
|
|
|
* |
|
286
|
|
|
* @return \Generator |
|
287
|
|
|
*/ |
|
288
|
|
|
public function listLoadBalancerPools(): \Generator |
|
289
|
|
|
{ |
|
290
|
|
|
return $this->model(LoadBalancerPool::class)->enumerate($this->api->getLoadBalancerPools()); |
|
|
|
|
|
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* Retrieve an instance of a loadbalancer Pool object |
|
295
|
|
|
* |
|
296
|
|
|
* @param string $id |
|
297
|
|
|
* |
|
298
|
|
|
* @return LoadBalancerPool |
|
299
|
|
|
*/ |
|
300
|
|
|
public function getLoadBalancerPool(string $id): LoadBalancerPool |
|
301
|
|
|
{ |
|
302
|
|
|
return $this->model(LoadBalancerPool::class, ['id' => $id]); |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* Create a new loadbalancer Pool resource. |
|
307
|
|
|
* |
|
308
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postLoadBalancerPool} |
|
309
|
|
|
* |
|
310
|
|
|
* @return LoadBalancerPool |
|
311
|
|
|
*/ |
|
312
|
|
|
public function createLoadBalancerPool(array $options): LoadBalancerPool |
|
313
|
|
|
{ |
|
314
|
|
|
return $this->model(LoadBalancerPool::class)->create($options); |
|
|
|
|
|
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* Lists loadbalancer members |
|
319
|
|
|
* |
|
320
|
|
|
* @param string $poolId |
|
321
|
|
|
* @return \Generator |
|
322
|
|
|
*/ |
|
323
|
|
|
public function listLoadBalancerMembers(string $poolId): \Generator |
|
324
|
|
|
{ |
|
325
|
|
|
return $this->model(LoadBalancerPool::class, ['poolId' => $poolId])->enumerate($this->api->getLoadBalancerMembers()); |
|
|
|
|
|
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* Retrieve an instance of a loadbalancer Member object |
|
330
|
|
|
* |
|
331
|
|
|
* @param string $poolId |
|
332
|
|
|
* @param string $memberId |
|
333
|
|
|
* |
|
334
|
|
|
* @return LoadBalancerMember |
|
335
|
|
|
*/ |
|
336
|
|
|
public function getLoadBalancerMember(string $poolId, string $memberId): LoadBalancerMember |
|
337
|
|
|
{ |
|
338
|
|
|
return $this->model(LoadBalancerMember::class, ['poolId' => $poolId, 'id' => $memberId]); |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* Create a new loadbalancer member resource. |
|
343
|
|
|
* |
|
344
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postLoadBalancerMember} |
|
345
|
|
|
* |
|
346
|
|
|
* @return LoadBalancerMember |
|
347
|
|
|
*/ |
|
348
|
|
|
public function createLoadBalancerMember(array $options): LoadBalancerMember |
|
349
|
|
|
{ |
|
350
|
|
|
return $this->model(LoadBalancerMember::class)->create($options); |
|
|
|
|
|
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
/** |
|
354
|
|
|
* Lists loadbalancer healthmonitors |
|
355
|
|
|
* |
|
356
|
|
|
* @return \Generator |
|
357
|
|
|
*/ |
|
358
|
|
|
public function listLoadBalancerHealthMonitors(): \Generator |
|
359
|
|
|
{ |
|
360
|
|
|
return $this->model(LoadBalancerHealthMonitor::class)->enumerate($this->api->getLoadBalancerHealthMonitors()); |
|
|
|
|
|
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* Retrieve an instance of a loadbalancer healthmonitor object |
|
365
|
|
|
* |
|
366
|
|
|
* @param string $id |
|
367
|
|
|
* |
|
368
|
|
|
* @return LoadBalancerHealthMonitor |
|
369
|
|
|
*/ |
|
370
|
|
|
public function getLoadBalancerHealthMonitor(string $id): LoadBalancerHealthMonitor |
|
371
|
|
|
{ |
|
372
|
|
|
return $this->model(LoadBalancerHealthMonitor::class, ['id' => $id]); |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* Create a new loadbalancer healthmonitor resource. |
|
377
|
|
|
* |
|
378
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postLoadBalancerHealthMonitor} |
|
379
|
|
|
* |
|
380
|
|
|
* @return LoadBalancerHealthMonitor |
|
381
|
|
|
*/ |
|
382
|
|
|
public function createLoadBalancerHealthMonitor(array $options): LoadBalancerHealthMonitor |
|
383
|
|
|
{ |
|
384
|
|
|
return $this->model(LoadBalancerHealthMonitor::class)->create($options); |
|
|
|
|
|
|
385
|
|
|
} |
|
386
|
|
|
} |
|
387
|
|
|
|
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: