github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/providers/firecracker/delete_volume.go (about) 1 package firecracker 2 3 import ( 4 "os" 5 6 "github.com/emc-advanced-dev/pkg/errors" 7 ) 8 9 func (p *FirecrackerProvider) DeleteVolume(id string, force bool) error { 10 11 volume, err := p.GetVolume(id) 12 if err != nil { 13 return errors.New("retrieving volume "+id, err) 14 } 15 if volume.Attachment != "" { 16 if force { 17 if err := p.DetachVolume(volume.Id); err != nil { 18 return errors.New("detaching volume for deletion", err) 19 } 20 } else { 21 return errors.New("volume "+volume.Id+" is attached to instance."+volume.Attachment+", try again with --force or detach volume first", err) 22 } 23 } 24 volumePath := getVolumePath(volume.Name) 25 err = os.Remove(volumePath) 26 if err != nil { 27 return errors.New("could not delete volume at path "+volumePath, err) 28 } 29 return p.state.RemoveVolume(volume) 30 }