Skip to content

Commit f55e320

Browse files
committed
Merge branch 'master' of https://github.com/turtle0x1/php-lxd
2 parents 5ecb8d5 + 8d07bcf commit f55e320

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

src/Endpoint/Projects.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint;
4+
5+
class Projects extends AbstructEndpoint
6+
{
7+
protected function getEndpoint()
8+
{
9+
return '/projects/';
10+
}
11+
12+
/**
13+
* List all projects on the server
14+
*
15+
*
16+
* @return array
17+
*/
18+
public function all()
19+
{
20+
$projects = [];
21+
22+
foreach ($this->get($this->getEndpoint()) as $project) {
23+
$x = str_replace('/'.$this->client->getApiVersion().$this->getEndpoint(), '', $project);
24+
$x = str_replace('?project=' . $this->client->getProject(), '', $x);
25+
26+
$projects[] = $x;
27+
}
28+
29+
return $projects;
30+
}
31+
32+
public function create(string $name, string $description = "", array $config = [])
33+
{
34+
$project = [];
35+
$project["name"] = $name;
36+
$project["description"] = $description;
37+
$project["config"] = empty($config) ? $this->defaultProjectConfig() : $config;
38+
39+
return $this->post($this->getEndpoint(), $project);
40+
}
41+
42+
public function info(string $name)
43+
{
44+
return $this->get($this->getEndpoint() . "/" . $name);
45+
}
46+
47+
public function replace(string $name, string $description = "", array $config = [])
48+
{
49+
$project = [];
50+
$project["description"] = $description;
51+
$project["config"] = empty($config) ? $this->defaultProjectConfig() : $config;
52+
53+
return $this->put($this->getEndpoint() . $name, $project);
54+
}
55+
56+
public function update(string $name, string $description = "", array $config = [])
57+
{
58+
$project = [];
59+
if(!empty($description)){
60+
$project["description"] = $description;
61+
}
62+
$project["config"] = empty($config) ? $this->defaultProjectConfig() : $config;
63+
return $this->patch($this->getEndpoint() . $name, $project);
64+
}
65+
66+
public function rename(string $name, string $newName)
67+
{
68+
$config = ["name"=>$newName];
69+
return $this->post($this->getEndpoint() . $name, $config);
70+
}
71+
72+
public function remove(string $name)
73+
{
74+
return $this->delete($this->getEndpoint() . $name);
75+
}
76+
77+
private function defaultProjectConfig()
78+
{
79+
return [
80+
"features.images"=>"true",
81+
"features.profiles"=>"true",
82+
];
83+
}
84+
}

0 commit comments

Comments
 (0)