Skip to content

Commit 352f823

Browse files
author
Jamie Hannaford
authored
Merge pull request #129 from nexcess/nex-various
[rtr] Basic Hosts, AZ Support And Other Fixes
2 parents f1bf63e + 6192267 commit 352f823

20 files changed

+552
-35
lines changed

src/Common/Api/Parameter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ private function hasCorrectType($userValue): bool
285285
return true;
286286
}
287287

288+
// allow string nulls
289+
if ($this->type == 'string' && $userValue === null) {
290+
return true;
291+
}
292+
288293
return gettype($userValue) == $this->type;
289294
}
290295

src/Compute/v2/Api.php

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function postServer(): array
190190
'method' => 'POST',
191191
'jsonKey' => 'server',
192192
'params' => [
193-
'imageId' => $this->params->imageId(),
193+
'imageId' => $this->notRequired($this->params->imageId()),
194194
'flavorId' => $this->params->flavorId(),
195195
'personality' => $this->params->personality(),
196196
'metadata' => $this->notRequired($this->params->metadata()),
@@ -459,6 +459,18 @@ public function getAddressesByNetwork(): array
459459
];
460460
}
461461

462+
public function getInterfaceAttachments(): array
463+
{
464+
return [
465+
'method' => 'GET',
466+
'path' => 'servers/{id}/os-interface',
467+
'jsonKey' => 'interfaceAttachments',
468+
'params' => [
469+
'id' => $this->params->urlId('server')
470+
]
471+
];
472+
}
473+
462474
public function getServerMetadata(): array
463475
{
464476
return [
@@ -639,7 +651,7 @@ public function getHypervisorStatistics(): array
639651
{
640652
return [
641653
'method' => 'GET',
642-
'path' => 'os-hypervisors/statistics',
654+
'path' => 'os-hypervisors/statistics',
643655
'params' => [
644656
]
645657
];
@@ -648,10 +660,12 @@ public function getHypervisorStatistics(): array
648660
public function getHypervisors(): array
649661
{
650662
return [
651-
'method' => 'GET',
652-
'path' => 'os-hypervisors',
663+
'method' => 'GET',
664+
'path' => 'os-hypervisors',
653665
'jsonKey' => 'hypervisors',
654-
'params' => [
666+
'params' => [
667+
'limit' => $this->params->limit(),
668+
'marker' => $this->params->marker()
655669
],
656670
];
657671
}
@@ -660,15 +674,49 @@ public function getHypervisorsDetail(): array
660674
{
661675
$definition = $this->getHypervisors();
662676
$definition['path'] .= '/detail';
677+
663678
return $definition;
664679
}
665680

666681
public function getHypervisor(): array
667682
{
668683
return [
669684
'method' => 'GET',
670-
'path' => 'os-hypervisors/{id}',
671-
'params' => ['id' => $this->params->urlId('hypervisor')]
685+
'path' => 'os-hypervisors/{id}',
686+
'params' => ['id' => $this->params->urlId('id')]
687+
];
688+
}
689+
690+
public function getAvailabilityZones(): array
691+
{
692+
return [
693+
'method' => 'GET',
694+
'path' => 'os-availability-zone/detail',
695+
'params' => [
696+
'limit' => $this->params->limit(),
697+
'marker' => $this->params->marker()
698+
]
699+
];
700+
}
701+
702+
public function getHosts(): array
703+
{
704+
return [
705+
'method' => 'GET',
706+
'path' => 'os-hosts',
707+
'params' => [
708+
'limit' => $this->params->limit(),
709+
'marker' => $this->params->marker()
710+
]
711+
];
712+
}
713+
714+
public function getHost(): array
715+
{
716+
return [
717+
'method' => 'GET',
718+
'path' => 'os-hosts/{name}',
719+
'params' => ['name' => $this->params->urlId('name')]
672720
];
673721
}
674722

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace OpenStack\Compute\v2\Models;
4+
5+
use OpenStack\Common\Resource\OperatorResource;
6+
use OpenStack\Common\Resource\Listable;
7+
8+
/**
9+
* Represents a Compute v2 AvailabilityZone.
10+
*
11+
* @property \OpenStack\Compute\v2\Api $api
12+
*/
13+
class AvailabilityZone extends OperatorResource implements Listable
14+
{
15+
/** @var string */
16+
public $name;
17+
18+
/** @var string */
19+
public $state;
20+
21+
/** @var array */
22+
public $hosts;
23+
24+
protected $resourceKey = 'availabilityZoneInfo';
25+
protected $resourcesKey = 'availabilityZoneInfo';
26+
27+
protected $aliases = [
28+
'zoneName' => 'name',
29+
'zoneState' => 'state',
30+
];
31+
}

src/Compute/v2/Models/Host.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace OpenStack\Compute\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\Listable;
9+
use OpenStack\Common\Resource\Retrievable;
10+
11+
/**
12+
* Represents a Compute v2 Host.
13+
*
14+
* @property \OpenStack\Compute\v2\Api $api
15+
*/
16+
class Host extends OperatorResource implements Listable, Retrievable
17+
{
18+
/** @var string **/
19+
public $name;
20+
21+
/** @var string **/
22+
public $service;
23+
24+
/** @var string **/
25+
public $zone;
26+
27+
protected $resourceKey = 'host';
28+
protected $resourcesKey = 'hosts';
29+
30+
protected $aliases = [
31+
'host_name' => 'name'
32+
];
33+
34+
/**
35+
* {@inheritDoc}
36+
*/
37+
public function retrieve()
38+
{
39+
$response = $this->execute($this->api->getHost(), $this->getAttrs(['name']));
40+
$this->populateFromResponse($response);
41+
}
42+
}

src/Compute/v2/Models/Hypervisor.php

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,77 @@ class Hypervisor extends OperatorResource implements
2323
public $state;
2424

2525
/** @var string */
26-
public $host_ip;
26+
public $hostIp;
2727

2828
/** @var int */
29-
public $free_disk_gb;
29+
public $freeDiskGb;
3030

3131
/** @var int */
32-
public $free_ram_mb;
32+
public $freeRamMb;
3333

3434
/** @var string */
35-
public $hypervisor_hostname;
35+
public $hypervisorHostname;
3636

3737
/** @var string */
38-
public $hypervisor_type;
38+
public $hypervisorType;
3939

4040
/** @var string */
41-
public $hypervisor_version;
41+
public $hypervisorVersion;
4242

4343
/** @var int */
44-
public $local_gb;
44+
public $localGb;
4545

4646
/** @var int */
47-
public $local_gb_used;
47+
public $localGbUsed;
4848

4949
/** @var int */
50-
public $memory_mb;
50+
public $memoryMb;
5151

5252
/** @var int */
53-
public $memory_mb_used;
53+
public $memoryMbUsed;
5454

5555
/** @var int */
56-
public $running_vms;
56+
public $runningVms;
5757

5858
/** @var int */
5959
public $vcpus;
6060

6161
/** @var int */
62-
public $vcpus_used;
62+
public $vcpusUsed;
63+
64+
/** @var array */
65+
public $cpuInfo;
66+
67+
/** @var int */
68+
public $currentWorkload;
69+
70+
/** @var int */
71+
public $diskAvailableLeast;
6372

6473
/** @var array */
6574
public $service;
6675

6776
protected $resourceKey = 'hypervisor';
6877
protected $resourcesKey = 'hypervisors';
6978

79+
protected $aliases = [
80+
'host_ip' => 'hostIp',
81+
'free_disk_gb' => 'freeDiskGb',
82+
'free_ram_mb' => 'freeRamMb',
83+
'hypervisor_hostname' => 'hypervisorHostname',
84+
'hypervisor_type' => 'hypervisorType',
85+
'hypervisor_version' => 'hypervisorVersion',
86+
'local_gb' => 'localGb',
87+
'local_gb_used' => 'localGbUsed',
88+
'memory_mb' => 'memoryMb',
89+
'memory_mb_used' => 'memoryMbUsed',
90+
'running_vms' => 'runningVms',
91+
'vcpus_used' => 'vcpusUsed',
92+
'cpu_info' => 'cpuInfo',
93+
'current_workload' => 'currentWorkload',
94+
'disk_available_least' => 'diskAvailableLeast'
95+
];
96+
7097
/**
7198
* {@inheritDoc}
7299
*/

src/Compute/v2/Models/Server.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OpenStack\Common\Resource\OperatorResource;
1212
use OpenStack\Common\Transport\Utils;
1313
use OpenStack\BlockStorage\v2\Models\VolumeAttachment;
14+
use OpenStack\Networking\v2\Models\InterfaceAttachment;
1415
use OpenStack\Compute\v2\Enum;
1516
use OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroup;
1617
use Psr\Http\Message\ResponseInterface;
@@ -106,6 +107,10 @@ class Server extends OperatorResource implements
106107
*/
107108
public function create(array $userOptions): Creatable
108109
{
110+
if (!isset($userOptions['imageId']) && !isset($userOptions['blockDeviceMapping']['uuid'])) {
111+
throw new \RuntimeException('imageId or blockDeviceMapping.uuid must be set.');
112+
}
113+
109114
$response = $this->execute($this->api->postServer(), $userOptions);
110115
return $this->populateFromResponse($response);
111116
}
@@ -313,6 +318,16 @@ public function listAddresses(array $options = []): array
313318
return Utils::jsonDecode($response)['addresses'];
314319
}
315320

321+
/**
322+
* Returns Generator for InterfaceAttachment
323+
*
324+
* @return \Generator
325+
*/
326+
public function listInterfaceAttachments(array $options = []): \Generator
327+
{
328+
return $this->model(InterfaceAttachment::class)->enumerate($this->api->getInterfaceAttachments(), ['id' => $this->id]);
329+
}
330+
316331
/**
317332
* Retrieves metadata from the API.
318333
*

src/Compute/v2/Params.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function imageId(): array
116116
'type' => self::STRING_TYPE,
117117
'required' => true,
118118
'sentAs' => 'imageRef',
119-
'description' => 'The unique ID of the image that this server will be based on',
119+
'description' => 'The UUID of the image to use for your server instance. This is not required in case of boot from volume. In all other cases it is required and must be a valid UUID',
120120
];
121121
}
122122

@@ -287,6 +287,11 @@ public function blockDeviceMapping(): array
287287
'sentAs' => 'device_name',
288288
'description' => 'Describes a path to the device for the volume you want to use to boot the server.',
289289
],
290+
'volumeSize' => [
291+
'type' => self::INT_TYPE,
292+
'sentAs' => 'volume_size',
293+
'description' => 'Size of the volume created if we are doing vol creation',
294+
],
290295
]
291296
],
292297
];

0 commit comments

Comments
 (0)