-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum_box_events.go
209 lines (179 loc) · 4.82 KB
/
enum_box_events.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package clccam
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
// Events in the lifecycle of an Elastic Box
type BoxEvent uint32
const (
// Event before configuring the box
BoxEvent_PreConfigure BoxEvent = iota
// Configuring the box
BoxEvent_Configure
// Before installing onto the box
BoxEvent_PreInstall
// Installing onto the box
BoxEvent_Install
// Before starting the box
BoxEvent_PreStart
// Starting the box
BoxEvent_Start
// Before stopping the box
BoxEvent_PreStop
// Stopping the box
BoxEvent_Stop
// After stopping the box
BoxEvent_PostStop
// Before disposing the box
BoxEvent_PreDispose
// Disposing the box
BoxEvent_Dispose
// After disposing the box
BoxEvent_PostDispose
// Collecting bindings?
BoxEvent_CollectBindings
// Run the execute_patch operation (upload script with variables expanded from request)
BoxEvent_Patch
)
// Implements encoding.TextMarshaler
func (b BoxEvent) MarshalText() ([]byte, error) {
switch b {
case BoxEvent_PreConfigure:
return []byte("pre_configure"), nil
case BoxEvent_Configure:
return []byte("configure"), nil
case BoxEvent_PreInstall:
return []byte("pre_install"), nil
case BoxEvent_Install:
return []byte("install"), nil
case BoxEvent_PreStart:
return []byte("pre_start"), nil
case BoxEvent_Start:
return []byte("start"), nil
case BoxEvent_PreStop:
return []byte("pre_stop"), nil
case BoxEvent_Stop:
return []byte("stop"), nil
case BoxEvent_PostStop:
return []byte("post_stop"), nil
case BoxEvent_PreDispose:
return []byte("pre_dispose"), nil
case BoxEvent_Dispose:
return []byte("dispose"), nil
case BoxEvent_PostDispose:
return []byte("post_dispose"), nil
case BoxEvent_CollectBindings:
return []byte("collect_bindings"), nil
case BoxEvent_Patch:
return []byte("patch"), nil
}
return nil, fmt.Errorf("invalid BoxEvent %d", b)
}
// Implements fmt.Stringer
func (b BoxEvent) String() string {
if b, err := b.MarshalText(); err != nil {
return err.Error()
} else {
return string(b)
}
}
// Implements encoding.TextUnmarshaler
func (b *BoxEvent) UnmarshalText(data []byte) error {
switch string(data) {
case "pre_configure":
*b = BoxEvent_PreConfigure
case "configure":
*b = BoxEvent_Configure
case "pre_install":
*b = BoxEvent_PreInstall
case "install":
*b = BoxEvent_Install
case "pre_start":
*b = BoxEvent_PreStart
case "start":
*b = BoxEvent_Start
case "pre_stop":
*b = BoxEvent_PreStop
case "stop":
*b = BoxEvent_Stop
case "post_stop":
*b = BoxEvent_PostStop
case "pre_dispose":
*b = BoxEvent_PreDispose
case "dispose":
*b = BoxEvent_Dispose
case "post_dispose":
*b = BoxEvent_PostDispose
case "collect_bindings":
*b = BoxEvent_CollectBindings
case "patch":
*b = BoxEvent_Patch
default:
return fmt.Errorf("invalid BoxEvent %q", string(data))
}
return nil
}
// Implements flag.Value
func (b *BoxEvent) Set(value string) error {
return b.UnmarshalText([]byte(value))
}
// Implements pflag.Value (superset of flag.Value)
func (b BoxEvent) Type() string {
return "BoxEvent"
}
// BoxEventFromString attempts to parse @s as stringified BoxEvent.
func BoxEventFromString(s string) (val BoxEvent, err error) {
return val, val.Set(s)
}
// BoxEventStrings returns the list of BoxEvent string literals, or maps @vals if non-empty.
func BoxEventStrings(vals ...BoxEvent) (ret []string) {
if len(vals) > 0 {
for _, val := range vals {
ret = append(ret, val.String())
}
return ret
}
return []string{"pre_configure", "configure", "pre_install", "install", "pre_start", "start", "pre_stop", "stop", "post_stop", "pre_dispose", "dispose", "post_dispose", "collect_bindings", "patch"}
}
// Implements database/sql/driver.Valuer
func (b BoxEvent) Value() (driver.Value, error) {
return b.String(), nil
}
// Implements database/sql.Scanner
func (b *BoxEvent) Scan(src interface{}) error {
switch src := src.(type) {
case int64:
*b = BoxEvent(src)
return nil
case []byte:
return b.UnmarshalText(src)
case string:
return b.UnmarshalText([]byte(src))
}
return fmt.Errorf("unable to convert %T to BoxEvent", src)
}
// Implements json.Marshaler
func (b BoxEvent) MarshalJSON() ([]byte, error) {
return json.Marshal(b.String())
}
// Implements json.Unmarshaler
func (b *BoxEvent) UnmarshalJSON(data []byte) error {
var output string
if err := json.Unmarshal(data, &output); err != nil {
return fmt.Errorf("failed to parse '%s' as BoxEvent: %s", string(data), err)
}
return b.UnmarshalText([]byte(output))
}
// Implements yaml.Marshaler
func (b BoxEvent) MarshalYAML() (interface{}, error) {
return b.String(), nil
}
// Implements yaml.Unmarshaler
func (b *BoxEvent) UnmarshalYAML(unmarshal func(interface{}) error) error {
var output string
if err := unmarshal(&output); err != nil {
return fmt.Errorf("failed to unmarshal BoxEvent from YAML: %s", err)
}
return b.UnmarshalText([]byte(output))
}