launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/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 "launchpad.net/juju-core/environs" 8 ) 9 10 // Destroy is a common implementation of the Destroy method defined on 11 // environs.Environ; we strongly recommend that this implementation be 12 // used when writing a new provider. 13 func Destroy(env environs.Environ) error { 14 logger.Infof("destroying environment %q", env.Name()) 15 instances, err := env.AllInstances() 16 switch err { 17 case nil: 18 if err := env.StopInstances(instances); err != nil { 19 return err 20 } 21 fallthrough 22 case environs.ErrNoInstances: 23 return env.Storage().RemoveAll() 24 } 25 return err 26 }