Skip to content

Commit 85714b8

Browse files
committed
Added provide backup as source type & file to create container from backup file
1 parent 9f2455c commit 85714b8

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
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.14.0]
8+
9+
## Added
10+
- Provide backup as source type & file to create container from backup file
11+
712
## [0.13.2]
813

914
## Fixed

src/Endpoint/Containers.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,18 @@ public function unfreeze($name, $timeout = 30, $force = true, $stateful = false,
259259
* @param bool $wait Wait for operation to finish
260260
* @return object
261261
*/
262-
public function create($name, array $options, $wait = false)
262+
public function create($name, array $options, $wait = false, array $requestHeaders = [])
263263
{
264264
$source = $this->getSource($options);
265265

266266
if (empty($options['empty']) && empty($source)) {
267267
throw new SourceImageException();
268268
}
269269

270-
if (!empty($options['source'])) {
270+
if ($source == "backup") {
271+
$opts = $this->getOptions($name, $options);
272+
$requestHeaders["Content-Type"] = "application/octet-stream";
273+
} elseif (!empty($options['source'])) {
271274
$opts = $this->getOptions($name, $options);
272275
$opts['source'] = $source;
273276
} elseif (isset($options['empty']) && $options['empty']) {
@@ -282,7 +285,8 @@ public function create($name, array $options, $wait = false)
282285
"project"=>$this->client->getProject()
283286
];
284287

285-
$response = $this->post($this->getEndpoint(), $opts, $config);
288+
289+
$response = $this->post($this->getEndpoint(), $opts, $config, $requestHeaders);
286290

287291
if ($wait) {
288292
$response = $this->client->operations->wait($response['id']);
@@ -630,6 +634,7 @@ private function getSource($options)
630634
'fingerprint',
631635
'properties',
632636
'live',
637+
'backup'
633638
];
634639
$opts = array_intersect_key($options, array_flip((array) $only));
635640

@@ -654,6 +659,13 @@ private function getSource($options)
654659
*/
655660
private function getOptions($name, $options)
656661
{
662+
if (isset($options["source"]) && $options["source"] == "backup") {
663+
if (!isset($options["file"])) {
664+
throw new \Exception('source => backup requires file => file_get_contents(BACKUP_PATH) ');
665+
}
666+
return $options["file"];
667+
}
668+
657669
$only = [
658670
'architecture',
659671
'profiles',

0 commit comments

Comments
 (0)