本文整理汇总了Golang中github.com/lxc/lxd.Client.NetworkPut方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.NetworkPut方法的具体用法?Golang Client.NetworkPut怎么用?Golang Client.NetworkPut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lxc/lxd.Client
的用法示例。
在下文中一共展示了Client.NetworkPut方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doNetworkSet
func (c *networkCmd) doNetworkSet(client *lxd.Client, name string, args []string) error {
// we shifted @args so so it should read "<key> [<value>]"
if len(args) < 1 {
return errArgs
}
network, err := client.NetworkGet(name)
if err != nil {
return err
}
key := args[0]
var value string
if len(args) < 2 {
value = ""
} else {
value = args[1]
}
if !termios.IsTerminal(int(syscall.Stdin)) && value == "-" {
buf, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("Can't read from stdin: %s", err)
}
value = string(buf[:])
}
network.Config[key] = value
return client.NetworkPut(name, network)
}
示例2: doNetworkEdit
func (c *networkCmd) doNetworkEdit(client *lxd.Client, name string) error {
// If stdin isn't a terminal, read text from it
if !termios.IsTerminal(int(syscall.Stdin)) {
contents, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
newdata := shared.NetworkConfig{}
err = yaml.Unmarshal(contents, &newdata)
if err != nil {
return err
}
return client.NetworkPut(name, newdata)
}
// Extract the current value
network, err := client.NetworkGet(name)
if err != nil {
return err
}
data, err := yaml.Marshal(&network)
if err != nil {
return err
}
// Spawn the editor
content, err := shared.TextEditor("", []byte(c.networkEditHelp()+"\n\n"+string(data)))
if err != nil {
return err
}
for {
// Parse the text received from the editor
newdata := shared.NetworkConfig{}
err = yaml.Unmarshal(content, &newdata)
if err == nil {
err = client.NetworkPut(name, 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 open 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
}