Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Ops/Net IP Availability/Vol Ops #152

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions samples/compute/v2/servers/resume_server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
'authUrl' => '{authUrl}',
'region' => '{region}',
'user' => [
'id' => '{userId}',
'password' => '{password}'
],
'scope' => ['project' => ['id' => '{projectId}']]
]);

$compute = $openstack->computeV2(['region' => '{region}']);

$server = $compute->getServer([
'id' => '{serverId}',
]);

$server->resume();
21 changes: 21 additions & 0 deletions samples/compute/v2/servers/suspend_server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
'authUrl' => '{authUrl}',
'region' => '{region}',
'user' => [
'id' => '{userId}',
'password' => '{password}'
],
'scope' => ['project' => ['id' => '{projectId}']]
]);

$compute = $openstack->computeV2(['region' => '{region}']);

$server = $compute->getServer([
'id' => '{serverId}',
]);

$server->suspend();
33 changes: 33 additions & 0 deletions src/BlockStorage/Enum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

namespace OpenStack\BlockStorage\v2;

/**
* Represents common constants.
*
* @package OpenStack\BlockStorage\v2
*/
abstract class Enum
{
const STATUS_AVAILABLE = 'available';
const STATUS_CREATING = 'creating';
const STATUS_RESERVED = 'reserved';
const STATUS_ATTACHING = 'attaching';
const STATUS_DETACHING = 'detaching';
const STATUS_IN_USE = 'in-use';
const STATUS_MAINTENANCE = 'maintenance';
const STATUS_DELETING = 'deleting';
const STATUS_AWAITING_TRANSFER = 'awaiting-transfer';
const STATUS_ERROR = 'error';
const STATUS_ERROR_DELETING = 'error_deleting';
const STATUS_BACKING_UP = 'backing-up';
const STATUS_ERROR_BACKING_UP = 'error_backing-up';
const STATUS_ERROR_RESTORING = 'error_restoring';
const STATUS_DOWNLOADING = 'downloading';
const STATUS_UPLOADING = 'uploading';
const STATUS_RETYPINGi = 'retyping';
const STATUS_EXTENDING = 'extending';

const ATTACH_STATUS_ATTACHED = 'attached';
const ATTACH_STATUS_DETACHED = 'detached';
}
26 changes: 26 additions & 0 deletions src/BlockStorage/v2/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,30 @@ public function putQuotaSet(): array
]
];
}

public function extendVolume(): array
{
return [
'method' => 'POST',
'path' => 'volumes/{id}/action',
'jsonKey' => 'os-extend',
'params' => [
'id' => $this->params->idPath(),
'new_size' => $this->params->size(),
],
];
}

public function resetVolumeStatus(): array
{
return [
'method' => 'POST',
'path' => 'volumes/{id}/action',
'jsonKey' => 'os-reset_status',
'params' => [
'id' => $this->params->idPath(),
'status' => $this->params->status()
],
];
}
}
18 changes: 18 additions & 0 deletions src/BlockStorage/v2/Models/Volume.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ public function delete()
$this->executeWithState($this->api->deleteVolume());
}

public function resetStatus(string $status)
{
$response = $this->execute($this->api->resetVolumeStatus(), [
'id' => $this->id,
'status' => $status
]);
$this->populateFromResponse($response);
}

public function getMetadata(): array
{
$response = $this->executeWithState($this->api->getVolumeMetadata());
Expand All @@ -135,4 +144,13 @@ public function parseMetadata(ResponseInterface $response): array
$json = Utils::jsonDecode($response);
return isset($json['metadata']) ? $json['metadata'] : [];
}

public function extend(int $size_in_gb)
{
$response = $this->execute($this->api->extendVolume(), [
'id' => $this->id,
'new_size' => $size_in_gb
]);
$this->populateFromResponse($response);
}
}
21 changes: 20 additions & 1 deletion src/BlockStorage/v2/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function snapshotName(): array
'location' => self::JSON,
];
}

protected function quotaSetLimit($sentAs, $description): array
{
return [
Expand Down Expand Up @@ -224,4 +224,23 @@ public function quotaSetVolumesIscsi(): array
{
return $this->quotaSetLimit('volumes_iscsi', 'The number of allowed volumes iscsi');
}

public function nullAction(): array
{
return [
'type' => self::NULL_TYPE,
'location' => self::JSON,
'required' => true
];
}

public function status(): array
{
return [
'type' => self::STRING_TYPE,
'location' => self::JSON,
'required' => true,
'description' => 'The new status of the volume',
];
}
}
121 changes: 121 additions & 0 deletions src/Compute/v2/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,90 @@ public function stopServer() : array
];
}

public function resumeServer() : array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'params' => [
'id' => $this->params->urlId('server'),
'resume' => $this->params->nullAction()
],
];
}

public function suspendServer() : array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'params' => [
'id' => $this->params->urlId('server'),
'suspend' => $this->params->nullAction()
],
];
}

public function shelveServer() : array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'params' => [
'id' => $this->params->urlId('server'),
'shelve' => $this->params->nullAction(),
],
];
}

public function shelveOffloadServer() : array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'params' => [
'id' => $this->params->urlId('server'),
'shelveOffload' => $this->params->nullAction()
],
];
}

public function unshelveServer() : array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'params' => [
'id' => $this->params->urlId('server'),
'unshelve' => $this->params->nullAction()
],
];
}

public function lockServer() : array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'params' => [
'id' => $this->params->urlId('server'),
'lock' => $this->params->nullAction()
],
];
}

public function unlockServer() : array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'params' => [
'id' => $this->params->urlId('server'),
'unlock' => $this->params->nullAction()
],
];
}

public function rebuildServer(): array
{
return [
Expand Down Expand Up @@ -438,6 +522,19 @@ public function getRDPConsole(): array
];
}

public function getConsoleLog(): array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'jsonKey' => 'os-getConsoleOutput',
'params' => [
'id' => $this->params->urlId('server'),
'length' => $this->params->consoleLogLength()
]
];
}

public function getAddresses(): array
{
return [
Expand Down Expand Up @@ -777,4 +874,28 @@ public function putQuotaSet(): array
]
];
}

public function getInstanceActions(): array
{
return [
'method' => 'GET',
'path' => 'servers/{id}/os-instance-actions',
'params' => [
'id' => $this->params->urlId('server')
]
];
}

public function getInstanceAction(): array
{
return [
'method' => 'GET',
'path' => 'servers/{id}/os-instance-actions/{requestId}',
'params' => [
'id' => $this->params->urlId('server'),
'requestId' => $this->params->urlId('request')
]
];
}

}
44 changes: 44 additions & 0 deletions src/Compute/v2/Models/InstanceAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);

namespace OpenStack\Compute\v2\Models;

use OpenStack\Common\Resource\Listable;
use OpenStack\Common\Resource\OperatorResource;

/**
* @property \OpenStack\Compute\v2\Api $api
*/
class InstanceAction extends OperatorResource implements
Listable
{

/** @var string */
public $requestId;

/** @var string */
public $action;

/** @var string */
public $instanceUuid;

/** @var string */
public $message;

/** @var string */
public $startTime;

/** @var array */
public $events;

protected $resourceKey = 'instanceAction';
protected $resourcesKey = 'instanceActions';

protected $aliases = [
'instance_uuid' => 'instanceUuid',
'project_id' => 'projectId',
'request_id' => 'requestId',
'start_time' => 'startTime',
'user_id' => 'userId'
];

}
Loading