本文整理汇总了Golang中github.com/lxc/lxd.Client.UpdateContainerConfig方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.UpdateContainerConfig方法的具体用法?Golang Client.UpdateContainerConfig怎么用?Golang Client.UpdateContainerConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lxc/lxd.Client
的用法示例。
在下文中一共展示了Client.UpdateContainerConfig方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doProfileRemove
func (c *profileCmd) doProfileRemove(client *lxd.Client, d string, p string) error {
ct, err := client.ContainerInfo(d)
if err != nil {
return err
}
if !shared.StringInSlice(p, ct.Profiles) {
return fmt.Errorf("Profile %s isn't currently applied to %s", p, d)
}
profiles := []string{}
for _, profile := range ct.Profiles {
if profile == p {
continue
}
profiles = append(profiles, profile)
}
ct.Profiles = profiles
err = client.UpdateContainerConfig(d, ct.Brief())
if err != nil {
return err
}
fmt.Printf(i18n.G("Profile %s removed from %s")+"\n", p, d)
return err
}
示例2: doProfileAdd
func (c *profileCmd) doProfileAdd(client *lxd.Client, d string, p string) error {
ct, err := client.ContainerInfo(d)
if err != nil {
return err
}
ct.Profiles = append(ct.Profiles, p)
err = client.UpdateContainerConfig(d, ct.Brief())
if err != nil {
return err
}
fmt.Printf(i18n.G("Profile %s added to %s")+"\n", p, d)
return err
}
示例3: doConfigEdit
func doConfigEdit(client *lxd.Client, cont string) error {
if !terminal.IsTerminal(syscall.Stdin) {
contents, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
newdata := shared.BriefContainerState{}
err = yaml.Unmarshal(contents, &newdata)
if err != nil {
return err
}
return client.UpdateContainerConfig(cont, newdata)
}
config, err := client.ContainerStatus(cont, false)
if err != nil {
return err
}
brief := config.BriefState()
editor := os.Getenv("VISUAL")
if editor == "" {
editor = os.Getenv("EDITOR")
if editor == "" {
editor = "vi"
}
}
data, err := yaml.Marshal(&brief)
f, err := ioutil.TempFile("", "lxd_lxc_config_")
if err != nil {
return err
}
fname := f.Name()
if err = f.Chmod(0600); err != nil {
f.Close()
os.Remove(fname)
return err
}
f.Write([]byte(configEditHelp))
f.Write(data)
f.Close()
defer os.Remove(fname)
for {
cmdParts := strings.Fields(editor)
cmd := exec.Command(cmdParts[0], append(cmdParts[1:], fname)...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
return err
}
contents, err := ioutil.ReadFile(fname)
if err != nil {
return err
}
newdata := shared.BriefContainerState{}
err = yaml.Unmarshal(contents, &newdata)
if err != nil {
fmt.Fprintf(os.Stderr, gettext.Gettext("YAML parse error %v\n"), err)
fmt.Printf("Press enter to play again ")
_, err := os.Stdin.Read(make([]byte, 1))
if err != nil {
return err
}
continue
}
err = client.UpdateContainerConfig(cont, newdata)
break
}
return err
}
示例4: doConfigEdit
func doConfigEdit(client *lxd.Client, cont string) error {
// If stdin isn't a terminal, read text from it
if !terminal.IsTerminal(int(syscall.Stdin)) {
contents, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
newdata := shared.BriefContainerState{}
err = yaml.Unmarshal(contents, &newdata)
if err != nil {
return err
}
return client.UpdateContainerConfig(cont, newdata)
}
// Extract the current value
config, err := client.ContainerStatus(cont)
if err != nil {
return err
}
brief := config.BriefState()
data, err := yaml.Marshal(&brief)
if err != nil {
return err
}
// Spawn the editor
content, err := shared.TextEditor("", []byte(configEditHelp+"\n\n"+string(data)))
if err != nil {
return err
}
for {
// Parse the text received from the editor
newdata := shared.BriefContainerState{}
err = yaml.Unmarshal(content, &newdata)
if err == nil {
err = client.UpdateContainerConfig(cont, newdata)
}
// Respawn the editor
if err != nil {
fmt.Fprintf(os.Stderr, i18n.G("Config parsing error: %s")+"\n", err)
fmt.Println(i18n.G("Press enter to start the editor again"))
_, err := os.Stdin.Read(make([]byte, 1))
if err != nil {
return err
}
content, err = shared.TextEditor("", content)
if err != nil {
return err
}
continue
}
break
}
return nil
}
示例5: cmdCreate
//.........这里部分代码省略.........
for _, p := range router.Peers {
if p.ASN != 0 {
bgpd += fmt.Sprintf(" neighbor %s activate\n", p.Remote)
}
}
}
bgpd += ` redistribute connected
redistribute kernel
exit-address-family
`
config["user.internet.config.interfaces"] = interfaces
config["user.internet.config.bgpd"] = bgpd
}
// Config-only containers
if router.Tier > 3 {
ct, err := c.ContainerInfo(router.Name)
if err != nil {
logf("Failed to configure container '%s': %s", router.Name, err)
return
}
for k, _ := range ct.Config {
if strings.HasPrefix(k, "user.internet.") {
delete(ct.Config, k)
}
}
for k, v := range config {
ct.Config[k] = v
}
err = c.UpdateContainerConfig(router.Name, ct.Writable())
if err != nil {
logf("Failed to configure container '%s': %s", router.Name, err)
return
}
return
}
// Create the container
resp, err := c.Init(router.Name, "local", "internet-router", &[]string{"internet-base"}, config, nil, false)
if err != nil {
logf("Failed to create container '%s': %s", router.Name, err)
return
}
err = c.WaitForSuccess(resp.Operation)
if err != nil {
logf("Failed to create container '%s': %s", router.Name, err)
return
}
// Setup the devices
ct, err := c.ContainerInfo(router.Name)
if err != nil {
logf("Failed to configure container '%s': %s", router.Name, err)
return
}
for k, v := range devices {
ct.Devices[k] = v
}
err = c.UpdateContainerConfig(router.Name, ct.Writable())
if err != nil {
logf("Failed to configure container '%s': %s", router.Name, err)
return
}
}
// Create the containers
batch := 8
batches := len(routers) / batch
remainder := len(routers) % batch
logf("Creating the containers")
current := 0
for i := 0; i < batches; i++ {
for j := 0; j < batch; j++ {
wgBatch.Add(1)
go createContainer(routers[current])
current += 1
}
wgBatch.Wait()
}
for k := 0; k < remainder; k++ {
wgBatch.Add(1)
go createContainer(routers[current])
current += 1
}
wgBatch.Wait()
logf("%d containers created", len(routers))
return nil
}