github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/providers/firecracker/stop_instance.go (about) 1 package firecracker 2 3 import ( 4 "github.com/emc-advanced-dev/pkg/errors" 5 "github.com/sirupsen/logrus" 6 "github.com/solo-io/unik/pkg/types" 7 ) 8 9 func (p *FirecrackerProvider) StopInstance(id string) error { 10 instance, err := p.GetInstance(id) 11 if err != nil { 12 return errors.New("retrieving instance "+id, err) 13 } 14 15 p.mapLock.RLock() 16 m := p.runningMachines[id] 17 p.mapLock.RUnlock() 18 19 if m == nil { 20 logrus.WithField("instance", instance).Warn("instance not available in runtime") 21 } else { 22 p.mapLock.Lock() 23 delete(p.runningMachines, id) 24 p.mapLock.Unlock() 25 26 m.StopVMM() 27 } 28 29 volumesToDetach := []*types.Volume{} 30 volumes, err := p.ListVolumes() 31 if err != nil { 32 return errors.New("getting volume list", err) 33 } 34 for _, volume := range volumes { 35 if volume.Attachment == instance.Id { 36 volumesToDetach = append(volumesToDetach, volume) 37 } 38 } 39 40 return p.state.RemoveInstance(instance) 41 }