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
|
|
|
/** |
94
|
|
|
* @inheritdoc |
95
|
|
|
*/ |
96
|
|
|
protected static function getAlias(): Alias |
97
|
|
|
{ |
98
|
|
|
$alias = parent::getAlias(); |
99
|
|
|
|
100
|
|
|
if (!$alias->hasAliases(self::class)) { |
101
|
|
|
$alias |
102
|
|
|
->add(self::class, 'tenant_id', 'tenantId') |
103
|
|
|
->add(self::class, 'admin_state_up', 'adminStateUp') |
104
|
|
|
->add(self::class, 'lb_algorithm', 'lbAlgorithm') |
105
|
|
|
->add(self::class, 'session_persistence', 'sessionPersistence') |
106
|
|
|
->add(self::class, 'healthmonitor_id', 'healthmonitorId') |
107
|
|
|
->add(self::class, 'loadbalancer_id', 'loadbalancerId') |
108
|
|
|
->add(self::class, 'operating_status', 'operatingStatus') |
109
|
|
|
->add(self::class, 'provisioning_status', 'provisioningStatus') |
110
|
|
|
->add(self::class, 'listeners', 'listeners', LoadBalancerListener::class, true) |
111
|
|
|
->add(self::class, 'members', 'members', LoadBalancerMember::class, true) |
112
|
|
|
->add(self::class, 'healthmonitors', 'healthmonitors', LoadBalancerHealthMonitor::class, true); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $alias; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritDoc} |
120
|
|
|
*/ |
121
|
|
|
public function create(array $userOptions): Creatable |
122
|
|
|
{ |
123
|
|
|
$response = $this->execute($this->api->postLoadBalancerPool(), $userOptions); |
124
|
|
|
return $this->populateFromResponse($response); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* {@inheritDoc} |
129
|
|
|
*/ |
130
|
|
|
public function retrieve() |
131
|
|
|
{ |
132
|
|
|
$response = $this->execute($this->api->getLoadBalancerPool(), ['id' => (string)$this->id]); |
133
|
|
|
$this->populateFromResponse($response); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* {@inheritDoc} |
138
|
|
|
*/ |
139
|
|
|
public function update() |
140
|
|
|
{ |
141
|
|
|
$response = $this->executeWithState($this->api->putLoadBalancerPool()); |
142
|
|
|
$this->populateFromResponse($response); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* {@inheritDoc} |
147
|
|
|
*/ |
148
|
|
|
public function delete() |
149
|
|
|
{ |
150
|
|
|
$this->executeWithState($this->api->deleteLoadBalancerPool()); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Add a member to this pool |
155
|
|
|
* |
156
|
|
|
* @param array $userOptions |
157
|
|
|
*/ |
158
|
|
|
public function addMember(array $userOptions = []): LoadBalancerMember |
159
|
|
|
{ |
160
|
|
|
$userOptions = array_merge(['poolId' => $this->id], $userOptions); |
161
|
|
|
return $this->model(LoadBalancerMember::class)->create($userOptions); |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Get an instance of a member |
166
|
|
|
* |
167
|
|
|
* @param string $memberId |
168
|
|
|
* @return LoadBalancerMember |
169
|
|
|
*/ |
170
|
|
|
public function getMember(string $memberId): LoadBalancerMember |
171
|
|
|
{ |
172
|
|
|
return $this->model(LoadBalancerMember::class, ['poolId' => $this->id, 'id' => $memberId]); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Delete a member |
177
|
|
|
* |
178
|
|
|
* @param string $memberId |
179
|
|
|
*/ |
180
|
|
|
public function deleteMember(string $memberId) |
181
|
|
|
{ |
182
|
|
|
$this->model(LoadBalancerMember::class, ['poolId' => $this->id, 'id' => $memberId])->delete(); |
|
|
|
|
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Add a healthmonitor to this load balancer pool |
187
|
|
|
* |
188
|
|
|
* @param array $userOptions |
189
|
|
|
* @return LoadBalancerHealthMonitor |
190
|
|
|
*/ |
191
|
|
|
public function addHealthMonitor(array $userOptions = []): LoadBalancerHealthMonitor |
192
|
|
|
{ |
193
|
|
|
$userOptions = array_merge(['poolId' => $this->id], $userOptions); |
194
|
|
|
return $this->model(LoadBalancerHealthMonitor::class)->create($userOptions); |
|
|
|
|
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
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: