This commit is contained in:
Megan Marsh 2020-06-17 02:04:45 -07:00 committed by GitHub
parent ca067475fd
commit 88c94cc987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

@ -325,7 +325,7 @@ func (d *VBox42Driver) LoadSnapshots(vmName string) (*VBoxSnapshot, error) {
var rootNode *VBoxSnapshot
stdoutString, err := d.VBoxManageWithOutput("snapshot", vmName, "list", "--machinereadable")
if stdoutString == "This machine does not have any snapshots" {
return rootNode, fmt.Errorf("VM %s does not have any snapshots.", vmName)
return rootNode, nil
}
if nil != err {
return nil, err

View File

@ -40,18 +40,22 @@ func (s *StepCreateSnapshot) Run(_ context.Context, state multistep.StateBag) mu
return multistep.ActionHalt
}
currentSnapshot := snapshotTree.GetCurrentSnapshot()
targetSnapshot := currentSnapshot.GetChildWithName(s.TargetSnapshot)
if nil != targetSnapshot {
log.Printf("Deleting existing target snapshot %s", s.TargetSnapshot)
err = driver.DeleteSnapshot(s.Name, targetSnapshot)
if nil != err {
err = fmt.Errorf("Unable to delete snapshot %s from VM %s: %s", s.TargetSnapshot, s.Name, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
// Remove any snapshot with the target's name, if present.
if snapshotTree != nil {
currentSnapshot := snapshotTree.GetCurrentSnapshot()
targetSnapshot := currentSnapshot.GetChildWithName(s.TargetSnapshot)
if nil != targetSnapshot {
log.Printf("Deleting existing target snapshot %s", s.TargetSnapshot)
err = driver.DeleteSnapshot(s.Name, targetSnapshot)
if nil != err {
err = fmt.Errorf("Unable to delete snapshot %s from VM %s: %s", s.TargetSnapshot, s.Name, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
}
}
err = driver.CreateSnapshot(s.Name, s.TargetSnapshot)
if err != nil {
err := fmt.Errorf("Error creating snaphot VM: %s", err)