1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace OpenStack\Networking\v2\Models; |
4
|
|
|
|
5
|
|
|
use OpenStack\Common\Resource\Creatable; |
6
|
|
|
use OpenStack\Common\Resource\Deletable; |
7
|
|
|
use OpenStack\Common\Resource\OperatorResource; |
8
|
|
|
use OpenStack\Common\Resource\Retrievable; |
9
|
|
|
use OpenStack\Common\Resource\Updateable; |
10
|
|
|
use OpenStack\Networking\v2\Api; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Represents a Neutron v2 Loadbalancer |
14
|
|
|
* |
15
|
|
|
* @property Api $api |
16
|
|
|
*/ |
17
|
|
|
class Loadbalancer extends OperatorResource implements Creatable, Retrievable, Updateable, Deletable |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
public $name; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
public $description; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var boolean |
31
|
|
|
*/ |
32
|
|
|
public $adminStateUp; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
public $tenantId; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var []LoadbalancerListener |
41
|
|
|
*/ |
42
|
|
|
public $listeners; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
public $vipAddress; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
public $vipSubnetId; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
public $id; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
public $operatingStatus; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var string |
66
|
|
|
*/ |
67
|
|
|
public $provisioningStatus; |
68
|
|
|
|
69
|
|
|
protected $resourcesKey = 'loadbalancers'; |
70
|
|
|
protected $resourceKey = 'loadbalancer'; |
71
|
|
|
|
72
|
|
|
protected $aliases = [ |
73
|
|
|
'tenant_id' => 'tenantId', |
74
|
|
|
'admin_state_up' => 'adminStateUp', |
75
|
|
|
'vip_address' => 'vipAddress', |
76
|
|
|
'vip_subnet_id' => 'vipSubnetId', |
77
|
|
|
'operating_status' => 'operatingStatus', |
78
|
|
|
'provisioning_status' => 'provisioningStatus' |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritDoc} |
83
|
|
|
*/ |
84
|
|
|
public function create(array $userOptions): Creatable |
85
|
|
|
{ |
86
|
|
|
$response = $this->execute($this->api->postLoadbalancer(), $userOptions); |
87
|
|
|
return $this->populateFromResponse($response); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritDoc} |
92
|
|
|
*/ |
93
|
|
|
public function retrieve() |
94
|
|
|
{ |
95
|
|
|
$response = $this->execute($this->api->getLoadbalancer(), ['id' => (string)$this->id]); |
96
|
|
|
$this->populateFromResponse($response); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritDoc} |
101
|
|
|
*/ |
102
|
|
|
public function update() |
103
|
|
|
{ |
104
|
|
|
$response = $this->executeWithState($this->api->putLoadbalancer()); |
105
|
|
|
$this->populateFromResponse($response); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritDoc} |
110
|
|
|
*/ |
111
|
|
|
public function delete() |
112
|
|
|
{ |
113
|
|
|
$this->executeWithState($this->api->deleteLoadBalancer()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Add a listener to this load balancer |
118
|
|
|
* |
119
|
|
|
* @param array $userOptions |
120
|
|
|
* @return LoadbalancerListener |
121
|
|
|
*/ |
122
|
|
|
public function addListener(array $userOptions = []): LoadbalancerListener |
123
|
|
|
{ |
124
|
|
|
$userOptions = array_merge(['loadbalancerId' => $this->id], $userOptions); |
125
|
|
|
return $this->model(LoadbalancerListener::class)->create($userOptions); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get stats for this loadbalancer |
130
|
|
|
* |
131
|
|
|
* @return LoadbalancerStat |
132
|
|
|
*/ |
133
|
|
|
public function getStats(): LoadbalancerStat |
134
|
|
|
{ |
135
|
|
|
$model = $this->model(LoadbalancerStat::class, ['loadbalancerId' => $this->id]); |
136
|
|
|
$model->retrieve(); |
137
|
|
|
return $model; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Get the status tree for this loadbalancer |
142
|
|
|
* |
143
|
|
|
* @return LoadbalancerStatus |
144
|
|
|
*/ |
145
|
|
|
public function getStatuses(): LoadbalancerStatus |
146
|
|
|
{ |
147
|
|
|
$model = $this->model(LoadbalancerStatus::class, ['loadbalancerId' => $this->id]); |
148
|
|
|
$model->retrieve(); |
149
|
|
|
return $model; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
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: