本文整理汇总了Golang中github.com/lxc/lxd.Client.ContainerDeviceDelete方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.ContainerDeviceDelete方法的具体用法?Golang Client.ContainerDeviceDelete怎么用?Golang Client.ContainerDeviceDelete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lxc/lxd.Client
的用法示例。
在下文中一共展示了Client.ContainerDeviceDelete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doNetworkDetach
func (c *networkCmd) doNetworkDetach(client *lxd.Client, name string, args []string) error {
if len(args) < 1 || len(args) > 2 {
return errArgs
}
containerName := args[0]
devName := ""
if len(args) > 1 {
devName = args[1]
}
container, err := client.ContainerInfo(containerName)
if err != nil {
return err
}
if devName == "" {
for n, d := range container.Devices {
if d["type"] == "nic" && d["parent"] == name {
if devName != "" {
return fmt.Errorf(i18n.G("More than one device matches, specify the device name."))
}
devName = n
}
}
}
if devName == "" {
return fmt.Errorf(i18n.G("No device found for this network"))
}
device, ok := container.Devices[devName]
if !ok {
return fmt.Errorf(i18n.G("The specified device doesn't exist"))
}
if device["type"] != "nic" || device["parent"] != name {
return fmt.Errorf(i18n.G("The specified device doesn't match the network"))
}
resp, err := client.ContainerDeviceDelete(containerName, devName)
if err != nil {
return err
}
return client.WaitForSuccess(resp.Operation)
}