Skip to content

Commit b708f72

Browse files
committed
Added backup endpoints
1 parent ad3f414 commit b708f72

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All Notable changes to `php-lxd` will be documented in this file.
44

55
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
66

7+
## [0.12.0]
8+
9+
### Added
10+
- Backup endpoints
11+
712
## [0.6.0] - 2017-01-23
813

914
### Added

src/Endpoint/Containers/Backups.php

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
3+
namespace Opensaucesystems\Lxd\Endpoint\Containers;
4+
5+
use Opensaucesystems\Lxd\Endpoint\AbstructEndpoint;
6+
7+
class Backups extends AbstructEndpoint
8+
{
9+
protected function getEndpoint()
10+
{
11+
return '/containers/';
12+
}
13+
/**
14+
* Get all backups for a particular container
15+
* @param string $container Container name
16+
* @return object
17+
*/
18+
public function all(string $container)
19+
{
20+
$backups = [];
21+
22+
$config = [
23+
"project"=>$this->client->getProject()
24+
];
25+
26+
foreach ($this->get($this->getEndpoint().$container.'/backups/', $config) as $backup) {
27+
$backup = str_replace(
28+
'/'.$this->client->getApiVersion().'/containers/'.$container.'/backups/',
29+
'',
30+
$backup
31+
);
32+
$backup = str_replace("?project=".$config["project"], "", $backup);
33+
$backups[] = $backup;
34+
}
35+
36+
return $backups;
37+
}
38+
/**
39+
* Get info for a container backup
40+
* @param string $container Container name
41+
* @param string $name Backup name
42+
* @return object
43+
*/
44+
public function info(string $container, string $name)
45+
{
46+
$config = [
47+
"project"=>$this->client->getProject()
48+
];
49+
50+
return $this->get($this->getEndpoint().$container.'/backups/'.$name, $config);
51+
}
52+
/**
53+
* Create a backup for a container
54+
* @param string $container Name of the container
55+
* @param string $name Name of the backup
56+
* @param array $opts Options for the backup
57+
* @param bool $wait Wait for the backup operation to finish
58+
* @return object
59+
*/
60+
public function create(string $container, string $name, array $opts, $wait = false)
61+
{
62+
$opts = array_merge([
63+
"name"=>$name
64+
], $opts);
65+
66+
$config = [
67+
"project"=>$this->client->getProject()
68+
];
69+
70+
$response = $this->post($this->getEndpoint().$container.'/backups', $opts, $config);
71+
72+
if ($wait) {
73+
$response = $this->client->operations->wait($response['id']);
74+
}
75+
76+
return $response;
77+
}
78+
/**
79+
* Rename a container backup
80+
* @param string $container Name of the container
81+
* @param string $name Name of the backup
82+
* @param string $newBackup New name for the backup
83+
* @param bool $wait Wait for the rename operation to finish
84+
* @return object
85+
*/
86+
public function rename(string $container, string $name, string $newBackup, $wait = false)
87+
{
88+
$opts = [
89+
"name"=>$newBackup
90+
];
91+
92+
$config = [
93+
"project"=>$this->client->getProject()
94+
];
95+
96+
$response = $this->post($this->getEndpoint().$container.'/backups/'.$name, $opts, $config);
97+
98+
99+
if ($wait) {
100+
$response = $this->client->operations->wait($response['id']);
101+
}
102+
103+
return $response;
104+
}
105+
/**
106+
* Remove a container backup
107+
* @param string $container Name of a container
108+
* @param string $name Name of the backup
109+
* @param bool $wait Wait for the delete operation to finish
110+
* @return object
111+
*/
112+
public function remove(string $container, string $name, $wait = false)
113+
{
114+
$config = [
115+
"project"=>$this->client->getProject()
116+
];
117+
118+
$response = $this->delete($this->getEndpoint().$container.'/backups/'.$name, $config);
119+
120+
if ($wait) {
121+
$response = $this->client->operations->wait($response['id']);
122+
}
123+
124+
return $response;
125+
}
126+
}

0 commit comments

Comments
 (0)