Skip to content

Commit 7c69175

Browse files
committed
Implement some of the storage endpoints (enough for LxdMosaic)
1 parent dad6a22 commit 7c69175

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

src/Endpoint/Storage.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint;
4+
5+
class Storage extends AbstructEndpoint
6+
{
7+
protected function getEndpoint()
8+
{
9+
return '/storage-pools/';
10+
}
11+
12+
public function all()
13+
{
14+
$storagePools = [];
15+
foreach ($this->get($this->getEndpoint()) as $pool) {
16+
$storagePools[] = str_replace('/'.$this->client->getApiVersion().$this->getEndpoint(), '', $pool);
17+
}
18+
return $storagePools;
19+
}
20+
21+
public function info(string $name)
22+
{
23+
return $this->get($this->getEndpoint().$name);
24+
}
25+
26+
public function create(string $name, string $driver, array $config)
27+
{
28+
$pool = [
29+
"name"=>$name,
30+
"driver"=>$driver,
31+
"config"=>$config
32+
];
33+
34+
return $this->post($this->getEndpoint(), $pool);
35+
}
36+
37+
public function replace(string $name, array $config)
38+
{
39+
return $this->put($this->getEndpoint().$name, ["config"=>$config]);
40+
}
41+
42+
public function update(string $name, array $config)
43+
{
44+
return $this->patch($this->getEndpoint().$name, ["config"=>$config]);
45+
}
46+
47+
public function remove(string $name)
48+
{
49+
return $this->delete($this->getEndpoint().$name);
50+
}
51+
52+
public function __get($endpoint)
53+
{
54+
$class = __NAMESPACE__.'\\Storage\\'.ucfirst($endpoint);
55+
56+
if (class_exists($class)) {
57+
return new $class($this->client);
58+
} else {
59+
throw new InvalidEndpointException(
60+
'Endpoint '.$class.', not implemented.'
61+
);
62+
}
63+
}
64+
}

src/Endpoint/Storage/Resources.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\Storage;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstructEndpoint;
6+
7+
class Resources extends AbstructEndpoint
8+
{
9+
protected function getEndpoint()
10+
{
11+
return '/storage-pools/';
12+
}
13+
14+
/**
15+
*/
16+
public function info($name)
17+
{
18+
return $this->get($this->getEndpoint().$name.'/resources');
19+
}
20+
}

src/Endpoint/Storage/Volumes.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\Storage;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstructEndpoint;
6+
7+
class Volumes extends AbstructEndpoint
8+
{
9+
protected function getEndpoint()
10+
{
11+
return '/storage-pools/';
12+
}
13+
14+
/**
15+
*/
16+
public function info($name)
17+
{
18+
return $this->get($this->getEndpoint().$name.'/volumes');
19+
}
20+
}

0 commit comments

Comments
 (0)