func CloneVM(
	client *govmomi.Client,
	src *object.VirtualMachine,
	fo *object.Folder,
	name string,
	spec types.VirtualMachineCloneSpec,
	timeout int,
	pod *object.StoragePod,
) (*object.VirtualMachine, error) {
	sdrsEnabled, err := StorageDRSEnabled(pod)
	if err != nil {
		return nil, err
	}
	if !sdrsEnabled {
		return nil, fmt.Errorf("storage DRS is not enabled on datastore cluster %q", pod.Name())
	}
	log.Printf(
		"[DEBUG] Cloning virtual machine %q to %q on datastore cluster %q",
		src.InventoryPath,
		fmt.Sprintf("%s/%s", fo.InventoryPath, name),
		pod.Name(),
	)

	sps := types.StoragePlacementSpec{
		Folder:    types.NewReference(fo.Reference()),
		Vm:        types.NewReference(src.Reference()),
		CloneName: name,
		CloneSpec: &spec,
		PodSelectionSpec: types.StorageDrsPodSelectionSpec{
			StoragePod: types.NewReference(pod.Reference()),
		},
		Type: string(types.StoragePlacementSpecPlacementTypeClone),
	}

	return recommendAndApplySDRS(client, sps, time.Minute*time.Duration(timeout))
}
func CloneVM(
	client *govmomi.Client,
	src *object.VirtualMachine,
	fo *object.Folder,
	name string,
	spec types.VirtualMachineCloneSpec,
	timeout int,
	pod *object.StoragePod,
) (*object.VirtualMachine, error) {
	sdrsEnabled, err := StorageDRSEnabled(pod)
	if err != nil {
		return nil, err
	}
	if !sdrsEnabled {
		return nil, fmt.Errorf("storage DRS is not enabled on datastore cluster %q", pod.Name())
	}
	log.Printf(
		"[DEBUG] Cloning virtual machine %q to %q on datastore cluster %q",
		src.InventoryPath,
		fmt.Sprintf("%s/%s", fo.InventoryPath, name),
		pod.Name(),
	)

	sps := types.StoragePlacementSpec{
		Folder:    types.NewReference(fo.Reference()),
		Vm:        types.NewReference(src.Reference()),
		CloneName: name,
		CloneSpec: &spec,
		PodSelectionSpec: types.StorageDrsPodSelectionSpec{
			StoragePod: types.NewReference(pod.Reference()),
		},
		Type: string(types.StoragePlacementSpecPlacementTypeClone),
	}

	return recommendAndApplySDRS(client, sps, time.Minute*time.Duration(timeout))
}
// CloneVM clones a virtual machine to a datastore cluster via the
// StorageResourceManager API. It mimics our helper in the virtualmachine
// package in functionality, returning a VM helper object on success.