Skip to content

Commit 96fbcf1

Browse files
committed
Add new name param on container migrate & fix empty device bug (close #7, #6)
1 parent b0bdc02 commit 96fbcf1

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/Endpoint/Containers.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,17 @@ public function copy($name, $copyName, array $options = [], $wait = false)
346346
* @param bool $wait Wait for operation to finish
347347
* @return object
348348
*/
349-
public function migrate(\Opensaucesystems\Lxd\Client $destination, $name, $wait = false)
350-
{
351-
return $destination->containers->create($name, $this->initMigration($name), $wait);
349+
public function migrate(
350+
\Opensaucesystems\Lxd\Client $destination,
351+
$name,
352+
string $newName = "",
353+
$wait = false
354+
) {
355+
if (empty($newName)) {
356+
$newName = $name;
357+
}
358+
359+
return $destination->containers->create($newName, $this->initMigration($name), $wait);
352360
}
353361

354362
/**
@@ -364,11 +372,11 @@ public function initMigration($name)
364372
$container = $this->info($name);
365373
$url = $this->client->getUrl().'/'.$this->client->getApiVersion().'/operations/'.$migration['id'];
366374

367-
return [
375+
376+
$settings = [
368377
'name' => $name,
369378
'architecture' => $container['architecture'],
370379
'config' => $container['config'],
371-
'devices' => $container['devices'],
372380
'epehemeral' => $container['ephemeral'],
373381
'profiles' => $container['profiles'],
374382
'source' => [
@@ -379,6 +387,12 @@ public function initMigration($name)
379387
'secrets' => $migration['metadata'],
380388
]
381389
];
390+
391+
if (!empty($container["devices"])) {
392+
$settings["devices"] = $container["devices"];
393+
}
394+
395+
return $settings;
382396
}
383397

384398
/**

0 commit comments

Comments
 (0)