@@ -259,15 +259,18 @@ public function unfreeze($name, $timeout = 30, $force = true, $stateful = false,
259
259
* @param bool $wait Wait for operation to finish
260
260
* @return object
261
261
*/
262
- public function create ($ name , array $ options , $ wait = false )
262
+ public function create ($ name , array $ options , $ wait = false , array $ requestHeaders = [] )
263
263
{
264
264
$ source = $ this ->getSource ($ options );
265
265
266
266
if (empty ($ options ['empty ' ]) && empty ($ source )) {
267
267
throw new SourceImageException ();
268
268
}
269
269
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 ' ])) {
271
274
$ opts = $ this ->getOptions ($ name , $ options );
272
275
$ opts ['source ' ] = $ source ;
273
276
} elseif (isset ($ options ['empty ' ]) && $ options ['empty ' ]) {
@@ -282,7 +285,8 @@ public function create($name, array $options, $wait = false)
282
285
"project " =>$ this ->client ->getProject ()
283
286
];
284
287
285
- $ response = $ this ->post ($ this ->getEndpoint (), $ opts , $ config );
288
+
289
+ $ response = $ this ->post ($ this ->getEndpoint (), $ opts , $ config , $ requestHeaders );
286
290
287
291
if ($ wait ) {
288
292
$ response = $ this ->client ->operations ->wait ($ response ['id ' ]);
@@ -630,6 +634,7 @@ private function getSource($options)
630
634
'fingerprint ' ,
631
635
'properties ' ,
632
636
'live ' ,
637
+ 'backup '
633
638
];
634
639
$ opts = array_intersect_key ($ options , array_flip ((array ) $ only ));
635
640
@@ -654,6 +659,13 @@ private function getSource($options)
654
659
*/
655
660
private function getOptions ($ name , $ options )
656
661
{
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
+
657
669
$ only = [
658
670
'architecture ' ,
659
671
'profiles ' ,
0 commit comments