-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.go
110 lines (94 loc) · 2.18 KB
/
hooks.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package deploy
import (
"os"
log "github.com/Sirupsen/logrus"
"github.com/docker/libcompose/deploy/labels"
"github.com/docker/libcompose/deploy/nethooks"
"github.com/docker/libcompose/deploy/ops"
"github.com/docker/libcompose/project"
)
type eventType int
const (
noEvent = eventType(iota)
startEvent = eventType(iota)
stopEvent = eventType(iota)
scaleEvent = eventType(iota)
)
func getEvent(event string) eventType {
switch event {
case "up", "start":
return startEvent
case "down", "delete", "kill", "rm", "stop":
return stopEvent
case "scale":
return scaleEvent
case "create", "build", "ps", "port", "pull", "log", "restart":
// unsupported
}
return noEvent
}
func PopulateEnvLabels(p *project.Project, csvLabels string) error {
parts, err := labels.Parse(csvLabels)
if err != nil {
return err
}
if err := labels.Insert(p, parts); err != nil {
return err
}
return nil
}
func PreHooks(p *project.Project, e string) error {
if err := ops.LoadOps(); err != nil {
log.Fatalf("Failed to load ops policies: %s", err)
os.Exit(10)
return err
}
if err := nethooks.Init(); err != nil {
log.Fatalf("Failed to Init: %s", err)
os.Exit(10)
return err
}
event := getEvent(e)
switch event {
case startEvent:
if err := nethooks.CreateNetConfig(p); err != nil {
log.Fatalf("Failed to Create Network Config: %s", err)
os.Exit(10)
return err
}
case scaleEvent:
if err := nethooks.ScaleNetConfig(p); err != nil {
log.Fatalf("Failed to Scale Network Config: %s", err)
os.Exit(10)
return err
}
case stopEvent:
}
switch event {
case startEvent, scaleEvent:
if err := nethooks.AutoGenLabels(p); err != nil {
log.Fatalf("Failed to AutoGenerate Lables: %s", err)
os.Exit(10)
return err
}
if err := nethooks.AutoGenParams(p); err != nil {
log.Fatalf("Failed to AutoGenerate Params: %s", err)
os.Exit(10)
return err
}
}
return nil
}
func PostHooks(p *project.Project, e string) error {
event := getEvent(e)
switch event {
case startEvent:
case scaleEvent:
case stopEvent:
if err := nethooks.DeleteNetConfig(p); err != nil {
log.Debugf("Failed to Delete Netwrok Config Params: %s", err)
return err
}
}
return nil
}