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 |
15
|
|
|
* |
16
|
|
|
* @property Api $api |
17
|
|
|
*/ |
18
|
|
|
class LoadBalancer 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 boolean |
32
|
|
|
*/ |
33
|
|
|
public $adminStateUp; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
public $tenantId; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var LoadBalancerListener[] |
42
|
|
|
*/ |
43
|
|
|
public $listeners; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
public $vipAddress; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
public $vipSubnetId; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
public $id; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
public $operatingStatus; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
public $provisioningStatus; |
69
|
|
|
|
70
|
|
|
protected $resourcesKey = 'loadbalancers'; |
71
|
|
|
protected $resourceKey = 'loadbalancer'; |
72
|
|
|
|
73
|
|
|
protected $aliases = [ |
74
|
|
|
'tenant_id' => 'tenantId', |
75
|
|
|
'admin_state_up' => 'adminStateUp', |
76
|
|
|
'vip_address' => 'vipAddress', |
77
|
|
|
'vip_subnet_id' => 'vipSubnetId', |
78
|
|
|
'operating_status' => 'operatingStatus', |
79
|
|
|
'provisioning_status' => 'provisioningStatus', |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @inheritdoc |
84
|
|
|
*/ |
85
|
|
|
protected function getAliases(): array |
86
|
|
|
{ |
87
|
|
|
return parent::getAliases() + [ |
88
|
|
|
'listeners' => new Alias('listeners', LoadBalancerListener::class, true) |
89
|
|
|
]; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritDoc} |
94
|
|
|
*/ |
95
|
|
|
public function create(array $userOptions): Creatable |
96
|
|
|
{ |
97
|
|
|
$response = $this->execute($this->api->postLoadBalancer(), $userOptions); |
98
|
|
|
return $this->populateFromResponse($response); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* {@inheritDoc} |
103
|
|
|
*/ |
104
|
|
|
public function retrieve() |
105
|
|
|
{ |
106
|
|
|
$response = $this->execute($this->api->getLoadBalancer(), ['id' => (string)$this->id]); |
107
|
|
|
$this->populateFromResponse($response); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritDoc} |
112
|
|
|
*/ |
113
|
|
|
public function update() |
114
|
|
|
{ |
115
|
|
|
$response = $this->executeWithState($this->api->putLoadBalancer()); |
116
|
|
|
$this->populateFromResponse($response); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* {@inheritDoc} |
121
|
|
|
*/ |
122
|
|
|
public function delete() |
123
|
|
|
{ |
124
|
|
|
$this->executeWithState($this->api->deleteLoadBalancer()); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Add a listener to this load balancer |
129
|
|
|
* |
130
|
|
|
* @param array $userOptions |
131
|
|
|
* @return LoadBalancerListener |
132
|
|
|
*/ |
133
|
|
|
public function addListener(array $userOptions = []): LoadBalancerListener |
134
|
|
|
{ |
135
|
|
|
$userOptions = array_merge(['loadbalancerId' => $this->id], $userOptions); |
136
|
|
|
return $this->model(LoadBalancerListener::class)->create($userOptions); |
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Get stats for this loadbalancer |
141
|
|
|
* |
142
|
|
|
* @return LoadBalancerStat |
143
|
|
|
*/ |
144
|
|
|
public function getStats(): LoadBalancerStat |
145
|
|
|
{ |
146
|
|
|
$model = $this->model(LoadBalancerStat::class, ['loadbalancerId' => $this->id]); |
147
|
|
|
$model->retrieve(); |
148
|
|
|
return $model; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get the status tree for this loadbalancer |
153
|
|
|
* |
154
|
|
|
* @return LoadBalancerStatus |
155
|
|
|
*/ |
156
|
|
|
public function getStatuses(): LoadBalancerStatus |
157
|
|
|
{ |
158
|
|
|
$model = $this->model(LoadBalancerStatus::class, ['loadbalancerId' => $this->id]); |
159
|
|
|
$model->retrieve(); |
160
|
|
|
return $model; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
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: