|  | 
|  | 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 | +} | 
0 commit comments