Skip to content
Merged
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
20 changes: 20 additions & 0 deletions samples/compute/v2/servers/get_server_rdp_console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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}']);

/** @var array $console */
$console = $server->getRDPConsole();
20 changes: 20 additions & 0 deletions samples/compute/v2/servers/get_server_serial_console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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}']);

/** @var array $console */
$console = $server->getSerialConsole();
20 changes: 20 additions & 0 deletions samples/compute/v2/servers/get_server_spice_console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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}']);

/** @var array $console */
$console = $server->getSpiceConsole();
20 changes: 20 additions & 0 deletions samples/compute/v2/servers/get_server_vnc_console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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}']);

/** @var array $console */
$console = $server->getVncConsole();
Copy link
Contributor

@jamiehannaford jamiehannaford Aug 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe have /** @var array $console */ above this, just to be clear

52 changes: 52 additions & 0 deletions src/Compute/v2/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,58 @@ public function createServerImage(): array
];
}

public function getVncConsole(): array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'jsonKey' => 'os-getVNCConsole',
'params' => [
'id' => $this->params->urlId('server'),
'type' => $this->params->consoleType()
]
];
}

public function getSpiceConsole(): array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'jsonKey' => 'os-getSPICEConsole',
'params' => [
'id' => $this->params->urlId('server'),
'type' => $this->params->consoleType()
]
];
}

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

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

public function getAddresses(): array
{
return [
Expand Down
5 changes: 5 additions & 0 deletions src/Compute/v2/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ abstract class Enum
{
const REBOOT_SOFT = 'SOFT';
const REBOOT_HARD = 'HARD';
const CONSOLE_NOVNC = 'novnc';
const CONSOLE_XVPNC = 'xvpvnc';
const CONSOLE_RDP_HTML5 = 'rdp-html5';
const CONSOLE_SPICE_HTML5 = 'spice-html5';
const CONSOLE_SERIAL = 'serial';
}
53 changes: 53 additions & 0 deletions src/Compute/v2/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,59 @@ public function revertResize()
$this->execute($this->api->revertServerResize(), ['revertResize' => null, 'id' => $this->id]);
}

/**
* Gets a VNC console for a server.
*
* @param string $type The type of VNC console: novnc|xvpvnc.
* Defaults to novnc.
*
* @return array
*/
public function getVncConsole($type = Enum::CONSOLE_NOVNC): array
{
$response = $this->execute($this->api->getVncConsole(), ['id' => $this->id, 'type' => $type]);
return Utils::jsonDecode($response)['console'];
}

/**
* Gets a RDP console for a server.
*
* @param string $type The type of VNC console: rdp-html5 (default).
*
* @return array
*/
public function getRDPConsole($type = Enum::CONSOLE_RDP_HTML5): array
{
$response = $this->execute($this->api->getRDPConsole(), ['id' => $this->id, 'type' => $type]);
return Utils::jsonDecode($response)['console'];
}

/**
* Gets a Spice console for a server.
*
* @param string $type The type of VNC console: spice-html5.
*
* @return array
*/
public function getSpiceConsole($type = Enum::CONSOLE_SPICE_HTML5): array
{
$response = $this->execute($this->api->getSpiceConsole(), ['id' => $this->id, 'type' => $type]);
return Utils::jsonDecode($response)['console'];
}

/**
* Gets a serial console for a server.
*
* @param string $type The type of VNC console: serial.
*
* @return array
*/
public function getSerialConsole($type = Enum::CONSOLE_SERIAL): array
{
$response = $this->execute($this->api->getSerialConsole(), ['id' => $this->id, 'type' => $type]);
return Utils::jsonDecode($response)['console'];
}

/**
* Creates an image for the current server.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Compute/v2/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,13 @@ public function attachmentId(): array
'required' => true,
];
}

public function consoleType(): array
{
return [
'type' => self::STRING_TYPE,
'location' => self::JSON,
'required' => true
];
}
}
14 changes: 14 additions & 0 deletions tests/integration/Compute/v2/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ public function runTests()
// Limits
$this->getLimits();
$this->getHypervisorsStatistics();

// Console
$this->getVncConsole();
} finally {
// Teardown
$this->deleteServer();
Expand Down Expand Up @@ -647,4 +650,15 @@ private function detachVolumeFromServer()

$this->logStep('Detached volume attachments for server {serverId}', $replacements);
}

private function getVncConsole()
{
$replacements = [
'{serverId}' => $this->serverId
];

require_once $this->sampleFile($replacements, 'servers/get_server_vnc_console.php');

$this->logStep('Get VNC console for server {serverId}', $replacements);
}
}
9 changes: 9 additions & 0 deletions tests/unit/Compute/v2/Fixtures/server-get-console-rdp.resp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HTTP/1.1 200 Accepted
Content-Type: application/json

{
"console": {
"type": "rdp-html5",
"url": "http://127.0.0.1:6083/?token=191996c3-7b0f-42f3-95a7-f1839f2da6ed"
}
}
9 changes: 9 additions & 0 deletions tests/unit/Compute/v2/Fixtures/server-get-console-serial.resp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HTTP/1.1 200 Accepted
Content-Type: application/json

{
"console": {
"type": "serial",
"url":"ws://127.0.0.1:6083/?token=f9906a48-b71e-4f18-baca-c987da3ebdb3"
}
}
9 changes: 9 additions & 0 deletions tests/unit/Compute/v2/Fixtures/server-get-console-spice.resp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HTTP/1.1 200 Accepted
Content-Type: application/json

{
"console": {
"type": "spice-html5",
"url": "http://127.0.0.1:6082/spice_auto.html?token=a30e5d08-6a20-4043-958f-0852440c6af4"
}
}
9 changes: 9 additions & 0 deletions tests/unit/Compute/v2/Fixtures/server-get-console-vnc.resp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HTTP/1.1 200 Accepted
Content-Type: application/json

{
"console": {
"type": "novnc",
"url": "http://127.0.0.1:6080/vnc_auto.html?token=191996c3-7b0f-42f3-95a7-f1839f2da6ed"
}
}
56 changes: 56 additions & 0 deletions tests/unit/Compute/v2/Models/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,62 @@ public function test_it_reverts_resizes()
$this->assertNull($this->server->revertResize());
}

public function test_it_gets_vnc_console()
{
$type = 'novnc';
$expectedJson = ['os-getVNCConsole' => ['type' => $type]];

$this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], 'server-get-console-vnc');

$response = $this->server->getVncConsole();

$this->assertArrayHasKey('url', $response);
$this->assertArrayHasKey('type', $response);
$this->assertEquals($type, $response['type']);
}

public function test_it_gets_rdp_console()
{
$type = 'rdp-html5';
$expectedJson = ['os-getRDPConsole' => ['type' => $type]];

$this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], 'server-get-console-rdp');

$response = $this->server->getRDPConsole();

$this->assertArrayHasKey('url', $response);
$this->assertArrayHasKey('type', $response);
$this->assertEquals($type, $response['type']);
}

public function test_it_gets_spice_console()
{
$type = 'spice-html5';
$expectedJson = ['os-getSPICEConsole' => ['type' => $type]];

$this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], 'server-get-console-spice');

$response = $this->server->getSpiceConsole();

$this->assertArrayHasKey('url', $response);
$this->assertArrayHasKey('type', $response);
$this->assertEquals($type, $response['type']);
}

public function test_it_gets_serial_console()
{
$type = 'serial';
$expectedJson = ['os-getSerialConsole' => ['type' => $type]];

$this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], 'server-get-console-serial');

$response = $this->server->getSerialConsole();

$this->assertArrayHasKey('url', $response);
$this->assertArrayHasKey('type', $response);
$this->assertEquals($type, $response['type']);
}

public function test_it_creates_images()
{
$userData = ['name' => 'newImage', 'metadata' => ['foo' => 'bar']];
Expand Down