Skip to content

Commit b0bd49b

Browse files
authored
Merge pull request #22 from turtle0x1/incus-os
Add IncusOS GET endpoints + a few of the easier POST ones
2 parents 5df1967 + a7370bb commit b0bd49b

12 files changed

Lines changed: 278 additions & 2 deletions

File tree

src/Endpoint/IncusOS.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint;
4+
5+
use Opensaucesystems\Lxd\Exception\InvalidEndpointException;
6+
7+
class IncusOS extends AbstractEndpoint
8+
{
9+
protected function getEndpoint()
10+
{
11+
return '';
12+
}
13+
14+
public function __get($endpoint)
15+
{
16+
$class = __NAMESPACE__ . '\\IncusOS\\' . ucfirst($endpoint);
17+
18+
if (class_exists($class)) {
19+
return new $class($this->client);
20+
} else {
21+
throw new InvalidEndpointException(
22+
'Endpoint ' . $class . ', not implemented.'
23+
);
24+
}
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\IncusOS;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
6+
7+
class Applications extends AbstractEndpoint
8+
{
9+
10+
protected function getEndpoint()
11+
{
12+
return '/os/1.0/applications';
13+
}
14+
15+
public function all()
16+
{
17+
$applications = [];
18+
foreach ($this->get($this->getEndpoint()) as $application) {
19+
$applications[] = str_replace($this->getEndpoint() . "/", '', $application);
20+
}
21+
return $applications;
22+
}
23+
24+
public function info(string $application)
25+
{
26+
return $this->get($this->getEndpoint() . "/" . $application);
27+
}
28+
}

src/Endpoint/IncusOS/Services.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\IncusOS;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
6+
7+
class Services extends AbstractEndpoint
8+
{
9+
10+
protected function getEndpoint()
11+
{
12+
return '/os/1.0/services';
13+
}
14+
15+
public function all()
16+
{
17+
$services = [];
18+
foreach ($this->get($this->getEndpoint()) as $service) {
19+
$services[] = str_replace($this->getEndpoint() . "/", '', $service);
20+
}
21+
return $services;
22+
}
23+
24+
public function info(string $service)
25+
{
26+
return $this->get($this->getEndpoint() . "/" . $service);
27+
}
28+
}

src/Endpoint/IncusOS/System.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\IncusOS;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
6+
use Opensaucesystems\Lxd\Exception\InvalidEndpointException;
7+
8+
class System extends AbstractEndpoint
9+
{
10+
11+
protected function getEndpoint()
12+
{
13+
return '/os/1.0/system';
14+
}
15+
16+
public function endpoints()
17+
{
18+
$endpoints = [];
19+
foreach ($this->get($this->getEndpoint()) as $endpoint) {
20+
$endpoints[] = str_replace($this->getEndpoint() . "/", '', $endpoint);
21+
}
22+
return $endpoints;
23+
}
24+
25+
public function factoryReset()
26+
{
27+
$this->post($this->getEndpoint() . "/:factory-reset");
28+
}
29+
30+
public function powerOff()
31+
{
32+
$this->post($this->getEndpoint() . "/:poweroff");
33+
}
34+
35+
public function reboot()
36+
{
37+
$this->post($this->getEndpoint() . "/:reboot");
38+
}
39+
40+
public function __get($endpoint)
41+
{
42+
$class = __NAMESPACE__ . '\\System\\' . ucfirst($endpoint);
43+
44+
if (class_exists($class)) {
45+
return new $class($this->client);
46+
} else {
47+
throw new InvalidEndpointException(
48+
'Endpoint ' . $class . ', not implemented.'
49+
);
50+
}
51+
}
52+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
6+
7+
class Logging extends AbstractEndpoint
8+
{
9+
10+
protected function getEndpoint()
11+
{
12+
return '/os/1.0/system/logging';
13+
}
14+
15+
public function info()
16+
{
17+
return $this->get($this->getEndpoint());
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
6+
7+
class Network extends AbstractEndpoint
8+
{
9+
10+
protected function getEndpoint()
11+
{
12+
return '/os/1.0/system/network';
13+
}
14+
15+
public function info()
16+
{
17+
return $this->get($this->getEndpoint());
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
6+
7+
class Provider extends AbstractEndpoint
8+
{
9+
10+
protected function getEndpoint()
11+
{
12+
return '/os/1.0/system/provider';
13+
}
14+
15+
public function info()
16+
{
17+
return $this->get($this->getEndpoint());
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
6+
7+
class Resources extends AbstractEndpoint
8+
{
9+
10+
protected function getEndpoint()
11+
{
12+
return '/os/1.0/system/resources';
13+
}
14+
15+
public function info()
16+
{
17+
return $this->get($this->getEndpoint());
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
6+
7+
class Security extends AbstractEndpoint
8+
{
9+
10+
protected function getEndpoint()
11+
{
12+
return '/os/1.0/system/security';
13+
}
14+
15+
public function info()
16+
{
17+
return $this->get($this->getEndpoint());
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\IncusOS\System;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
6+
7+
class Storage extends AbstractEndpoint
8+
{
9+
10+
protected function getEndpoint()
11+
{
12+
return '/os/1.0/system/storage';
13+
}
14+
15+
public function info()
16+
{
17+
return $this->get($this->getEndpoint());
18+
}
19+
}

0 commit comments

Comments
 (0)