本文整理汇总了Golang中github.com/vmware/govmomi/object.Folder.Children方法的典型用法代码示例。如果您正苦于以下问题:Golang Folder.Children方法的具体用法?Golang Folder.Children怎么用?Golang Folder.Children使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/govmomi/object.Folder
的用法示例。
在下文中一共展示了Folder.Children方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deleteFolder
func deleteFolder(client *govmomi.Client, f *folder) error {
dc, err := getDatacenter(client, f.datacenter)
if err != nil {
return err
}
var folder *object.Folder
currentPath := f.path
finder := find.NewFinder(client.Client, true)
finder = finder.SetDatacenter(dc)
si := object.NewSearchIndex(client.Client)
folderRef, err := si.FindByInventoryPath(
context.TODO(), fmt.Sprintf("%v/vm/%v", f.datacenter, f.path))
if err != nil {
return fmt.Errorf("[ERROR] Could not locate folder %s: %v", f.path, err)
} else {
folder = folderRef.(*object.Folder)
}
log.Printf("[INFO] Deleting empty sub-folders of existing path: %s", f.existingPath)
for currentPath != f.existingPath {
log.Printf("[INFO] Deleting folder: %s", currentPath)
children, err := folder.Children(context.TODO())
if err != nil {
return err
}
if len(children) > 0 {
return fmt.Errorf("Folder %s is non-empty and will not be deleted", currentPath)
} else {
log.Printf("[DEBUG] current folder: %#v", folder)
currentPath = path.Dir(currentPath)
if currentPath == "." {
currentPath = ""
}
log.Printf("[INFO] parent path of %s is calculated as %s", f.path, currentPath)
task, err := folder.Destroy(context.TODO())
if err != nil {
return err
}
err = task.Wait(context.TODO())
if err != nil {
return err
}
folderRef, err = si.FindByInventoryPath(
context.TODO(), fmt.Sprintf("%v/vm/%v", f.datacenter, currentPath))
if err != nil {
return err
} else if folderRef != nil {
folder = folderRef.(*object.Folder)
}
}
}
return nil
}
示例2: findSwitchesInFolder
func (f *Finder) findSwitchesInFolder(ctx context.Context, folder *object.Folder) []object.DistributedVirtualSwitch {
var switches []object.DistributedVirtualSwitch
if children, err := folder.Children(ctx); err == nil {
for _, j := range children {
if j.Reference().Type == "VmwareDistributedVirtualSwitch" {
switches = append(switches, *object.NewDistributedVirtualSwitch(f.client, j.Reference()))
}
if j.Reference().Type == "Folder" {
switches2 := f.findSwitchesInFolder(ctx, object.NewFolder(f.client, j.Reference()))
for _, k := range switches2 {
switches = append(switches, k)
}
}
}
} else {
fmt.Printf("Error getting switches! %v\n", err)
}
return switches
}