-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathService.php
More file actions
311 lines (277 loc) · 10.6 KB
/
Copy pathService.php
File metadata and controls
311 lines (277 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
declare(strict_types=1);
namespace OpenStack\Compute\v2;
use OpenStack\Common\Service\AbstractService;
use OpenStack\Compute\v2\Models\Flavor;
use OpenStack\Compute\v2\Models\HypervisorStatistic;
use OpenStack\Compute\v2\Models\Image;
use OpenStack\Compute\v2\Models\Keypair;
use OpenStack\Compute\v2\Models\Limit;
use OpenStack\Compute\v2\Models\Server;
use OpenStack\Compute\v2\Models\Host;
use OpenStack\Compute\v2\Models\Hypervisor;
use OpenStack\Compute\v2\Models\AvailabilityZone;
use OpenStack\Compute\v2\Models\QuotaSet;
/**
* Compute v2 service for OpenStack.
*
* @property \OpenStack\Compute\v2\Api $api
*/
class Service extends AbstractService
{
/**
* Create a new server resource. This operation will provision a new virtual machine on a host chosen by your
* service API.
*
* @param array $options {@see \OpenStack\Compute\v2\Api::postServer}
*
* @return \OpenStack\Compute\v2\Models\Server
*/
public function createServer(array $options): Server
{
return $this->model(Server::class)->create($options);
}
/**
* List servers.
*
* @param bool $detailed Determines whether detailed information will be returned. If FALSE is specified, only
* the ID, name and links attributes are returned, saving bandwidth.
* @param array $options {@see \OpenStack\Compute\v2\Api::getServers}
* @param callable $mapFn a callable function that will be invoked on every iteration of the list
*
* @return \Generator
*/
public function listServers(bool $detailed = false, array $options = [], callable $mapFn = null): \Generator
{
$def = (true === $detailed) ? $this->api->getServersDetail() : $this->api->getServers();
return $this->model(Server::class)->enumerate($def, $options, $mapFn);
}
/**
* Retrieve a server object without calling the remote API. Any values provided in the array will populate the
* empty object, allowing you greater control without the expense of network transactions. To call the remote API
* and have the response populate the object, call {@see Server::retrieve}. For example:.
*
* <code>$server = $service->getServer(['id' => '{serverId}']);</code>
*
* @param array $options An array of attributes that will be set on the {@see Server} object. The array keys need to
* correspond to the class public properties.
*
* @return \OpenStack\Compute\v2\Models\Server
*/
public function getServer(array $options = []): Server
{
$server = $this->model(Server::class);
$server->populateFromArray($options);
return $server;
}
/**
* List flavors.
*
* @param array $options {@see \OpenStack\Compute\v2\Api::getFlavors}
* @param callable $mapFn a callable function that will be invoked on every iteration of the list
* @param bool $detailed set to true to fetch flavors' details
*
* @return \Generator
*/
public function listFlavors(array $options = [], callable $mapFn = null, bool $detailed = false): \Generator
{
$def = true === $detailed ? $this->api->getFlavorsDetail() : $this->api->getFlavors();
return $this->model(Flavor::class)->enumerate($def, $options, $mapFn);
}
/**
* Retrieve a flavor object without calling the remote API. Any values provided in the array will populate the
* empty object, allowing you greater control without the expense of network transactions. To call the remote API
* and have the response populate the object, call {@see Flavor::retrieve}.
*
* @param array $options An array of attributes that will be set on the {@see Flavor} object. The array keys need to
* correspond to the class public properties.
*
* @return \OpenStack\Compute\v2\Models\Flavor
*/
public function getFlavor(array $options = []): Flavor
{
$flavor = $this->model(Flavor::class);
$flavor->populateFromArray($options);
return $flavor;
}
/**
* Create a new flavor resource.
*
* @param array $options {@see \OpenStack\Compute\v2\Api::postFlavors}
*
* @return Flavor
*/
public function createFlavor(array $options = []): Flavor
{
return $this->model(Flavor::class)->create($options);
}
/**
* List images.
*
* @param array $options {@see \OpenStack\Compute\v2\Api::getImages}
* @param callable $mapFn a callable function that will be invoked on every iteration of the list
*
* @return \Generator
*/
public function listImages(array $options = [], callable $mapFn = null): \Generator
{
return $this->model(Image::class)->enumerate($this->api->getImages(), $options, $mapFn);
}
/**
* Retrieve an image object without calling the remote API. Any values provided in the array will populate the
* empty object, allowing you greater control without the expense of network transactions. To call the remote API
* and have the response populate the object, call {@see Image::retrieve}.
*
* @param array $options An array of attributes that will be set on the {@see Image} object. The array keys need to
* correspond to the class public properties.
*
* @return \OpenStack\Compute\v2\Models\Image
*/
public function getImage(array $options = []): Image
{
$image = $this->model(Image::class);
$image->populateFromArray($options);
return $image;
}
/**
* List key pairs.
*
* @param array $options {@see \OpenStack\Compute\v2\Api::getKeyPairs}
* @param callable $mapFn a callable function that will be invoked on every iteration of the list
*
* @return \Generator
*/
public function listKeypairs(array $options = [], callable $mapFn = null): \Generator
{
return $this->model(Keypair::class)->enumerate($this->api->getKeypairs(), $options, $mapFn);
}
/**
* Create or import keypair.
*
* @param array $options
*
* @return Keypair
*/
public function createKeypair(array $options): Keypair
{
return $this->model(Keypair::class)->create($options);
}
/**
* Get keypair.
*
* @param array $options
*
* @return Keypair
*/
public function getKeypair(array $options = []): Keypair
{
$keypair = $this->model(Keypair::class);
$keypair->populateFromArray($options);
return $keypair;
}
/**
* Shows rate and absolute limits for the tenant.
*
* @return Limit
*/
public function getLimits(): Limit
{
$limits = $this->model(Limit::class);
$limits->populateFromResponse($this->execute($this->api->getLimits(), []));
return $limits;
}
/**
* Shows summary statistics for all hypervisors over all compute nodes.
*
* @return HypervisorStatistic
*/
public function getHypervisorStatistics(): HypervisorStatistic
{
$statistics = $this->model(HypervisorStatistic::class);
$statistics->populateFromResponse($this->execute($this->api->getHypervisorStatistics(), []));
return $statistics;
}
/**
* List hypervisors.
*
* @param bool $detailed Determines whether detailed information will be returned. If FALSE is specified, only
* the ID, name and links attributes are returned, saving bandwidth.
* @param array $options {@see \OpenStack\Compute\v2\Api::getHypervisors}
* @param callable $mapFn a callable function that will be invoked on every iteration of the list
*
* @return \Generator
*/
public function listHypervisors(bool $detailed = false, array $options = [], callable $mapFn = null): \Generator
{
$def = (true === $detailed) ? $this->api->getHypervisorsDetail() : $this->api->getHypervisors();
return $this->model(Hypervisor::class)->enumerate($def, $options, $mapFn);
}
/**
* Shows details for a given hypervisor.
*
* @param array $options
*
* @return Hypervisor
*/
public function getHypervisor(array $options = []): Hypervisor
{
$hypervisor = $this->model(Hypervisor::class);
return $hypervisor->populateFromArray($options);
}
/**
* List hosts.
*
* @param array $options {@see \OpenStack\Compute\v2\Api::getHosts}
* @param callable $mapFn a callable function that will be invoked on every iteration of the list
*
* @return \Generator
*/
public function listHosts(array $options = [], callable $mapFn = null): \Generator
{
return $this->model(Host::class)->enumerate($this->api->getHosts(), $options, $mapFn);
}
/**
* Retrieve a host object without calling the remote API. Any values provided in the array will populate the
* empty object, allowing you greater control without the expense of network transactions. To call the remote API
* and have the response populate the object, call {@see Host::retrieve}. For example:.
*
* <code>$server = $service->getHost(['name' => '{name}']);</code>
*
* @param array $options An array of attributes that will be set on the {@see Host} object. The array keys need to
* correspond to the class public properties.
*
* @return \OpenStack\Compute\v2\Models\Host
*/
public function getHost(array $options = []): Host
{
$host = $this->model(Host::class);
$host->populateFromArray($options);
return $host;
}
/**
* List AZs.
*
* @param array $options {@see \OpenStack\Compute\v2\Api::getAvailabilityZones}
* @param callable $mapFn a callable function that will be invoked on every iteration of the list
*
* @return \Generator
*/
public function listAvailabilityZones(array $options = [], callable $mapFn = null): \Generator
{
return $this->model(AvailabilityZone::class)->enumerate($this->api->getAvailabilityZones(), $options, $mapFn);
}
/**
* Shows A Quota for a tenant.
*
* @param string $tenantId
* @param bool $detailed
*
* @return QuotaSet
*/
public function getQuotaSet(string $tenantId, bool $detailed = false): QuotaSet
{
$quotaSet = $this->model(QuotaSet::class);
$quotaSet->populateFromResponse($this->execute($detailed ? $this->api->getQuotaSetDetail() : $this->api->getQuotaSet(), ['tenantId' => $tenantId]));
return $quotaSet;
}
}