You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing hyper-v library which gives ability to create snapshot and read disks.
I was able to take snapshot with below code
`
snapshotService, err := vm.getVSSSnapshotService() // returns object from SELECT * FROM Msvm_VirtualSystemSnapshotService
if err != nil {
return nil, fmt.Errorf("failed to get snapshot service: %w", err)
}
// Set up snapshot settings data
settingsData, err := vm.getSnapshotSettingsData(level) // returns settings object
if err != nil {
return nil, fmt.Errorf("failed to get snapshot settings: %w", err)
}
defer settingsData.Release()
_, err = oleutil.PutProperty(settingsData, "ElementName", checkpointName)
if err != nil {
return nil, fmt.Errorf("failed to set checkpoint name: %w", err)
}
// Get VM path and convert settings to text
vmPath, err := vm.getVMReferencePathForDebug()
if err != nil {
return nil, fmt.Errorf("failed to get VM path: %w", err)
}
settingsDataString, err := oleutil.CallMethod(settingsData, "GetText_", 1)
if err != nil {
return nil, fmt.Errorf("failed to get snapshot settings text: %w", err)
}
defer settingsDataString.Clear()
// Call CreateSnapshot - this returns a return code
fmt.Println("Creating snapshot with name:", checkpointName)
// Call CreateSnapshot normally (no job object parameter)
resultRaw, err := oleutil.CallMethod(snapshotService, "CreateSnapshot",
vmPath,
settingsDataString,
int32(2)) // Snapshot type 2
if err != nil {
return nil, fmt.Errorf("failed to call CreateSnapshot: %w", err)
}
defer resultRaw.Clear()
// Check return code
returnCode := int(resultRaw.Val)
fmt.Printf("CreateSnapshot returned code: %d\n", returnCode)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm writing hyper-v library which gives ability to create snapshot and read disks.
I was able to take snapshot with below code
`
snapshotService, err := vm.getVSSSnapshotService() // returns object from SELECT * FROM Msvm_VirtualSystemSnapshotService
if err != nil {
return nil, fmt.Errorf("failed to get snapshot service: %w", err)
}
`
The resultRaw object only has Val which is 4096 for job started, snapshot is getting created, but I want to add ability to poll for job state but not able to figure out how to get the Job object.
I referred below link for snapshot creation.
https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/createsnapshot-msvm-virtualsystemsnapshotservice
Help is appreciated if any other implementation is also available I can explore that too, please feel free to correct code if inefficiencies observed.
Beta Was this translation helpful? Give feedback.
All reactions