Skip to content

Commit

Permalink
Implement some of the storage endpoints (enough for LxdMosaic)
Browse files Browse the repository at this point in the history
  • Loading branch information
turtle0x1 committed May 1, 2019
1 parent dad6a22 commit 7c69175
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/Endpoint/Storage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Opensaucesystems\Lxd\Endpoint;

class Storage extends AbstructEndpoint
{
protected function getEndpoint()
{
return '/storage-pools/';
}

public function all()
{
$storagePools = [];
foreach ($this->get($this->getEndpoint()) as $pool) {
$storagePools[] = str_replace('/'.$this->client->getApiVersion().$this->getEndpoint(), '', $pool);
}
return $storagePools;
}

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

public function create(string $name, string $driver, array $config)
{
$pool = [
"name"=>$name,
"driver"=>$driver,
"config"=>$config
];

return $this->post($this->getEndpoint(), $pool);
}

public function replace(string $name, array $config)
{
return $this->put($this->getEndpoint().$name, ["config"=>$config]);
}

public function update(string $name, array $config)
{
return $this->patch($this->getEndpoint().$name, ["config"=>$config]);
}

public function remove(string $name)
{
return $this->delete($this->getEndpoint().$name);
}

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

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

namespace Opensaucesystems\Lxd\Endpoint\Storage;

use Opensaucesystems\Lxd\Endpoint\AbstructEndpoint;

class Resources extends AbstructEndpoint
{
protected function getEndpoint()
{
return '/storage-pools/';
}

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

namespace Opensaucesystems\Lxd\Endpoint\Storage;

use Opensaucesystems\Lxd\Endpoint\AbstructEndpoint;

class Volumes extends AbstructEndpoint
{
protected function getEndpoint()
{
return '/storage-pools/';
}

/**
*/
public function info($name)
{
return $this->get($this->getEndpoint().$name.'/volumes');
}
}

0 comments on commit 7c69175

Please sign in to comment.