lxc / go-lxc

Go bindings for liblxc
https://linuxcontainers.org/lxc
Other
431 stars 76 forks source link

SetConfigItem creates duplicate entries #56

Closed ranjib closed 8 years ago

ranjib commented 8 years ago

I am trying to use the SetConfigItem api call to change hostname of a container, and I noticed that this results in multiple lxc.utsname entries in the config file. I tried using the ClearConfigItem, but thats failing with "cant clear cgroup item" error message,

package main

import (
  "fmt"
  "gopkg.in/lxc/go-lxc.v2"
  "os"
)

func main() {
  lxcpath := lxc.DefaultConfigPath()
  ct, err := lxc.NewContainer("test", lxcpath)
  if err != nil {
    fmt.Println(err)
    os.Exit(1)
  }
  /*
    if err := ct.ClearConfigItem("lxc.utsname"); err != nil {
      fmt.Println("Clear config")
      fmt.Println(err)
      os.Exit(1)
    } 
  */
  if err := ct.SetConfigItem("lxc.utsname", "foo"); err != nil { 
    fmt.Println("Set config")
    fmt.Println(err)
    os.Exit(1)
  } 

  fmt.Println(ct.ConfigFileName())
  if err := ct.SaveConfigFile(ct.ConfigFileName()); err != nil {
    fmt.Println("Save config")
    fmt.Println(err)
    os.Exit(1)
  }
} 
ranjib commented 8 years ago

@caglar10ur @tych0 @stgraber bump.

stgraber commented 8 years ago

That sounds like expected behavior, sure isn't ideal but it's what the config management code in LXC will indeed do.

Only the last value is used for keys that aren't lists so we just keep appending as doing something else becomes tricky for complex configs which include a bunch of includes.

Certainly isn't pretty but it gets you a valid config nonetheless