Skip to content

Commit 1777a85

Browse files
authored
Merge pull request #1596 from dougm/example-snapshot
examples: add VirtualMachine.CreateSnapshot
2 parents 8d5f8e5 + 1828eee commit 1777a85

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

object/example_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,39 @@ func ExampleResourcePool_Owner() {
6161
// DC0_C0_RP0_VM0 owner is a *object.ClusterComputeResource
6262
}
6363

64+
func ExampleVirtualMachine_CreateSnapshot() {
65+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
66+
vm, err := find.NewFinder(c).VirtualMachine(ctx, "DC0_H0_VM0")
67+
if err != nil {
68+
return err
69+
}
70+
71+
task, err := vm.CreateSnapshot(ctx, "backup", "Backup", false, false)
72+
if err != nil {
73+
return err
74+
}
75+
if err = task.Wait(ctx); err != nil {
76+
return err
77+
}
78+
79+
id, err := vm.FindSnapshot(ctx, "backup")
80+
if err != nil {
81+
return err
82+
}
83+
84+
var snapshot mo.VirtualMachineSnapshot
85+
err = vm.Properties(ctx, *id, []string{"config.hardware.device"}, &snapshot)
86+
if err != nil {
87+
return err
88+
}
89+
90+
fmt.Printf("%d devices", len(snapshot.Config.Hardware.Device))
91+
92+
return nil
93+
})
94+
// Output: 13 devices
95+
}
96+
6497
func ExampleVirtualMachine_HostSystem() {
6598
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
6699
vm, err := find.NewFinder(c).VirtualMachine(ctx, "DC0_H0_VM0")

0 commit comments

Comments
 (0)