/
container_state.go
259 lines (195 loc) · 6.06 KB
/
container_state.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// Code generated by go-swagger; DO NOT EDIT.
package types
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/errors"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// ContainerState container state
// swagger:model ContainerState
type ContainerState struct {
// Whether this container is dead.
// Required: true
Dead bool `json:"Dead"`
// The error message of this container
// Required: true
Error string `json:"Error"`
// The last exit code of this container
// Required: true
ExitCode int64 `json:"ExitCode"`
// Whether this container is abnormal stopped. So that we can distinguish whether
// a container stoppped by API or abnormal.
//
// This flag can be used on the circumstances that when the host restart and try to pull up
// the containers that are running before host down. If we have a container with `RestartPolicy`
// is `always` but the `Status` is `Stopped`, should we start it or not?
//
// So with the `Exited` flag being set, we can make sure that this container is exited by abnormal,
// we should pull it up. But with status is `Stopped`, we should not pull it up because it is stopped
// by API.
//
Exited bool `json:"Exited,omitempty"`
// The time when this container last exited.
// Required: true
FinishedAt string `json:"FinishedAt"`
// Whether this container has been killed because it ran out of memory.
// Required: true
OOMKilled bool `json:"OOMKilled"`
// Whether this container is paused.
// Required: true
Paused bool `json:"Paused"`
// The process ID of this container
// Required: true
Pid int64 `json:"Pid"`
// Whether this container is restarting.
// Required: true
Restarting bool `json:"Restarting"`
// Whether this container is running.
//
// Note that a running container can be _paused_. The `Running` and `Paused`
// booleans are not mutually exclusive:
//
// When pausing a container (on Linux), the cgroups freezer is used to suspend
// all processes in the container. Freezing the process requires the process to
// be running. As a result, paused containers are both `Running` _and_ `Paused`.
//
// Use the `Status` field instead to determine if a container's state is "running".
//
// Required: true
Running bool `json:"Running"`
// The time when this container was last started.
// Required: true
StartedAt string `json:"StartedAt"`
// status
// Required: true
Status Status `json:"Status"`
}
// Validate validates this container state
func (m *ContainerState) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateDead(formats); err != nil {
res = append(res, err)
}
if err := m.validateError(formats); err != nil {
res = append(res, err)
}
if err := m.validateExitCode(formats); err != nil {
res = append(res, err)
}
if err := m.validateFinishedAt(formats); err != nil {
res = append(res, err)
}
if err := m.validateOOMKilled(formats); err != nil {
res = append(res, err)
}
if err := m.validatePaused(formats); err != nil {
res = append(res, err)
}
if err := m.validatePid(formats); err != nil {
res = append(res, err)
}
if err := m.validateRestarting(formats); err != nil {
res = append(res, err)
}
if err := m.validateRunning(formats); err != nil {
res = append(res, err)
}
if err := m.validateStartedAt(formats); err != nil {
res = append(res, err)
}
if err := m.validateStatus(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *ContainerState) validateDead(formats strfmt.Registry) error {
if err := validate.Required("Dead", "body", bool(m.Dead)); err != nil {
return err
}
return nil
}
func (m *ContainerState) validateError(formats strfmt.Registry) error {
if err := validate.RequiredString("Error", "body", string(m.Error)); err != nil {
return err
}
return nil
}
func (m *ContainerState) validateExitCode(formats strfmt.Registry) error {
if err := validate.Required("ExitCode", "body", int64(m.ExitCode)); err != nil {
return err
}
return nil
}
func (m *ContainerState) validateFinishedAt(formats strfmt.Registry) error {
if err := validate.RequiredString("FinishedAt", "body", string(m.FinishedAt)); err != nil {
return err
}
return nil
}
func (m *ContainerState) validateOOMKilled(formats strfmt.Registry) error {
if err := validate.Required("OOMKilled", "body", bool(m.OOMKilled)); err != nil {
return err
}
return nil
}
func (m *ContainerState) validatePaused(formats strfmt.Registry) error {
if err := validate.Required("Paused", "body", bool(m.Paused)); err != nil {
return err
}
return nil
}
func (m *ContainerState) validatePid(formats strfmt.Registry) error {
if err := validate.Required("Pid", "body", int64(m.Pid)); err != nil {
return err
}
return nil
}
func (m *ContainerState) validateRestarting(formats strfmt.Registry) error {
if err := validate.Required("Restarting", "body", bool(m.Restarting)); err != nil {
return err
}
return nil
}
func (m *ContainerState) validateRunning(formats strfmt.Registry) error {
if err := validate.Required("Running", "body", bool(m.Running)); err != nil {
return err
}
return nil
}
func (m *ContainerState) validateStartedAt(formats strfmt.Registry) error {
if err := validate.RequiredString("StartedAt", "body", string(m.StartedAt)); err != nil {
return err
}
return nil
}
func (m *ContainerState) validateStatus(formats strfmt.Registry) error {
if err := m.Status.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("Status")
}
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *ContainerState) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *ContainerState) UnmarshalBinary(b []byte) error {
var res ContainerState
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}