What is the best way to replace device config

I am trying to replace the device config through the REST API, not that the operation did not succeed, but it doesn’t replace the existing one, suppose, I have the following:

devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  proxyPort27017:
    connect: tcp:127.0.0.1:27017
    listen: tcp:0.0.0.0:27017
    proxy_protocol: "true"
    type: proxy
  root:
    path: /
    pool: default
    type: disk

and I wanna replace it with:

devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk

Using the PUT request, gave me, the Volatile idmap keys can't be deleted by the user

using the PATCH request succeeded, but that did not replace it. I also stopped the instance before replacing the devices, but that did not work either.

Here is the PayLoad:

array:3 [
  "description" => "This is container seven updated"
  "devices" => array:2 [
    "root" => array:3 [
      "type" => "disk"
      "path" => "/"
      "pool" => "default"
    ]
    "eth0" => array:3 [
      "type" => "nic"
      "name" => "eth0"
      "network" => "lxdbr0"
    ]
  ]
  "profiles" => array:1 [
    0 => "default"
  ]
]

In JSON:

"{"description":"This is container seven updated","devices":{"root":{"type":"disk","path":"\/","pool":"default"},"eth0":{"type":"nic","name":"eth0","network":"lxdbr0"}},"profiles":["default"]}"

I think I have an idea, I would first of all use GET to return the config info, and I would then update whatever I want updated, still tinkering with how to send the payload

Edit:

Yh, that works, for future readers, you can do something like so:

$instanceInfo = $client->instances()->info('container-name');

if ($client->isSuccess()){
    $update = [
        "architecture" => $instanceInfo->metadata->architecture,
        "description" => 'container-description-here',
        "devices" => [...],
        "profiles" => ['default'],
        "config" => (array)$instanceInfo->metadata->config,
        "ephemeral" => false
    ];

    $response = $client->instances()->update('container-name', $update);
    $waitResponse = $client->operations()->wait($response->operation);
    if (isset($waitResponse->metadata->status) && strtoupper($waitResponse->metadata->status) === 'SUCCESS'){
        // success;
    }
}

Something like that, you can adapt it to your language.

1 Like