forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zedmanagertypes.go
343 lines (294 loc) · 10.9 KB
/
zedmanagertypes.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
// Copyright (c) 2017 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package types
import (
"fmt"
"net"
"time"
"github.com/google/go-cmp/cmp"
"github.com/lf-edge/eve/pkg/pillar/base"
uuid "github.com/satori/go.uuid"
)
type UrlCloudCfg struct {
ConfigUrl string
MetricsUrl string
StatusUrl string
LogUrl string
}
// top level config container
type DeviceConfigResponse struct {
Config EdgeDevConfig
}
type EdgeDevConfig struct {
Id UUIDandVersion
DevConfigSha256 string
DevConfigSignature string
Apps []AppInstanceConfig
Networks []UnderlayNetworkConfig
}
// UUID plus version
type UUIDandVersion struct {
UUID uuid.UUID
Version string
}
// This is what we assume will come from the ZedControl for each
// application instance. Note that we can have different versions
// configured for the same UUID, hence the key is the UUIDandVersion
// We assume the elements in StorageConfig should be installed, but activation
// (advertize the EID in lisp and boot the guest) is driven by the Activate
// attribute.
type AppInstanceConfig struct {
UUIDandVersion UUIDandVersion
DisplayName string
// Error
// If this is set, do not process further.. Just set the status to error
// so the cloud gets it.
Errors []string
FixedResources VmConfig // CPU etc
VolumeRefConfigList []VolumeRefConfig
Activate bool //EffectiveActivate in AppInstanceStatus must be used for the actual activation
UnderlayNetworkList []UnderlayNetworkConfig
IoAdapterList []IoAdapter
RestartCmd AppInstanceOpsCmd
PurgeCmd AppInstanceOpsCmd
// XXX: to be deprecated, use CipherBlockStatus instead
CloudInitUserData *string `json:"pubsub-large-CloudInitUserData"`
RemoteConsole bool
// Collect Stats IP Address, assume port is the default docker API for http: 2375
CollectStatsIPAddr net.IP
// CipherBlockStatus, for encrypted cloud-init data
CipherBlockStatus
MetaDataType MetaDataType
ProfileList []string
}
type AppInstanceOpsCmd struct {
Counter uint32
ApplyTime string // XXX not currently used
}
// IoAdapter specifies that a group of ports should be assigned
type IoAdapter struct {
Type IoType
Name string // Short hand name such as "COM1" or "eth1-2"
}
// LogCreate :
func (config AppInstanceConfig) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.AppInstanceConfigLogType, config.DisplayName,
config.UUIDandVersion.UUID, config.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("activate", config.Activate).
AddField("remote-console", config.RemoteConsole).
Noticef("App instance config create")
}
// LogModify :
func (config AppInstanceConfig) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.AppInstanceConfigLogType, config.DisplayName,
config.UUIDandVersion.UUID, config.LogKey())
oldConfig, ok := old.(AppInstanceConfig)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of AppInstanceConfig type")
}
if oldConfig.Activate != config.Activate ||
oldConfig.RemoteConsole != config.RemoteConsole {
logObject.CloneAndAddField("activate", config.Activate).
AddField("remote-console", config.RemoteConsole).
AddField("old-activate", oldConfig.Activate).
AddField("old-remote-console", oldConfig.RemoteConsole).
Noticef("App instance config modify")
} else {
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldConfig, config)).
Noticef("App instance config modify other change")
}
}
// LogDelete :
func (config AppInstanceConfig) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.AppInstanceConfigLogType, config.DisplayName,
config.UUIDandVersion.UUID, config.LogKey())
logObject.CloneAndAddField("activate", config.Activate).
AddField("remote-console", config.RemoteConsole).
Noticef("App instance config delete")
base.DeleteLogObject(logBase, config.LogKey())
}
// LogKey :
func (config AppInstanceConfig) LogKey() string {
return string(base.AppInstanceConfigLogType) + "-" + config.Key()
}
func (config AppInstanceConfig) Key() string {
return config.UUIDandVersion.UUID.String()
}
// Indexed by UUIDandVersion as above
type AppInstanceStatus struct {
UUIDandVersion UUIDandVersion
DisplayName string
DomainName string // Once booted
Activated bool
ActivateInprogress bool // Needed for cleanup after failure
FixedResources VmConfig // CPU etc
VolumeRefStatusList []VolumeRefStatus
UnderlayNetworks []UnderlayNetworkStatus
BootTime time.Time
IoAdapterList []IoAdapter // Report what was actually used
RestartInprogress Inprogress
PurgeInprogress Inprogress
// Mininum state across all steps and all StorageStatus.
// Error* set implies error.
State SwState
MissingNetwork bool // If some Network UUID not found
MissingMemory bool // Waiting for memory
EffectiveActivate bool //set here effective activate after profile check and apply
// All error strings across all steps and all StorageStatus
// ErrorAndTimeWithSource provides SetError, SetErrrorWithSource, etc
ErrorAndTimeWithSource
}
// LogCreate :
func (status AppInstanceStatus) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.AppInstanceStatusLogType, status.DisplayName,
status.UUIDandVersion.UUID, status.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("state", status.State.String()).
AddField("restart-in-progress", status.RestartInprogress).
AddField("purge-in-progress", status.PurgeInprogress).
Noticef("App instance status create")
}
// LogModify :
func (status AppInstanceStatus) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.AppInstanceStatusLogType, status.DisplayName,
status.UUIDandVersion.UUID, status.LogKey())
oldStatus, ok := old.(AppInstanceStatus)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of AppInstanceStatus type")
}
if oldStatus.State != status.State ||
oldStatus.RestartInprogress != status.RestartInprogress ||
oldStatus.PurgeInprogress != status.PurgeInprogress {
logObject.CloneAndAddField("state", status.State.String()).
AddField("restart-in-progress", status.RestartInprogress).
AddField("purge-in-progress", status.PurgeInprogress).
AddField("old-state", oldStatus.State.String()).
AddField("old-restart-in-progress", oldStatus.RestartInprogress).
AddField("old-purge-in-progress", oldStatus.PurgeInprogress).
Noticef("App instance status modify")
} else {
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldStatus, status)).
Noticef("App instance status modify other change")
}
if status.HasError() {
errAndTime := status.ErrorAndTime()
logObject.CloneAndAddField("state", status.State.String()).
AddField("restart-in-progress", status.RestartInprogress).
AddField("purge-in-progress", status.PurgeInprogress).
AddField("error", errAndTime.Error).
AddField("error-time", errAndTime.ErrorTime).
Noticef("App instance status modify")
}
}
// LogDelete :
func (status AppInstanceStatus) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.AppInstanceStatusLogType, status.DisplayName,
status.UUIDandVersion.UUID, status.LogKey())
logObject.CloneAndAddField("state", status.State.String()).
AddField("restart-in-progress", status.RestartInprogress).
AddField("purge-in-progress", status.PurgeInprogress).
Noticef("App instance status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey :
func (status AppInstanceStatus) LogKey() string {
return string(base.AppInstanceStatusLogType) + "-" + status.Key()
}
// Track more complicated workflows
type Inprogress uint8
// NotInprogress and other values for Inprogress
const (
NotInprogress Inprogress = iota
RecreateVolumes // Download and verify new images if need be
BringDown
BringUp
)
func (status AppInstanceStatus) Key() string {
return status.UUIDandVersion.UUID.String()
}
// GetAppInterfaceList is a helper function to get all the vifnames
func (status AppInstanceStatus) GetAppInterfaceList() []string {
var viflist []string
for _, ulStatus := range status.UnderlayNetworks {
if ulStatus.VifUsed != "" {
viflist = append(viflist, ulStatus.VifUsed)
}
}
return viflist
}
func RoundupToKB(b uint64) uint64 {
return (b + 1023) / 1024
}
// AppAndImageToHash is used to retain <app,image> to sha maps across reboots.
// Key for OCI images which can be specified with a tag and we need to be
// able to latch the sha and choose when to update/refresh from the tag.
type AppAndImageToHash struct {
AppUUID uuid.UUID
ImageID uuid.UUID
Hash string
PurgeCounter uint32
}
// Key is used for pubsub
func (aih AppAndImageToHash) Key() string {
if aih.PurgeCounter == 0 {
return fmt.Sprintf("%s.%s", aih.AppUUID.String(), aih.ImageID.String())
} else {
return fmt.Sprintf("%s.%s.%d", aih.AppUUID.String(), aih.ImageID.String(), aih.PurgeCounter)
}
}
// LogCreate :
func (aih AppAndImageToHash) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.AppAndImageToHashLogType, "",
aih.AppUUID, aih.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("purge-counter-int64", aih.PurgeCounter).
AddField("image-id", aih.ImageID.String()).
AddField("hash", aih.Hash).
Noticef("App and image to hash create")
}
// LogModify :
func (aih AppAndImageToHash) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.AppAndImageToHashLogType, "",
aih.AppUUID, aih.LogKey())
oldAih, ok := old.(AppAndImageToHash)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of AppAndImageToHash type")
}
if oldAih.Hash != aih.Hash ||
oldAih.PurgeCounter != aih.PurgeCounter {
logObject.CloneAndAddField("purge-counter-int64", aih.PurgeCounter).
AddField("image-id", aih.ImageID.String()).
AddField("hash", aih.Hash).
AddField("purge-counter-int64", aih.PurgeCounter).
AddField("old-hash", oldAih.Hash).
AddField("old-purge-counter-int64", oldAih.PurgeCounter).
Noticef("App and image to hash modify")
} else {
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldAih, aih)).
Noticef("App and image to hash modify other change")
}
}
// LogDelete :
func (aih AppAndImageToHash) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.AppAndImageToHashLogType, "",
aih.AppUUID, aih.LogKey())
logObject.CloneAndAddField("purge-counter-int64", aih.PurgeCounter).
AddField("image-id", aih.ImageID.String()).
AddField("hash", aih.Hash).
Noticef("App and image to hash delete")
base.DeleteLogObject(logBase, aih.LogKey())
}
// LogKey :
func (aih AppAndImageToHash) LogKey() string {
return string(base.AppAndImageToHashLogType) + "-" + aih.Key()
}