当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.UpdateContainerConfig方法代码示例

本文整理汇总了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
}
开发者ID:vahe,项目名称:lxd,代码行数:30,代码来源:profile.go

示例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
}
开发者ID:vahe,项目名称:lxd,代码行数:17,代码来源:profile.go

示例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
}
开发者ID:rrva,项目名称:lxd,代码行数:76,代码来源:config.go

示例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
}
开发者ID:HPCNow,项目名称:lxd,代码行数:62,代码来源:config.go

示例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
}
开发者ID:nsec,项目名称:the-internet,代码行数:101,代码来源:cmd_create.go


注:本文中的github.com/lxc/lxd.Client.UpdateContainerConfig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。