forked from pkallberg/cx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container-restart.go
53 lines (43 loc) · 1.18 KB
/
container-restart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"os"
"text/tabwriter"
"time"
"github.com/cloud66/cloud66"
"github.com/cloud66/cli"
)
func runContainerRestart(c *cli.Context) {
if len(c.Args()) != 1 {
cli.ShowSubcommandHelp(c)
os.Exit(2)
}
stack := mustStack(c)
w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
defer w.Flush()
containerUid := c.Args()[0]
container, err := client.GetContainer(stack.Uid, containerUid)
must(err)
if container == nil {
printFatal("Container with Id '" + containerUid + "' not found")
}
asyncId, err := startContainerRestart(stack.Uid, containerUid)
if err != nil {
printFatal(err.Error())
}
genericRes, err := endServerSet(*asyncId, stack.Uid)
if err != nil {
printFatal(err.Error())
}
printGenericResponse(*genericRes)
return
}
func startContainerRestart(stackUid string, containerUid string) (*int, error) {
asyncRes, err := client.InvokeStackContainerAction(stackUid, containerUid, "container_restart")
if err != nil {
return nil, err
}
return &asyncRes.Id, err
}
func endContainerRestart(asyncId int, stackUid string) (*cloud66.GenericResponse, error) {
return client.WaitStackAsyncAction(asyncId, stackUid, 3*time.Second, 20*time.Minute, true)
}