~ubuntu-branches/ubuntu/trusty/juju-core/trusty-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/state/statecmd/destroymachines.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-29 11:40:20 UTC
  • mfrom: (23.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20140129114020-ejieitm8smtt5vln
Tags: 1.17.1-0ubuntu2
d/tests/local-provider: Don't fail tests if ~/.juju is present as its
created by the juju version command. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2012, 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package statecmd
 
5
 
 
6
import (
 
7
        "fmt"
 
8
        "strings"
 
9
 
 
10
        "launchpad.net/juju-core/errors"
 
11
        "launchpad.net/juju-core/state"
 
12
)
 
13
 
 
14
// DestroyMachines1dot16 destroys the machines with the specified ids.
 
15
// This is copied from the 1.16.3 code to enable compatibility. It should be
 
16
// removed when we release a version that goes via the API only (whatever is
 
17
// after 1.18)
 
18
func DestroyMachines1dot16(st *state.State, ids ...string) (err error) {
 
19
        var errs []string
 
20
        for _, id := range ids {
 
21
                machine, err := st.Machine(id)
 
22
                switch {
 
23
                case errors.IsNotFoundError(err):
 
24
                        err = fmt.Errorf("machine %s does not exist", id)
 
25
                case err != nil:
 
26
                case machine.Life() != state.Alive:
 
27
                        continue
 
28
                default:
 
29
                        err = machine.Destroy()
 
30
                }
 
31
                if err != nil {
 
32
                        errs = append(errs, err.Error())
 
33
                }
 
34
        }
 
35
        if len(errs) == 0 {
 
36
                return nil
 
37
        }
 
38
        msg := "some machines were not destroyed"
 
39
        if len(errs) == len(ids) {
 
40
                msg = "no machines were destroyed"
 
41
        }
 
42
        return fmt.Errorf("%s: %s", msg, strings.Join(errs, "; "))
 
43
}