Skip to content

Commit

Permalink
Merge pull request #142 from kthcloud/dev
Browse files Browse the repository at this point in the history
simplify snapshout creation since it auto fetched anyway
  • Loading branch information
saffronjam authored Aug 17, 2023
2 parents 41d2a68 + 801c8a3 commit 3091dd4
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions service/vm_service/internal_service/cs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,12 @@ func CreateSnapshotCS(id string) error {
VmID: vm.Subsystems.CS.VM.ID,
}

snapshot, err := createSnapshot(client, vm, public)
snapshotID, err := client.CreateSnapshot(public)
if err != nil {
return makeError(err)
}

log.Println("created snapshot", snapshot.Name, "for vm", id)
log.Println("created snapshot", snapshotID, "for vm", id)

return nil
}
Expand Down Expand Up @@ -881,34 +881,6 @@ func createPortForwardingRule(client *cs.Client, vm *vmModel.VM, name string, pu
return portForwardingRule, nil
}

func createSnapshot(client *cs.Client, vm *vmModel.VM, public *csModels.SnapshotPublic) (*csModels.SnapshotPublic, error) {
id, err := client.CreateSnapshot(public)
if err != nil {
return nil, err
}

snapshot, err := client.ReadSnapshot(id)
if err != nil {
return nil, err
}

if snapshot == nil {
return nil, errors.New("failed to read snapshot after creation")
}

if vm.Subsystems.CS.SnapshotMap == nil {
vm.Subsystems.CS.SnapshotMap = make(map[string]csModels.SnapshotPublic)
}
vm.Subsystems.CS.SnapshotMap[public.Name] = *snapshot

err = vmModel.UpdateSubsystemByName(vm.Name, "cs", "snapshotMap", vm.Subsystems.CS.SnapshotMap)
if err != nil {
return nil, err
}

return snapshot, nil
}

func createDeployTags(name string, deployName string) []csModels.Tag {
return []csModels.Tag{
{Key: "name", Value: name},
Expand Down

0 comments on commit 3091dd4

Please sign in to comment.