|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenStack\Networking\v2; |
|
4
|
|
|
|
|
5
|
|
|
use OpenStack\Common\Service\AbstractService; |
|
6
|
|
|
use OpenStack\Networking\v2\Models\Network; |
|
7
|
|
|
use OpenStack\Networking\v2\Models\Port; |
|
8
|
|
|
use OpenStack\Networking\v2\Models\Subnet; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Network v2 service for OpenStack. |
|
12
|
|
|
* |
|
13
|
|
|
* @property \OpenStack\Networking\v2\Api $api |
|
14
|
|
|
*/ |
|
15
|
|
|
class Service extends AbstractService |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Create a new network resource. |
|
19
|
|
|
* |
|
20
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postNetwork} |
|
21
|
|
|
* |
|
22
|
|
|
* @return Network |
|
23
|
|
|
*/ |
|
24
|
1 |
|
public function createNetwork(array $options) |
|
25
|
|
|
{ |
|
26
|
1 |
|
return $this->model(Network::class)->create($options); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Create a new network resources. |
|
31
|
|
|
* |
|
32
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postNetworks} |
|
33
|
|
|
* |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
1 |
|
public function createNetworks(array $options) |
|
37
|
|
|
{ |
|
38
|
1 |
|
return $this->model(Network::class)->bulkCreate($options); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Retrieve a network object without calling the remote API. Any values provided in the array will populate the |
|
43
|
|
|
* empty object, allowing you greater control without the expense of network transactions. To call the remote API |
|
44
|
|
|
* and have the response populate the object, call {@see Network::retrieve}. |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $id |
|
47
|
|
|
* |
|
48
|
|
|
* @return Network |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function getNetwork($id) |
|
51
|
|
|
{ |
|
52
|
1 |
|
return $this->model(Network::class, ['id' => $id]); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* List networks. |
|
57
|
|
|
* |
|
58
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::getNetworks} |
|
59
|
|
|
* |
|
60
|
|
|
* @return \Generator |
|
61
|
|
|
*/ |
|
62
|
1 |
|
public function listNetworks(array $options = []) |
|
63
|
|
|
{ |
|
64
|
1 |
|
return $this->model(Network::class)->enumerate($this->api->getNetworks(), $options); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Create a new subnet resource. |
|
69
|
|
|
* |
|
70
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postSubnet} |
|
71
|
|
|
* |
|
72
|
|
|
* @return Subnet |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function createSubnet(array $options) |
|
75
|
|
|
{ |
|
76
|
1 |
|
return $this->model(Subnet::class)->create($options); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Create a new subnet resources. |
|
81
|
|
|
* |
|
82
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postSubnets} |
|
83
|
|
|
* |
|
84
|
|
|
* @return []Subnet |
|
|
|
|
|
|
85
|
|
|
*/ |
|
86
|
1 |
|
public function createSubnets(array $options) |
|
87
|
|
|
{ |
|
88
|
1 |
|
return $this->model(Subnet::class)->bulkCreate($options); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Retrieve a subnet object without calling the remote API. Any values provided in the array will populate the |
|
93
|
|
|
* empty object, allowing you greater control without the expense of network transactions. To call the remote API |
|
94
|
|
|
* and have the response populate the object, call {@see Subnet::retrieve}. |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $id |
|
97
|
|
|
* |
|
98
|
|
|
* @return Subnet |
|
99
|
|
|
*/ |
|
100
|
1 |
|
public function getSubnet($id) |
|
101
|
|
|
{ |
|
102
|
1 |
|
return $this->model(Subnet::class, ['id' => $id]); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* List subnets. |
|
107
|
|
|
* |
|
108
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::getSubnets} |
|
109
|
|
|
* |
|
110
|
|
|
* @return \Generator |
|
111
|
|
|
*/ |
|
112
|
1 |
|
public function listSubnets(array $options = []) |
|
113
|
|
|
{ |
|
114
|
1 |
|
return $this->model(Subnet::class)->enumerate($this->api->getSubnets(), $options); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Create a new port resource. |
|
119
|
|
|
* |
|
120
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postPort} |
|
121
|
|
|
* |
|
122
|
|
|
* @return Port |
|
123
|
|
|
*/ |
|
124
|
1 |
|
public function createPort(array $options) |
|
125
|
|
|
{ |
|
126
|
1 |
|
return $this->model(Port::class)->create($options); |
|
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Create new port resources. |
|
131
|
|
|
* |
|
132
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::postPorts} |
|
133
|
|
|
* |
|
134
|
|
|
* @return []Port |
|
|
|
|
|
|
135
|
|
|
*/ |
|
136
|
1 |
|
public function createPorts(array $options) |
|
137
|
|
|
{ |
|
138
|
1 |
|
return $this->model(Port::class)->bulkCreate($options); |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Retrieve a subnet object without calling the remote API. Any values provided in the array will populate the |
|
143
|
|
|
* empty object, allowing you greater control without the expense of network transactions. To call the remote API |
|
144
|
|
|
* and have the response populate the object, call {@see Port::retrieve}. |
|
145
|
|
|
* |
|
146
|
|
|
* @param string $id |
|
147
|
|
|
* |
|
148
|
|
|
* @return Port |
|
149
|
|
|
*/ |
|
150
|
1 |
|
public function getPort($id) |
|
151
|
|
|
{ |
|
152
|
1 |
|
return $this->model(Port::class, ['id' => $id]); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* List ports. |
|
157
|
|
|
* |
|
158
|
|
|
* @param array $options {@see \OpenStack\Networking\v2\Api::getPorts} |
|
159
|
|
|
* |
|
160
|
|
|
* @return \Generator |
|
161
|
|
|
*/ |
|
162
|
1 |
|
public function listPorts(array $options = []) |
|
163
|
|
|
{ |
|
164
|
1 |
|
return $this->model(Port::class)->enumerate($this->api->getPorts(), $options); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
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: