forked from ashleyhood/php-lxd
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement some of the storage endpoints (enough for LxdMosaic)
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |