• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang find.NewFinder函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/vmware/govmomi/find.NewFinder函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFinder函数的具体用法?Golang NewFinder怎么用?Golang NewFinder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewFinder函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: testAccCheckVSphereVirtualMachineExists

func testAccCheckVSphereVirtualMachineExists(n string, vm *virtualMachine) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		rs, ok := s.RootModule().Resources[n]
		if !ok {
			return fmt.Errorf("Not found: %s", n)
		}

		if rs.Primary.ID == "" {
			return fmt.Errorf("No ID is set")
		}

		client := testAccProvider.Meta().(*govmomi.Client)
		finder := find.NewFinder(client.Client, true)

		dc, err := finder.Datacenter(context.TODO(), rs.Primary.Attributes["datacenter"])
		if err != nil {
			return fmt.Errorf("error %s", err)
		}

		dcFolders, err := dc.Folders(context.TODO())
		if err != nil {
			return fmt.Errorf("error %s", err)
		}

		_, err = object.NewSearchIndex(client.Client).FindChild(context.TODO(), dcFolders.VmFolder, rs.Primary.Attributes["name"])

		*vm = virtualMachine{
			name: rs.Primary.ID,
		}

		return nil
	}
}
开发者ID:morts1a,项目名称:terraform,代码行数:33,代码来源:resource_vsphere_virtual_machine_test.go


示例2: Finder

func (flag *DatacenterFlag) Finder() (*find.Finder, error) {
	if flag.finder != nil {
		return flag.finder, nil
	}

	c, err := flag.Client()
	if err != nil {
		return nil, err
	}

	finder := find.NewFinder(c, flag.JSON || flag.Dump)

	// Datacenter is not required (ls command for example).
	// Set for relative func if dc flag is given or
	// if there is a single (default) Datacenter
	if flag.path == "" {
		flag.dc, flag.err = finder.DefaultDatacenter(context.TODO())
	} else {
		if flag.dc, err = finder.Datacenter(context.TODO(), flag.path); err != nil {
			return nil, err
		}
	}

	finder.SetDatacenter(flag.dc)

	flag.finder = finder

	return flag.finder, nil
}
开发者ID:hmahmood,项目名称:govmomi,代码行数:29,代码来源:datacenter.go


示例3: testAccVSphereVirtualDiskExists

func testAccVSphereVirtualDiskExists(name string) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		rs, ok := s.RootModule().Resources[name]
		if !ok {
			return fmt.Errorf("Not found: %s", name)
		}
		if rs.Primary.ID == "" {
			return fmt.Errorf("No ID is set")
		}

		client := testAccProvider.Meta().(*govmomi.Client)
		finder := find.NewFinder(client.Client, true)

		dc, err := finder.Datacenter(context.TODO(), rs.Primary.Attributes["datacenter"])
		if err != nil {
			return fmt.Errorf("error %s", err)
		}
		finder = finder.SetDatacenter(dc)

		ds, err := finder.Datastore(context.TODO(), rs.Primary.Attributes["datastore"])
		if err != nil {
			return fmt.Errorf("error %s", err)
		}

		_, err = ds.Stat(context.TODO(), rs.Primary.Attributes["vmdk_path"])
		if err != nil {
			return fmt.Errorf("error %s", err)
		}

		return nil
	}
}
开发者ID:Zordrak,项目名称:terraform,代码行数:32,代码来源:resource_vsphere_virtual_disk_test.go


示例4: testAccCheckVSphereVirtualDiskDestroy

func testAccCheckVSphereVirtualDiskDestroy(s *terraform.State) error {
	log.Printf("[FINDME] test Destroy")
	client := testAccProvider.Meta().(*govmomi.Client)
	finder := find.NewFinder(client.Client, true)

	for _, rs := range s.RootModule().Resources {
		if rs.Type != "vsphere_virtual_disk" {
			continue
		}

		dc, err := finder.Datacenter(context.TODO(), rs.Primary.Attributes["datacenter"])
		if err != nil {
			return fmt.Errorf("error %s", err)
		}

		finder = finder.SetDatacenter(dc)

		ds, err := finder.Datastore(context.TODO(), rs.Primary.Attributes["datastore"])
		if err != nil {
			return fmt.Errorf("error %s", err)
		}

		_, err = ds.Stat(context.TODO(), rs.Primary.Attributes["vmdk_path"])
		if err == nil {
			return fmt.Errorf("error %s", err)
		}
	}

	return nil
}
开发者ID:Zordrak,项目名称:terraform,代码行数:30,代码来源:resource_vsphere_virtual_disk_test.go


示例5: testAccCheckVSphereVirtualMachineDestroy

func testAccCheckVSphereVirtualMachineDestroy(s *terraform.State) error {
	client := testAccProvider.Meta().(*govmomi.Client)
	finder := find.NewFinder(client.Client, true)

	for _, rs := range s.RootModule().Resources {
		if rs.Type != "vsphere_virtual_machine" {
			continue
		}

		dc, err := finder.Datacenter(context.TODO(), rs.Primary.Attributes["datacenter"])
		if err != nil {
			return fmt.Errorf("error %s", err)
		}

		dcFolders, err := dc.Folders(context.TODO())
		if err != nil {
			return fmt.Errorf("error %s", err)
		}

		_, err = object.NewSearchIndex(client.Client).FindChild(context.TODO(), dcFolders.VmFolder, rs.Primary.Attributes["name"])
		if err == nil {
			return fmt.Errorf("Record still exists")
		}
	}

	return nil
}
开发者ID:semarj,项目名称:terraform,代码行数:27,代码来源:resource_vsphere_virtual_machine_test.go


示例6: createFile

func createFile(client *govmomi.Client, f *file) error {

	finder := find.NewFinder(client.Client, true)

	dc, err := finder.Datacenter(context.TODO(), f.datacenter)
	if err != nil {
		return fmt.Errorf("error %s", err)
	}
	finder = finder.SetDatacenter(dc)

	ds, err := getDatastore(finder, f.datastore)
	if err != nil {
		return fmt.Errorf("error %s", err)
	}

	dsurl, err := ds.URL(context.TODO(), dc, f.destinationFile)
	if err != nil {
		return err
	}

	p := soap.DefaultUpload
	err = client.Client.UploadFile(f.sourceFile, dsurl, &p)
	if err != nil {
		return fmt.Errorf("error %s", err)
	}
	return nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:27,代码来源:resource_vsphere_file.go


示例7: testAccCheckVSphereFolderExistingPathExists

func testAccCheckVSphereFolderExistingPathExists(n string, f *folder) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		rs, ok := s.RootModule().Resources[n]
		if !ok {
			return fmt.Errorf("Resource %s not found in %#v", n, s.RootModule().Resources)
		}

		if rs.Primary.ID == "" {
			return fmt.Errorf("No ID is set")
		}

		client := testAccProvider.Meta().(*govmomi.Client)
		finder := find.NewFinder(client.Client, true)

		dc, err := finder.Datacenter(context.TODO(), rs.Primary.Attributes["datacenter"])
		if err != nil {
			return fmt.Errorf("error %s", err)
		}

		dcFolders, err := dc.Folders(context.TODO())
		if err != nil {
			return fmt.Errorf("error %s", err)
		}

		_, err = object.NewSearchIndex(client.Client).FindChild(context.TODO(), dcFolders.VmFolder, rs.Primary.Attributes["existing_path"])

		*f = folder{
			path: rs.Primary.Attributes["path"],
		}

		return nil
	}
}
开发者ID:AssertSelenium,项目名称:terraform,代码行数:33,代码来源:resource_vsphere_folder_test.go


示例8: getVirtualMachineDevices

// Returns vSphere objects virtual machine, virtual device list, datastore and datacenter.
func getVirtualMachineDevices(cfg *VSphereConfig, ctx context.Context, c *govmomi.Client, name string) (*object.VirtualMachine, object.VirtualDeviceList, *object.Datastore, *object.Datacenter, error) {
	// Create a new finder
	f := find.NewFinder(c.Client, true)

	// Fetch and set data center
	dc, err := f.Datacenter(ctx, cfg.Global.Datacenter)
	if err != nil {
		return nil, nil, nil, nil, err
	}
	f.SetDatacenter(dc)

	// Find datastores
	ds, err := f.Datastore(ctx, cfg.Global.Datastore)
	if err != nil {
		return nil, nil, nil, nil, err
	}

	vmRegex := cfg.Global.WorkingDir + name

	vm, err := f.VirtualMachine(ctx, vmRegex)
	if err != nil {
		return nil, nil, nil, nil, err
	}

	// Get devices from VM
	vmDevices, err := vm.Device(ctx)
	if err != nil {
		return nil, nil, nil, nil, err
	}
	return vm, vmDevices, ds, dc, nil
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:32,代码来源:vsphere.go


示例9: deleteFile

func deleteFile(client *govmomi.Client, f *file) error {

	dc, err := getDatacenter(client, f.datacenter)
	if err != nil {
		return err
	}

	finder := find.NewFinder(client.Client, true)
	finder = finder.SetDatacenter(dc)

	ds, err := getDatastore(finder, f.datastore)
	if err != nil {
		return fmt.Errorf("error %s", err)
	}

	fm := object.NewFileManager(client.Client)
	task, err := fm.DeleteDatastoreFile(context.TODO(), ds.Path(f.destinationFile), dc)
	if err != nil {
		return err
	}

	_, err = task.WaitForResult(context.TODO(), nil)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:27,代码来源:resource_vsphere_file.go


示例10: waitForNetworkingActive

func waitForNetworkingActive(client *govmomi.Client, datacenter, name string) resource.StateRefreshFunc {
	return func() (interface{}, string, error) {
		dc, err := getDatacenter(client, datacenter)
		if err != nil {
			log.Printf("[ERROR] %#v", err)
			return nil, "", err
		}
		finder := find.NewFinder(client.Client, true)
		finder = finder.SetDatacenter(dc)

		vm, err := finder.VirtualMachine(context.TODO(), name)
		if err != nil {
			log.Printf("[ERROR] %#v", err)
			return nil, "", err
		}

		var mvm mo.VirtualMachine
		collector := property.DefaultCollector(client.Client)
		if err := collector.RetrieveOne(context.TODO(), vm.Reference(), []string{"summary"}, &mvm); err != nil {
			log.Printf("[ERROR] %#v", err)
			return nil, "", err
		}

		if mvm.Summary.Guest.IpAddress != "" {
			log.Printf("[DEBUG] IP address with DHCP: %v", mvm.Summary.Guest.IpAddress)
			return mvm.Summary, "active", err
		} else {
			log.Printf("[DEBUG] Waiting for IP address")
			return nil, "pending", err
		}
	}
}
开发者ID:mafrosis,项目名称:terraform,代码行数:32,代码来源:resource_vsphere_virtual_machine.go


示例11: DeleteVolume

// DeleteVolume deletes a volume given volume name.
func (vs *VSphere) DeleteVolume(vmDiskPath string) error {
	// Create context
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// Create vSphere client
	c, err := vsphereLogin(vs.cfg, ctx)
	if err != nil {
		return err
	}
	defer c.Logout(ctx)

	// Create a new finder
	f := find.NewFinder(c.Client, true)

	// Fetch and set data center
	dc, err := f.Datacenter(ctx, vs.cfg.Global.Datacenter)
	f.SetDatacenter(dc)

	// Create a virtual disk manager
	virtualDiskManager := object.NewVirtualDiskManager(c.Client)

	// Delete virtual disk
	task, err := virtualDiskManager.DeleteVirtualDisk(ctx, vmDiskPath, dc)
	if err != nil {
		return err
	}

	return task.Wait(ctx)
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:31,代码来源:vsphere.go


示例12: findVM

func (vmh *VMHost) findVM(targetMACAddress string) (vm *object.VirtualMachine, err error) {

	targetMACAddress = strings.ToUpper(targetMACAddress)
	f := find.NewFinder(vmh.client.Client, true)
	allDatacenters, err := f.DatacenterList(vmh.Ctx, "*")
	if err != nil {
		return nil, errors.New("Could not get List of Datacenters")
	}

	for _, datacenter := range allDatacenters {
		f.SetDatacenter(datacenter)
		allVMs, err := f.VirtualMachineList(vmh.Ctx, "*")
		if err != nil {
			return nil, errors.New("Could not get List of VMs")
		}
		for _, vm := range allVMs {
			VM_MAC, err := vmh.getMACAddressOfVM(vm)
			VM_MAC = strings.ToUpper(VM_MAC)
			if err != nil {
				return nil, errors.New("Could not get MAC Address of VM")
			}
			if VM_MAC == targetMACAddress {
				return vm, nil
			}
		}
	}
	return nil, errors.New("Could not find VM with specified MAC Address of " + targetMACAddress)
}
开发者ID:zhaog918,项目名称:govmax,代码行数:28,代码来源:vmomi.go


示例13: Run

func (cmd *destroy) Run(ctx context.Context, f *flag.FlagSet) error {
	if f.NArg() == 0 {
		return flag.ErrHelp
	}

	client, err := cmd.ClientFlag.Client()
	if err != nil {
		return err
	}

	finder := find.NewFinder(client, false)

	for _, path := range f.Args() {
		dcs, err := finder.DatacenterList(ctx, path)
		if err != nil {
			return err
		}

		for _, dc := range dcs {
			task, err := dc.Destroy(ctx)
			if err != nil {
				return err
			}

			if err := task.Wait(ctx); err != nil {
				return err
			}
		}
	}

	return nil
}
开发者ID:frapposelli,项目名称:govmomi,代码行数:32,代码来源:destroy.go


示例14: DeleteVolume

// DeleteVolume deletes a volume given volume name.
func (vs *VSphere) DeleteVolume(vmDiskPath string) error {
	// Create context
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// Ensure client is logged in and session is valid
	err := vSphereLogin(vs, ctx)
	if err != nil {
		glog.Errorf("Failed to login into vCenter - %v", err)
		return err
	}

	// Create a new finder
	f := find.NewFinder(vs.client.Client, true)

	// Fetch and set data center
	dc, err := f.Datacenter(ctx, vs.cfg.Global.Datacenter)
	f.SetDatacenter(dc)

	// Create a virtual disk manager
	virtualDiskManager := object.NewVirtualDiskManager(vs.client.Client)

	// Delete virtual disk
	task, err := virtualDiskManager.DeleteVirtualDisk(ctx, vmDiskPath, dc)
	if err != nil {
		return err
	}

	return task.Wait(ctx)
}
开发者ID:nak3,项目名称:kubernetes,代码行数:31,代码来源:vsphere.go


示例15: Folder

func (cmd *ovf) Folder() (*object.Folder, error) {
	if len(cmd.folder) == 0 {
		folders, err := cmd.Datacenter.Folders(context.TODO())
		if err != nil {
			return nil, err
		}
		return folders.VmFolder, nil
	} else {
		finder := find.NewFinder(cmd.Client, false)

		mo, err := finder.ManagedObjectList(context.TODO(), cmd.folder)
		if err != nil {
			return nil, err
		}
		if len(mo) == 0 {
			return nil, errors.New("folder does not resolve to object")
		}
		if len(mo) > 1 {
			return nil, errors.New("folder resolves to more than one object")
		}

		ref := mo[0].Object.Reference()
		if ref.Type != "Folder" {
			return nil, errors.New("folder does not resolve to folder")
		}

		return object.NewFolder(cmd.Client, ref), nil
	}
}
开发者ID:pratikvgupta,项目名称:govmomi,代码行数:29,代码来源:ovf.go


示例16: Run

func (cmd *destroy) Run(ctx context.Context, f *flag.FlagSet) error {
	if len(f.Args()) < 1 {
		return flag.ErrHelp
	}
	datacentersToDestroy := f.Args()

	client, err := cmd.ClientFlag.Client()
	if err != nil {
		return err
	}

	finder := find.NewFinder(client, false)
	for _, datacenterToDestroy := range datacentersToDestroy {
		foundDatacenters, err := finder.DatacenterList(context.TODO(), datacenterToDestroy)
		if err != nil {
			return err
		}
		for _, foundDatacenter := range foundDatacenters {
			task, err := foundDatacenter.Destroy(context.TODO())
			if err != nil {
				return err
			}

			if err := task.Wait(context.TODO()); err != nil {
				return err
			}
		}
	}
	return nil
}
开发者ID:robvanmieghem,项目名称:machine,代码行数:30,代码来源:destroy.go


示例17: createAndAttachDisk

func createAndAttachDisk(t *testing.T, vmName string, size int, datastore string, diskPath string, diskType string, adapterType string, datacenter string) {
	client := testAccProvider.Meta().(*govmomi.Client)
	finder := find.NewFinder(client.Client, true)

	dc, err := finder.Datacenter(context.TODO(), datacenter)
	if err != nil {
		log.Printf("[ERROR] finding Datacenter %s: %v", datacenter, err)
		t.Fail()
		return
	}
	finder = finder.SetDatacenter(dc)
	ds, err := getDatastore(finder, datastore)
	if err != nil {
		log.Printf("[ERROR] getDatastore %s: %v", datastore, err)
		t.Fail()
		return
	}
	vm, err := finder.VirtualMachine(context.TODO(), vmName)
	if err != nil {
		log.Printf("[ERROR] finding VM %s: %v", vmName, err)
		t.Fail()
		return
	}
	err = addHardDisk(vm, int64(size), int64(0), diskType, ds, diskPath, adapterType)
	if err != nil {
		log.Printf("[ERROR] addHardDisk: %v", err)
		t.Fail()
		return
	}
}
开发者ID:paultyng,项目名称:terraform,代码行数:30,代码来源:resource_vsphere_virtual_machine_test.go


示例18: Run

func (cmd *create) Run(f *flag.FlagSet) error {
	datacenters := f.Args()
	if len(datacenters) < 1 {
		return flag.ErrHelp
	}

	client, err := cmd.ClientFlag.Client()
	if err != nil {
		return err
	}

	finder := find.NewFinder(client, false)
	rootFolder := object.NewRootFolder(client)
	for _, datacenterToCreate := range datacenters {
		_, err := finder.Datacenter(context.TODO(), datacenterToCreate)
		if err == nil {
			// The datacenter was found, no need to create it
			continue
		}

		switch err.(type) {
		case *find.NotFoundError:
			_, err = rootFolder.CreateDatacenter(context.TODO(), datacenterToCreate)
			if err != nil {
				return err
			}
		default:
			return err
		}
	}

	return nil
}
开发者ID:kristinn,项目名称:govmomi,代码行数:33,代码来源:create.go


示例19: resourceVSphereFolderRead

func resourceVSphereFolderRead(d *schema.ResourceData, meta interface{}) error {

	log.Printf("[DEBUG] reading folder: %#v", d)
	client := meta.(*govmomi.Client)

	dc, err := getDatacenter(client, d.Get("datacenter").(string))
	if err != nil {
		return err
	}

	finder := find.NewFinder(client.Client, true)
	finder = finder.SetDatacenter(dc)

	folder, err := object.NewSearchIndex(client.Client).FindByInventoryPath(
		context.TODO(), fmt.Sprintf("%v/vm/%v", d.Get("datacenter").(string),
			d.Get("path").(string)))

	if err != nil {
		return err
	}

	if folder == nil {
		d.SetId("")
	}

	return nil
}
开发者ID:devendraPSL,项目名称:terraform-api,代码行数:27,代码来源:resource_vsphere_folder.go


示例20: Init

func Init(ctx context.Context, sess *session.Session, source extraconfig.DataSource, sink extraconfig.DataSink) error {
	trace.End(trace.Begin(""))

	initializer.once.Do(func() {
		var err error
		defer func() {
			initializer.err = err
		}()

		f := find.NewFinder(sess.Vim25(), false)

		var config Configuration
		config.sink = sink
		config.source = source
		config.Decode()
		config.PortGroups = make(map[string]object.NetworkReference)

		log.Debugf("Decoded VCH config for network: %#v", config)
		for nn, n := range config.ContainerNetworks {
			pgref := new(types.ManagedObjectReference)
			if !pgref.FromString(n.ID) {
				log.Warnf("Could not reacquire object reference from id for network %s: %s", nn, n.ID)
			}

			var r object.Reference
			if r, err = f.ObjectReference(ctx, *pgref); err != nil {
				log.Warnf("could not get network reference for %s network: %s", nn, err)
				err = nil
				continue
			}

			config.PortGroups[nn] = r.(object.NetworkReference)
		}

		// make sure a NIC attached to the bridge network exists
		config.BridgeLink, err = getBridgeLink(&config)
		if err != nil {
			return
		}

		var kv kvstore.KeyValueStore
		kv, err = store.NewDatastoreKeyValue(ctx, sess, "network.contexts.default")
		if err != nil {
			return
		}

		var netctx *Context
		if netctx, err = NewContext(&config, kv); err != nil {
			return
		}

		if err = engageContext(ctx, netctx, exec.Config.EventManager); err == nil {
			DefaultContext = netctx
			log.Infof("Default network context allocated")
		}
	})

	return initializer.err
}
开发者ID:vmware,项目名称:vic,代码行数:59,代码来源:network.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang find.Finder类代码示例发布时间:2022-05-28
下一篇:
Golang govmomi.NewClient函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap