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


Golang Folder.Children方法代码示例

本文整理汇总了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
}
开发者ID:devendraPSL,项目名称:terraform-api,代码行数:58,代码来源:resource_vsphere_folder.go

示例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
}
开发者ID:gonkulator,项目名称:govmomi,代码行数:19,代码来源:finder.go


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