vsphere/internal/helper/virtualmachine/virtual_machine_helper.go
func FromUUID(client *govmomi.Client, uuid string) (*object.VirtualMachine, error) {
	log.Printf("[DEBUG] Locating virtual machine with UUID %q", uuid)

	ctx, cancel := context.WithTimeout(context.Background(), provider.DefaultAPITimeout)
	defer cancel()

	var result object.Reference
	var err error
	version := viapi.ParseVersionFromClient(client)
	expected := vmUUIDSearchIndexVersion
	expected.Product = version.Product
	if version.Older(expected) {
		result, err = virtualMachineFromContainerView(ctx, client, uuid)
	} else {
		result, err = virtualMachineFromSearchIndex(ctx, client, uuid)
	}

	if err != nil {
		return nil, err
	}

	// We need to filter our object through finder to ensure that the
	// InventoryPath field is populated, or else functions that depend on this
	// being present will fail.
	finder := find.NewFinder(client.Client, false)

	vm, err := finder.ObjectReference(ctx, result.Reference())
	if err != nil {
		return nil, err
	}

	// Should be safe to return here. If our reference returned here and is not a
	// VM, then we have bigger problems and to be honest we should be panicking
	// anyway.
	log.Printf("[DEBUG] VM %q found for UUID %q", vm.(*object.VirtualMachine).InventoryPath, uuid)
	return vm.(*object.VirtualMachine), nil
}
func FromUUID(client *govmomi.Client, uuid string) (*object.VirtualMachine, error) {
	log.Printf("[DEBUG] Locating virtual machine with UUID %q", uuid)

	ctx, cancel := context.WithTimeout(context.Background(), provider.DefaultAPITimeout)
	defer cancel()

	var result object.Reference
	var err error
	version := viapi.ParseVersionFromClient(client)
	expected := vmUUIDSearchIndexVersion
	expected.Product = version.Product
	if version.Older(expected) {
		result, err = virtualMachineFromContainerView(ctx, client, uuid)
	} else {
		result, err = virtualMachineFromSearchIndex(ctx, client, uuid)
	}

	if err != nil {
		return nil, err
	}

	// We need to filter our object through finder to ensure that the
	// InventoryPath field is populated, or else functions that depend on this
	// being present will fail.
	finder := find.NewFinder(client.Client, false)

	vm, err := finder.ObjectReference(ctx, result.Reference())
	if err != nil {
		return nil, err
	}

	// Should be safe to return here. If our reference returned here and is not a
	// VM, then we have bigger problems and to be honest we should be panicking
	// anyway.
	log.Printf("[DEBUG] VM %q found for UUID %q", vm.(*object.VirtualMachine).InventoryPath, uuid)
	return vm.(*object.VirtualMachine), nil
}
func FromUUID ( client * govmomi . Client , uuid string ) ( * object . VirtualMachine , error ) { log . Printf ( " " , uuid ) ctx , cancel := context . WithTimeout ( context . Background ( ) , provider . DefaultAPITimeout ) defer cancel ( ) var result object . Reference var err error version := viapi . ParseVersionFromClient ( client ) expected := vmUUIDSearchIndexVersion expected . Product = version . Product if version . Older ( expected ) { result , err = virtualMachineFromContainerView ( ctx , client , uuid ) } else { result , err = virtualMachineFromSearchIndex ( ctx , client , uuid ) } if err != nil { return nil , err } // We need to filter our object through finder to ensure that the // InventoryPath field is populated, or else functions that depend on this // being present will fail. finder := find . NewFinder ( client . Client , false ) vm , err := finder . ObjectReference ( ctx , result . Reference ( ) ) if err != nil { return nil , err } // Should be safe to return here. If our reference returned here and is not a // VM, then we have bigger problems and to be honest we should be panicking // anyway. log . Printf ( " " , vm . ( * object . VirtualMachine ) . InventoryPath , uuid ) return vm . ( * object . VirtualMachine ) , nil }
// FromUUID locates a virtualMachine by its UUID.
FromUUID locates a virtualMachine by its UUID .