Skip to content

Commit f85eb66

Browse files
committed
Change behavior for unspecified number of lines
1 parent ee5dcf4 commit f85eb66

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
@@ -254,9 +254,12 @@ public function revertResize()
254254
*/
255255
public function getConsoleOutput(int $length = -1): string
256256
{
257-
$response = $this->execute($this->api->getConsoleOutput(), [
257+
$definition = $length == -1 ? $this->api->getAllConsoleOutput() : $this->api->getConsoleOutput();
258+
259+
$response = $this->execute($definition, [
260+
'os-getConsoleOutput' => new \stdClass(),
258261
'id' => $this->id,
259-
'length' => $length
262+
'length' => $length,
260263
]);
261264

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

src/Compute/v2/Params.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,13 @@ public function consoleLogLength(): array
508508
];
509509
}
510510

511+
public function emptyObject(): array
512+
{
513+
return [
514+
'type' => self::OBJECT_TYPE,
515+
];
516+
}
517+
511518
protected function quotaSetLimit($sentAs, $description): array
512519
{
513520
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)