@@ -25,11 +25,11 @@ import (
25
25
"github.com/vmware/govmomi/internal"
26
26
"github.com/vmware/govmomi/object"
27
27
"github.com/vmware/govmomi/simulator/esx"
28
+ "github.com/vmware/govmomi/units"
28
29
"github.com/vmware/govmomi/vim25/methods"
29
30
"github.com/vmware/govmomi/vim25/mo"
30
31
"github.com/vmware/govmomi/vim25/soap"
31
32
"github.com/vmware/govmomi/vim25/types"
32
- "github.com/vmware/govmomi/vmdk"
33
33
)
34
34
35
35
type VirtualMachine struct {
@@ -1351,7 +1351,6 @@ func (vm *VirtualMachine) configureDevice(
1351
1351
}
1352
1352
}
1353
1353
1354
- summary = fmt .Sprintf ("%s KB" , numberToString (x .CapacityInKB , ',' ))
1355
1354
switch b := d .Backing .(type ) {
1356
1355
case * types.VirtualDiskSparseVer2BackingInfo :
1357
1356
// Sparse disk creation not supported in ESX
@@ -1361,6 +1360,40 @@ func (vm *VirtualMachine) configureDevice(
1361
1360
},
1362
1361
}
1363
1362
case types.BaseVirtualDeviceFileBackingInfo :
1363
+ parent := ""
1364
+
1365
+ switch backing := d .Backing .(type ) {
1366
+ case * types.VirtualDiskFlatVer2BackingInfo :
1367
+ if backing .Parent != nil {
1368
+ parent = backing .Parent .FileName
1369
+ }
1370
+ case * types.VirtualDiskSeSparseBackingInfo :
1371
+ if backing .Parent != nil {
1372
+ parent = backing .Parent .FileName
1373
+ }
1374
+ case * types.VirtualDiskSparseVer2BackingInfo :
1375
+ if backing .Parent != nil {
1376
+ parent = backing .Parent .FileName
1377
+ }
1378
+ }
1379
+
1380
+ if parent != "" {
1381
+ desc , _ , err := ctx .Map .FileManager ().DiskDescriptor (ctx , & dc .Self , parent )
1382
+ if err != nil {
1383
+ return & types.InvalidDeviceSpec {
1384
+ InvalidVmConfig : types.InvalidVmConfig {
1385
+ Property : "virtualDeviceSpec.device.backing.parent.fileName" ,
1386
+ },
1387
+ }
1388
+ }
1389
+
1390
+ // Disk Capacity is always same as the parent's
1391
+ x .CapacityInBytes = int64 (desc .Capacity ())
1392
+ x .CapacityInKB = x .CapacityInBytes / 1024
1393
+ }
1394
+
1395
+ summary = fmt .Sprintf ("%s KB" , numberToString (x .CapacityInKB , ',' ))
1396
+
1364
1397
info := b .GetVirtualDeviceFileBackingInfo ()
1365
1398
var path object.DatastorePath
1366
1399
path .FromString (info .FileName )
@@ -2821,6 +2854,63 @@ func (vm *VirtualMachine) DetachDiskTask(ctx *Context, req *types.DetachDisk_Tas
2821
2854
}
2822
2855
}
2823
2856
2857
+ func (vm * VirtualMachine ) PromoteDisksTask (ctx * Context , req * types.PromoteDisks_Task ) soap.HasFault {
2858
+ task := CreateTask (vm , "promoteDisks" , func (t * Task ) (types.AnyType , types.BaseMethodFault ) {
2859
+ devices := object .VirtualDeviceList (vm .Config .Hardware .Device )
2860
+ devices = devices .SelectByType ((* types .VirtualDisk )(nil ))
2861
+ var cap int64
2862
+
2863
+ for i := range req .Disks {
2864
+ d := devices .FindByKey (req .Disks [i ].Key )
2865
+ if d == nil {
2866
+ return nil , & types.InvalidArgument {InvalidProperty : "disks" }
2867
+ }
2868
+
2869
+ disk := d .(* types.VirtualDisk )
2870
+
2871
+ switch backing := disk .Backing .(type ) {
2872
+ case * types.VirtualDiskFlatVer2BackingInfo :
2873
+ if backing .Parent != nil {
2874
+ cap += disk .CapacityInBytes
2875
+ if req .Unlink {
2876
+ backing .Parent = nil
2877
+ }
2878
+ }
2879
+ case * types.VirtualDiskSeSparseBackingInfo :
2880
+ if backing .Parent != nil {
2881
+ cap += disk .CapacityInBytes
2882
+ if req .Unlink {
2883
+ backing .Parent = nil
2884
+ }
2885
+ }
2886
+ case * types.VirtualDiskSparseVer2BackingInfo :
2887
+ if backing .Parent != nil {
2888
+ cap += disk .CapacityInBytes
2889
+ if req .Unlink {
2890
+ backing .Parent = nil
2891
+ }
2892
+ }
2893
+ }
2894
+ }
2895
+
2896
+ // Built-in default delay. `simulator.TaskDelay` can be used to add additional time
2897
+ // Translates to roughly 1s per 1GB
2898
+ sleep := time .Duration (cap / units .MB ) * time .Millisecond
2899
+ if sleep > 0 {
2900
+ log .Printf ("%s: sleep %s for %s" , t .Info .DescriptionId , sleep , units .ByteSize (cap ))
2901
+ time .Sleep (sleep )
2902
+ }
2903
+
2904
+ return nil , nil
2905
+ })
2906
+
2907
+ return & methods.PromoteDisks_TaskBody {
2908
+ Res : & types.PromoteDisks_TaskResponse {
2909
+ Returnval : task .Run (ctx ),
2910
+ },
2911
+ }
2912
+ }
2913
+
2824
2914
func (vm * VirtualMachine ) ShutdownGuest (ctx * Context , c * types.ShutdownGuest ) soap.HasFault {
2825
2915
r := & methods.ShutdownGuestBody {}
2826
2916
0 commit comments