LEFT | RIGHT |
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 "launchpad.net/gnuflag" | 5 "launchpad.net/gnuflag" |
6 "launchpad.net/juju-core/cmd" | 6 "launchpad.net/juju-core/cmd" |
7 "launchpad.net/juju-core/juju" | 7 "launchpad.net/juju-core/juju" |
8 "launchpad.net/juju-core/state" | 8 "launchpad.net/juju-core/state" |
9 ) | 9 ) |
10 | 10 |
11 // DestroyMachineCommand causes an existing machine to be destroyed. | 11 // DestroyMachineCommand causes an existing machine to be destroyed. |
12 type DestroyMachineCommand struct { | 12 type DestroyMachineCommand struct { |
13 EnvName string | 13 EnvName string |
14 MachineIds []string | 14 MachineIds []string |
15 } | 15 } |
16 | 16 |
17 func (c *DestroyMachineCommand) Info() *cmd.Info { | 17 func (c *DestroyMachineCommand) Info() *cmd.Info { |
18 » return cmd.NewInfo( | 18 » return &cmd.Info{ |
19 » » "destroy-machine", "<machine> [, ...]", "destroy machines", | 19 » » Name: "destroy-machine", |
20 » » "Machines that have assigned units, or are responsible for the e
nvironment, cannot be destroyed.", | 20 » » Args: "<machine> ...", |
21 » » "terminate-machine") | 21 » » Purpose: "destroy machines", |
| 22 » » Doc: "Machines that have assigned units, or are responsible
for the environment, cannot be destroyed.", |
| 23 » » Aliases: []string{"terminate-machine"}, |
| 24 » } |
22 } | 25 } |
23 | 26 |
24 func (c *DestroyMachineCommand) SetFlags(f *gnuflag.FlagSet) { | 27 func (c *DestroyMachineCommand) SetFlags(f *gnuflag.FlagSet) { |
25 addEnvironFlags(&c.EnvName, f) | 28 addEnvironFlags(&c.EnvName, f) |
26 } | 29 } |
27 | 30 |
28 func (c *DestroyMachineCommand) Init(args []string) error { | 31 func (c *DestroyMachineCommand) Init(args []string) error { |
29 if len(args) == 0 { | 32 if len(args) == 0 { |
30 return fmt.Errorf("no machines specified") | 33 return fmt.Errorf("no machines specified") |
31 } | 34 } |
32 for _, id := range args { | 35 for _, id := range args { |
33 if !state.IsMachineId(id) { | 36 if !state.IsMachineId(id) { |
34 return fmt.Errorf("invalid machine id %q", id) | 37 return fmt.Errorf("invalid machine id %q", id) |
35 } | 38 } |
36 } | 39 } |
37 c.MachineIds = args | 40 c.MachineIds = args |
38 return nil | 41 return nil |
39 } | 42 } |
40 | 43 |
41 func (c *DestroyMachineCommand) Run(_ *cmd.Context) error { | 44 func (c *DestroyMachineCommand) Run(_ *cmd.Context) error { |
42 conn, err := juju.NewConnFromName(c.EnvName) | 45 conn, err := juju.NewConnFromName(c.EnvName) |
43 if err != nil { | 46 if err != nil { |
44 return err | 47 return err |
45 } | 48 } |
46 defer conn.Close() | 49 defer conn.Close() |
47 return conn.DestroyMachines(c.MachineIds...) | 50 return conn.DestroyMachines(c.MachineIds...) |
48 } | 51 } |
LEFT | RIGHT |