Skip to content

Commit a37eb93

Browse files
committed
Change behavior for unspecified number of lines
1 parent 2f3d2ae commit a37eb93

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/Compute/v2/Api.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,18 @@ public function getConsoleOutput(): array
385385
];
386386
}
387387

388+
public function getAllConsoleOutput(): array
389+
{
390+
return [
391+
'method' => 'POST',
392+
'path' => 'servers/{id}/action',
393+
'params' => [
394+
'id' => $this->params->urlId('server'),
395+
'os-getConsoleOutput' => $this->params->emptyObject(),
396+
],
397+
];
398+
}
399+
388400
public function createServerImage(): array
389401
{
390402
return [

src/Compute/v2/Models/Server.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,12 @@ public function revertResize()
246246
*/
247247
public function getConsoleOutput(int $length = -1): string
248248
{
249-
$response = $this->execute($this->api->getConsoleOutput(), [
249+
$definition = $length == -1 ? $this->api->getAllConsoleOutput() : $this->api->getConsoleOutput();
250+
251+
$response = $this->execute($definition, [
252+
'os-getConsoleOutput' => new \stdClass(),
250253
'id' => $this->id,
251-
'length' => $length
254+
'length' => $length,
252255
]);
253256

254257
return Utils::jsonDecode($response)['output'];

src/Compute/v2/Params.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,13 @@ public function consoleLogLength(): array
468468
];
469469
}
470470

471+
public function emptyObject(): array
472+
{
473+
return [
474+
'type' => self::OBJECT_TYPE,
475+
];
476+
}
477+
471478
protected function quotaSetLimit($sentAs, $description): array
472479
{
473480
return [

tests/unit/Compute/v2/Models/ServerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ public function test_it_gets_console_output()
217217
$this->assertEquals("FAKE CONSOLE OUTPUT\nANOTHER\nLAST LINE", $this->server->getConsoleOutput(3));
218218
}
219219

220+
public function test_it_gets_all_console_output()
221+
{
222+
$expectedJson = ["os-getConsoleOutput" => new \stdClass()];
223+
$this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], 'server-get-console-output');
224+
225+
$this->assertEquals("FAKE CONSOLE OUTPUT\nANOTHER\nLAST LINE", $this->server->getConsoleOutput());
226+
}
227+
220228
public function test_it_gets_vnc_console()
221229
{
222230
$type = 'novnc';

0 commit comments

Comments
 (0)