vsphere/resource_vsphere_virtual_disk.go
func createHardDisk(client *govmomi.Client, size int, diskPath string, diskType string, adapterType string, dc string) error {
	var vDiskType string
	switch diskType {
	case "thin":
		vDiskType = "thin"
	case "eagerZeroedThick":
		vDiskType = "eagerZeroedThick"
	case "lazy":
		vDiskType = "preallocated"
	}

	virtualDiskManager := object.NewVirtualDiskManager(client.Client)
	spec := &types.FileBackedVirtualDiskSpec{
		VirtualDiskSpec: types.VirtualDiskSpec{
			AdapterType: adapterType,
			DiskType:    vDiskType,
		},
		CapacityKb: int64(1024 * 1024 * size),
	}
	datacenter, err := getDatacenter(client, dc)
	if err != nil {
		return err
	}
	log.Printf("[DEBUG] Disk spec: %v", spec)

	task, err := virtualDiskManager.CreateVirtualDisk(context.TODO(), diskPath, datacenter, spec)
	if err != nil {
		return err
	}

	_, err = task.WaitForResult(context.TODO(), nil)
	if err != nil {
		log.Printf("[INFO] Failed to create disk:  %v", err)
		return err
	}
	log.Printf("[INFO] Created disk.")

	return nil
}
func createHardDisk(client *govmomi.Client, size int, diskPath string, diskType string, adapterType string, dc string) error {
	var vDiskType string
	switch diskType {
	case "thin":
		vDiskType = "thin"
	case "eagerZeroedThick":
		vDiskType = "eagerZeroedThick"
	case "lazy":
		vDiskType = "preallocated"
	}

	virtualDiskManager := object.NewVirtualDiskManager(client.Client)
	spec := &types.FileBackedVirtualDiskSpec{
		VirtualDiskSpec: types.VirtualDiskSpec{
			AdapterType: adapterType,
			DiskType:    vDiskType,
		},
		CapacityKb: int64(1024 * 1024 * size),
	}
	datacenter, err := getDatacenter(client, dc)
	if err != nil {
		return err
	}
	log.Printf("[DEBUG] Disk spec: %v", spec)

	task, err := virtualDiskManager.CreateVirtualDisk(context.TODO(), diskPath, datacenter, spec)
	if err != nil {
		return err
	}

	_, err = task.WaitForResult(context.TODO(), nil)
	if err != nil {
		log.Printf("[INFO] Failed to create disk:  %v", err)
		return err
	}
	log.Printf("[INFO] Created disk.")

	return nil
}
func createHardDisk ( client * govmomi . Client , size int , diskPath string , diskType string , adapterType string , dc string ) error { var vDiskType string switch diskType { case " " : vDiskType = " " case " " : vDiskType = " " case " " : vDiskType = " " } virtualDiskManager := object . NewVirtualDiskManager ( client . Client ) spec := & types . FileBackedVirtualDiskSpec { VirtualDiskSpec : types . VirtualDiskSpec { AdapterType : adapterType , DiskType : vDiskType , } , CapacityKb : int64 ( 1024 * 1024 * size ) , } datacenter , err := getDatacenter ( client , dc ) if err != nil { return err } log . Printf ( " " , spec ) task , err := virtualDiskManager . CreateVirtualDisk ( context . TODO ( ) , diskPath , datacenter , spec ) if err != nil { return err } _ , err = task . WaitForResult ( context . TODO ( ) , nil ) if err != nil { log . Printf ( " " , err ) return err } log . Printf ( " " ) return nil }
// createHardDisk creates a new Hard Disk.
createHardDisk creates a new Hard Disk .