github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/provider/common/destroy.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package common 5 6 import ( 7 "github.com/juju/juju/environs" 8 "github.com/juju/juju/instance" 9 ) 10 11 // Destroy is a common implementation of the Destroy method defined on 12 // environs.Environ; we strongly recommend that this implementation be 13 // used when writing a new provider. 14 func Destroy(env environs.Environ) error { 15 logger.Infof("destroying environment %q", env.Name()) 16 instances, err := env.AllInstances() 17 switch err { 18 case nil: 19 ids := make([]instance.Id, len(instances)) 20 for i, inst := range instances { 21 ids[i] = inst.Id() 22 } 23 if err := env.StopInstances(ids...); err != nil { 24 return err 25 } 26 fallthrough 27 case environs.ErrNoInstances: 28 return env.Storage().RemoveAll() 29 } 30 return err 31 }