7
"github.com/lxc/lxd/shared"
8
"github.com/lxc/lxd/shared/gnuflag"
9
"github.com/lxc/lxd/shared/i18n"
12
type actionCmd struct {
13
action shared.ContainerAction
23
func (c *actionCmd) showByDefault() bool {
27
func (c *actionCmd) usage() string {
28
return fmt.Sprintf(i18n.G(
29
`Changes state of one or more containers to %s.
31
lxc %s <name> [<name>...]`), c.name, c.name)
34
func (c *actionCmd) flags() {
36
gnuflag.IntVar(&c.timeout, "timeout", -1, i18n.G("Time to wait for the container before killing it."))
37
gnuflag.BoolVar(&c.force, "force", false, i18n.G("Force the container to shutdown."))
38
gnuflag.BoolVar(&c.stateful, "stateful", false, i18n.G("Store the container state (only for stop)."))
39
gnuflag.BoolVar(&c.stateless, "stateless", false, i18n.G("Ignore the container state (only forstart)."))
43
func (c *actionCmd) run(config *lxd.Config, args []string) error {
50
// Only store state if asked to
51
if c.action == "stop" && c.stateful {
55
for _, nameArg := range args {
56
remote, name := config.ParseRemoteAndContainer(nameArg)
57
d, err := lxd.NewClient(config, remote)
63
return fmt.Errorf(i18n.G("Must supply container name for: ")+"\"%s\"", nameArg)
66
if c.action == shared.Start || c.action == shared.Stop {
67
current, err := d.ContainerInfo(name)
72
// "start" for a frozen container means "unfreeze"
73
if current.StatusCode == shared.Frozen {
74
c.action = shared.Unfreeze
77
// Always restore state (if present) unless asked not to
78
if c.action == shared.Start && current.Stateful && !c.stateless {
83
resp, err := d.Action(name, c.action, c.timeout, c.force, state)
88
if resp.Type != lxd.Async {
89
return fmt.Errorf(i18n.G("bad result type from action"))
92
if err := d.WaitForSuccess(resp.Operation); err != nil {
93
return fmt.Errorf("%s\n"+i18n.G("Try `lxc info --show-log %s` for more info"), err, name)