|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenStack\Networking\v2\Models; |
|
4
|
|
|
|
|
5
|
|
|
use OpenStack\Common\Resource\Alias; |
|
6
|
|
|
use OpenStack\Common\Resource\Creatable; |
|
7
|
|
|
use OpenStack\Common\Resource\Deletable; |
|
8
|
|
|
use OpenStack\Common\Resource\OperatorResource; |
|
9
|
|
|
use OpenStack\Common\Resource\Retrievable; |
|
10
|
|
|
use OpenStack\Common\Resource\Updateable; |
|
11
|
|
|
use OpenStack\Networking\v2\Api; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Represents a Neutron v2 LoadBalancer pool |
|
15
|
|
|
* |
|
16
|
|
|
* @property Api $api |
|
17
|
|
|
*/ |
|
18
|
|
|
class LoadBalancerPool extends OperatorResource implements Creatable, Retrievable, Updateable, Deletable |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
public $name; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $description; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
public $id; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
public $tenantId; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
public $protocol; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
public $lbAlgorithm; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var array |
|
52
|
|
|
*/ |
|
53
|
|
|
public $sessionPersistence; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var boolean |
|
57
|
|
|
*/ |
|
58
|
|
|
public $adminStateUp; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var LoadBalancerListener[] |
|
62
|
|
|
*/ |
|
63
|
|
|
public $listeners; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var LoadBalancerMember[] |
|
67
|
|
|
*/ |
|
68
|
|
|
public $members; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var LoadBalancerHealthMonitor[] |
|
72
|
|
|
*/ |
|
73
|
|
|
public $healthmonitors; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @var string |
|
77
|
|
|
*/ |
|
78
|
|
|
public $healthmonitorId; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @var string |
|
82
|
|
|
*/ |
|
83
|
|
|
public $operatingStatus; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @var string |
|
87
|
|
|
*/ |
|
88
|
|
|
public $provisioningStatus; |
|
89
|
|
|
|
|
90
|
|
|
protected $resourcesKey = 'pools'; |
|
91
|
|
|
protected $resourceKey = 'pool'; |
|
92
|
|
|
|
|
93
|
|
|
protected $aliases = [ |
|
94
|
|
|
'tenant_id' => 'tenantId', |
|
95
|
|
|
'admin_state_up' => 'adminStateUp', |
|
96
|
|
|
'lb_algorithm' => 'lbAlgorithm', |
|
97
|
|
|
'session_persistence' => 'sessionPersistence', |
|
98
|
|
|
'healthmonitor_id' => 'healthmonitorId', |
|
99
|
|
|
'loadbalancer_id' => 'loadbalancerId', |
|
100
|
|
|
'operating_status' => 'operatingStatus', |
|
101
|
|
|
'provisioning_status' => 'provisioningStatus', |
|
102
|
|
|
]; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @inheritdoc |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function getAliases(): array |
|
108
|
|
|
{ |
|
109
|
|
|
return parent::getAliases() + [ |
|
110
|
|
|
'listeners' => new Alias('listeners', LoadBalancerListener::class, true), |
|
111
|
|
|
'members' => new Alias('members', LoadBalancerMember::class, true), |
|
112
|
|
|
'healthmonitors' => new Alias('healthmonitors', LoadBalancerHealthMonitor::class, true) |
|
113
|
|
|
]; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* {@inheritDoc} |
|
118
|
|
|
*/ |
|
119
|
|
|
public function create(array $userOptions): Creatable |
|
120
|
|
|
{ |
|
121
|
|
|
$response = $this->execute($this->api->postLoadBalancerPool(), $userOptions); |
|
122
|
|
|
return $this->populateFromResponse($response); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* {@inheritDoc} |
|
127
|
|
|
*/ |
|
128
|
|
|
public function retrieve() |
|
129
|
|
|
{ |
|
130
|
|
|
$response = $this->execute($this->api->getLoadBalancerPool(), ['id' => (string)$this->id]); |
|
131
|
|
|
$this->populateFromResponse($response); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* {@inheritDoc} |
|
136
|
|
|
*/ |
|
137
|
|
|
public function update() |
|
138
|
|
|
{ |
|
139
|
|
|
$response = $this->executeWithState($this->api->putLoadBalancerPool()); |
|
140
|
|
|
$this->populateFromResponse($response); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* {@inheritDoc} |
|
145
|
|
|
*/ |
|
146
|
|
|
public function delete() |
|
147
|
|
|
{ |
|
148
|
|
|
$this->executeWithState($this->api->deleteLoadBalancerPool()); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Add a member to this pool |
|
153
|
|
|
* |
|
154
|
|
|
* @param array $userOptions |
|
155
|
|
|
*/ |
|
156
|
|
|
public function addMember(array $userOptions = []): LoadBalancerMember |
|
157
|
|
|
{ |
|
158
|
|
|
$userOptions = array_merge(['poolId' => $this->id], $userOptions); |
|
159
|
|
|
return $this->model(LoadBalancerMember::class)->create($userOptions); |
|
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Get an instance of a member |
|
164
|
|
|
* |
|
165
|
|
|
* @param string $memberId |
|
166
|
|
|
* @return LoadBalancerMember |
|
167
|
|
|
*/ |
|
168
|
|
|
public function getMember(string $memberId): LoadBalancerMember |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->model(LoadBalancerMember::class, ['poolId' => $this->id, 'id' => $memberId]); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Delete a member |
|
175
|
|
|
* |
|
176
|
|
|
* @param string $memberId |
|
177
|
|
|
*/ |
|
178
|
|
|
public function deleteMember(string $memberId) |
|
179
|
|
|
{ |
|
180
|
|
|
$this->model(LoadBalancerMember::class, ['poolId' => $this->id, 'id' => $memberId])->delete(); |
|
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Add a healthmonitor to this load balancer pool |
|
185
|
|
|
* |
|
186
|
|
|
* @param array $userOptions |
|
187
|
|
|
* @return LoadBalancerHealthMonitor |
|
188
|
|
|
*/ |
|
189
|
|
|
public function addHealthMonitor(array $userOptions = []): LoadBalancerHealthMonitor |
|
190
|
|
|
{ |
|
191
|
|
|
$userOptions = array_merge(['poolId' => $this->id], $userOptions); |
|
192
|
|
|
return $this->model(LoadBalancerHealthMonitor::class)->create($userOptions); |
|
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
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: