~rogpeppe/juju-core/438-local-instance-Addresses

« back to all changes in this revision

Viewing changes to provider/common/destroy.go

  • Committer: Tarmac
  • Author(s): William Reade
  • Date: 2013-10-02 10:38:04 UTC
  • mfrom: (1915.1.3 juju-core)
  • Revision ID: tarmac-20131002103804-zxlnv7ik17unxc3p
[r=fwereade] provider/common: Destroy, and tests

Added a common implementation of Destroy, and tests for Bootstrap which had
somehow never been written. Also drive-by removed the machineId arg from
consideration when bootstrapping, because, WTF... a non-0 bootstrap machine
would break *everything*.

https://codereview.appspot.com/14254043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}