Skip to content
Draft
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
26 changes: 26 additions & 0 deletions src/Endpoint/IncusOS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint;

use Opensaucesystems\Lxd\Exception\InvalidEndpointException;

class IncusOS extends AbstractEndpoint
{
protected function getEndpoint()
{
return '';
}

public function __get($endpoint)
{
$class = __NAMESPACE__ . '\\IncusOS\\' . ucfirst($endpoint);

if (class_exists($class)) {
return new $class($this->client);
} else {
throw new InvalidEndpointException(
'Endpoint ' . $class . ', not implemented.'
);
}
}
}
28 changes: 28 additions & 0 deletions src/Endpoint/IncusOS/Applications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint\IncusOS;

use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;

class Applications extends AbstractEndpoint
{

protected function getEndpoint()
{
return '/os/1.0/applications';
}

public function all()
{
$applications = [];
foreach ($this->get($this->getEndpoint()) as $application) {
$applications[] = str_replace($this->getEndpoint() . "/", '', $application);
}
return $applications;
}

public function info(string $application)
{
return $this->get($this->getEndpoint() . "/" . $application);
}
}
28 changes: 28 additions & 0 deletions src/Endpoint/IncusOS/Services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint\IncusOS;

use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;

class Services extends AbstractEndpoint
{

protected function getEndpoint()
{
return '/os/1.0/services';
}

public function all()
{
$services = [];
foreach ($this->get($this->getEndpoint()) as $service) {
$services[] = str_replace($this->getEndpoint() . "/", '', $service);
}
return $services;
}

public function info(string $service)
{
return $this->get($this->getEndpoint() . "/" . $service);
}
}
52 changes: 52 additions & 0 deletions src/Endpoint/IncusOS/System.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint\IncusOS;

use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
use Opensaucesystems\Lxd\Exception\InvalidEndpointException;

class System extends AbstractEndpoint
{

protected function getEndpoint()
{
return '/os/1.0/system';
}

public function endpoints()
{
$endpoints = [];
foreach ($this->get($this->getEndpoint()) as $endpoint) {
$endpoints[] = str_replace($this->getEndpoint() . "/", '', $endpoint);
}
return $endpoints;
}

public function factoryReset()
{
$this->post($this->getEndpoint() . "/:factory-reset");
}

public function powerOff()
{
$this->post($this->getEndpoint() . "/:poweroff");
}

public function reboot()
{
$this->post($this->getEndpoint() . "/:reboot");
}

public function __get($endpoint)
{
$class = __NAMESPACE__ . '\\System\\' . ucfirst($endpoint);

if (class_exists($class)) {
return new $class($this->client);
} else {
throw new InvalidEndpointException(
'Endpoint ' . $class . ', not implemented.'
);
}
}
}
19 changes: 19 additions & 0 deletions src/Endpoint/IncusOS/System/Logging.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;

use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;

class Logging extends AbstractEndpoint
{

protected function getEndpoint()
{
return '/os/1.0/system/logging';
}

public function info()
{
return $this->get($this->getEndpoint());
}
}
19 changes: 19 additions & 0 deletions src/Endpoint/IncusOS/System/Network.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;

use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;

class Network extends AbstractEndpoint
{

protected function getEndpoint()
{
return '/os/1.0/system/network';
}

public function info()
{
return $this->get($this->getEndpoint());
}
}
19 changes: 19 additions & 0 deletions src/Endpoint/IncusOS/System/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;

use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;

class Provider extends AbstractEndpoint
{

protected function getEndpoint()
{
return '/os/1.0/system/provider';
}

public function info()
{
return $this->get($this->getEndpoint());
}
}
19 changes: 19 additions & 0 deletions src/Endpoint/IncusOS/System/Resources.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;

use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;

class Resources extends AbstractEndpoint
{

protected function getEndpoint()
{
return '/os/1.0/system/resources';
}

public function info()
{
return $this->get($this->getEndpoint());
}
}
19 changes: 19 additions & 0 deletions src/Endpoint/IncusOS/System/Security.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;

use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;

class Security extends AbstractEndpoint
{

protected function getEndpoint()
{
return '/os/1.0/system/security';
}

public function info()
{
return $this->get($this->getEndpoint());
}
}
19 changes: 19 additions & 0 deletions src/Endpoint/IncusOS/System/Storage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;

use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;

class Storage extends AbstractEndpoint
{

protected function getEndpoint()
{
return '/os/1.0/system/storage';
}

public function info()
{
return $this->get($this->getEndpoint());
}
}
24 changes: 24 additions & 0 deletions src/Endpoint/IncusOS/System/Update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;

use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;

class Update extends AbstractEndpoint
{

protected function getEndpoint()
{
return '/os/1.0/system/update';
}

public function info()
{
return $this->get($this->getEndpoint());
}

public function check()
{
return $this->post($this->getEndpoint() . "/:check");
}
}
8 changes: 6 additions & 2 deletions src/HttpClient/Plugin/PathPrepend.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ public function __construct($path)
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
$currentPath = $request->getUri()->getPath();
$uri = $request->getUri()->withPath($this->path.$currentPath);
$request = $request->withUri($uri);
// Incus proxies requests to its OS management API but the path
// is like `/os/1.0/X` instead of `/1.0/X` for normal operations
if(substr($currentPath, 0, strlen("/os/")) !== "/os/"){
$uri = $request->getUri()->withPath($this->path . $currentPath);
$request = $request->withUri($uri);
}

return $next($request);
}
Expand Down