Skip to content

Commit bd2a9a5

Browse files
committed
Add sahara createMultipleClusters
1 parent 610bae9 commit bd2a9a5

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

samples/data_processing/nodegroup_template/create_nodegrouptemplate.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
'name' => '{nodeGroupTemplateName}',
3232
'flavorId' => '{flavorId}',
3333
'floatingIpPool' => '{floatingIpPool}',
34+
'autoSecurityGroup' => '{trueOrFalse}',
3435
'isProtected' => '{trueOrFalse}',
3536
];
3637

src/DataProcessing/v1/Api.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public function postNodeGroupTemplate()
279279
'imageId' => $this->params->imageId(),
280280
'floatingIpPool' => $this->params->floatingIpPool(),
281281
'useAutoconfig' => $this->params->useAutoconfig(),
282+
'autoSecurityGroup' => $this->params->autoSecurityGroup(),
282283
'isProxyGateway' => $this->params->isProxyGateway(),
283284
'isPublic' => $this->params->isPublic(),
284285
'isProtected' => $this->params->isProtected(),
@@ -319,6 +320,7 @@ public function putNodeGroupTemplate()
319320
'imageId' => $this->params->imageId(),
320321
'floatingIpPool' => $this->params->floatingIpPool(),
321322
'useAutoconfig' => $this->params->useAutoconfig(),
323+
'autoSecurityGroup' => $this->params->autoSecurityGroup(),
322324
'isProxyGateway' => $this->params->isProxyGateway(),
323325
'isPublic' => $this->params->isPublic(),
324326
'isProtected' => $this->params->isProtected(),

src/DataProcessing/v1/Models/NodeGroupTemplate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function delete()
8989

9090
public function update()
9191
{
92-
$response = $this->execute($this->api->putNodeGroupTemplate(), $this->getAttrs(['id', 'name', 'description', 'flavorId', 'availabilityZone', 'imageId', 'floatingIpPool', 'useAutoconfig', 'isProxyGateway', 'isPublic', 'isProtected']));
92+
$response = $this->execute($this->api->putNodeGroupTemplate(), $this->getAttrs(['id', 'name', 'description', 'flavorId', 'availabilityZone', 'imageId', 'floatingIpPool', 'useAutoconfig', 'autoSecurityGroup', 'isProxyGateway', 'isPublic', 'isProtected']));
9393
$this->populateFromResponse($response);
9494
}
9595
}

src/DataProcessing/v1/Params.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ public function useAutoconfig(): array
298298
];
299299
}
300300

301+
public function autoSecurityGroup(): array
302+
{
303+
return [
304+
'type' => self::BOOL_TYPE,
305+
'required' => false,
306+
'sentAs' => 'auto_security_group',
307+
'description' => 'If set to True, the cluster group is automatically secured.',
308+
];
309+
}
310+
301311
public function isProxyGateway(): array
302312
{
303313
return [

src/DataProcessing/v1/Service.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace OpenStack\DataProcessing\v1;
44

55
use OpenStack\Common\Service\AbstractService;
6+
use OpenStack\Common\Transport\Utils;
67
use OpenStack\DataProcessing\v1\Models\Cluster;
78
use OpenStack\DataProcessing\v1\Models\ClusterTemplate;
89
use OpenStack\DataProcessing\v1\Models\DataSource;
@@ -37,6 +38,26 @@ public function createCluster(array $options = []): Cluster
3738
return $this->model(Cluster::class)->create($options);
3839
}
3940

41+
public function createMultipleClusters(array $options = [])
42+
{
43+
if (!array_key_exists("count", $options)) {
44+
throw new \RuntimeException("Require 'count'");
45+
}
46+
47+
$response = $this->execute($this->api->postClusters(), $options);
48+
# For multiple clusters, the current API returns only cluster IDs.
49+
$ids = Utils::flattenJson(Utils::jsonDecode($response), 'clusters');
50+
if ($response->getStatusCode() === 204 || empty($ids)) {
51+
return;
52+
}
53+
foreach ($ids as $id) {
54+
$cluster = $this->model(Cluster::class);
55+
$cluster->id = $id;
56+
yield $cluster;
57+
}
58+
59+
}
60+
4061
public function scaleCluster(array $options = []): Cluster
4162
{
4263
return $this->model(Cluster::class)->scale($options);

0 commit comments

Comments
 (0)