-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathzedagenttypes.go
757 lines (673 loc) · 24.2 KB
/
zedagenttypes.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
// Copyright (c) 2017 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package types
import (
"fmt"
"strings"
"time"
"github.com/google/go-cmp/cmp"
"github.com/lf-edge/eve-api/go/info"
"github.com/lf-edge/eve/pkg/pillar/base"
uuid "github.com/satori/go.uuid"
)
// BaseOsConfig is what we assume will come from the ZedControl for base OS.
// We assume ContentTreeUUID should be installed, but activation
// is driven by the Activate attribute.
type BaseOsConfig struct {
BaseOsVersion string
ContentTreeUUID string
RetryUpdateCounter uint32
Activate bool
}
func (config BaseOsConfig) Key() string {
return config.ContentTreeUUID
}
// LogCreate :
func (config BaseOsConfig) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.BaseOsConfigLogType, config.BaseOsVersion,
nilUUID, config.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("activate", config.Activate).
Noticef("BaseOs config create")
}
// LogModify :
func (config BaseOsConfig) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.BaseOsConfigLogType, config.BaseOsVersion,
nilUUID, config.LogKey())
oldConfig, ok := old.(BaseOsConfig)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of BaseOsConfig type")
}
if oldConfig.Activate != config.Activate {
logObject.CloneAndAddField("activate", config.Activate).
AddField("old-activate", oldConfig.Activate).
Noticef("BaseOs config modify")
} else {
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldConfig, config)).
Noticef("BaseOs config modify other change")
}
}
// LogDelete :
func (config BaseOsConfig) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.BaseOsConfigLogType, config.BaseOsVersion,
nilUUID, config.LogKey())
logObject.CloneAndAddField("activate", config.Activate).
Noticef("BaseOs config delete")
base.DeleteLogObject(logBase, config.LogKey())
}
// LogKey :
func (config BaseOsConfig) LogKey() string {
return string(base.BaseOsConfigLogType) + "-" + config.BaseOsVersion
}
// BaseOsStatus indexed by ContentTreeUUID as above
type BaseOsStatus struct {
BaseOsVersion string
Activated bool
TooEarly bool // Failed since previous was inprogress/test
ContentTreeUUID string
PartitionLabel string
PartitionDevice string // From zboot
PartitionState string // From zboot
// Minimum state across all steps/StorageStatus.
// Error* set implies error.
State SwState
// error strings across all steps/StorageStatus
// ErrorAndTime provides SetErrorNow() and ClearError()
ErrorAndTime
}
func (status BaseOsStatus) Key() string {
return status.ContentTreeUUID
}
// LogCreate :
func (status BaseOsStatus) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.BaseOsStatusLogType, status.BaseOsVersion,
nilUUID, status.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("state", status.State.String()).
Noticef("BaseOs status create")
}
// LogModify :
func (status BaseOsStatus) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.BaseOsStatusLogType, status.BaseOsVersion,
nilUUID, status.LogKey())
oldStatus, ok := old.(BaseOsStatus)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of BaseOsStatus type")
}
if oldStatus.State != status.State {
logObject.CloneAndAddField("state", status.State.String()).
AddField("old-state", oldStatus.State.String()).
Noticef("BaseOs status modify")
} else {
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldStatus, status)).
Noticef("BaseOs status modify other change")
}
if status.HasError() {
errAndTime := status.ErrorAndTime
logObject.CloneAndAddField("state", status.State.String()).
AddField("error", errAndTime.Error).
AddField("error-time", errAndTime.ErrorTime).
Noticef("BaseOs status modify")
}
}
// LogDelete :
func (status BaseOsStatus) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.BaseOsStatusLogType, status.BaseOsVersion,
nilUUID, status.LogKey())
logObject.CloneAndAddField("state", status.State.String()).
Noticef("BaseOs status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey :
func (status BaseOsStatus) LogKey() string {
return string(base.BaseOsStatusLogType) + "-" + status.BaseOsVersion
}
// return value holder
type RetStatus struct {
Changed bool
MinState SwState
AllErrors string
ErrorTime time.Time
}
// Mirrors proto definition for ConfigItem
// The value can be bool, float, uint, or string
type ConfigItem struct {
Key string
Value interface{}
}
// Mirrors proto definition for MetricItem
// The value can be bool, float, uint, or string
type MetricItem struct {
Key string
Type MetricItemType
Value interface{}
}
type MetricItemType uint8
const (
MetricItemOther MetricItemType = iota // E.g., a string like an ESSID
MetricItemGauge // Goes up and down over time
MetricItemCounter // Monotonically increasing (until reboot)
MetricItemState // Toggles on and off; count transitions
)
type DatastoreConfig struct {
UUID uuid.UUID
DsType string
Fqdn string
ApiKey string // XXX: to be deprecated, use CipherBlockStatus instead
Password string // XXX: to be deprecated, use CipherBlockStatus instead
Dpath string // depending on DsType, it could be bucket or path
Region string
DsCertPEM [][]byte // cert chain used for the datastore
// CipherBlockStatus, for encrypted credentials
CipherBlockStatus
}
// Key is the key in pubsub
func (config DatastoreConfig) Key() string {
return config.UUID.String()
}
// LogCreate :
func (config DatastoreConfig) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.DatastoreConfigLogType, "",
config.UUID, config.LogKey())
if logObject == nil {
return
}
logObject.Noticef("Datastore config create")
}
// LogModify :
func (config DatastoreConfig) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.DatastoreConfigLogType, "",
config.UUID, config.LogKey())
oldConfig, ok := old.(DatastoreConfig)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of DatastoreConfig type")
}
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldConfig, config)).
Noticef("Datastore config modify")
}
// LogDelete :
func (config DatastoreConfig) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.DatastoreConfigLogType, "",
config.UUID, config.LogKey())
logObject.Noticef("Datastore config delete")
base.DeleteLogObject(logBase, config.LogKey())
}
// LogKey :
func (config DatastoreConfig) LogKey() string {
return string(base.DatastoreConfigLogType) + "-" + config.Key()
}
// BootReason captures our best guess of why the device (re)booted
type BootReason uint8
// BootReasonNone is the initial value, followed by three normal reasons
// to boot/reboot, and then different error reasons
// Must match the values in api/proto/info/info.proto.BootReason
const (
BootReasonNone BootReason = iota
BootReasonFirst // Normal - was not yet onboarded
BootReasonRebootCmd // Normal - result of a reboot command in the API
BootReasonUpdate // Normal - from an EVE image update in the API
BootReasonFallback // Fallback from a failed EVE image update
BootReasonDisconnect // Disconnected from controller for too long
BootReasonFatal // Fatal error causing log.Fatal
BootReasonOOM // OOM causing process to be killed
BootReasonWatchdogHung // Software watchdog due stuck agent
BootReasonWatchdogPid // Software watchdog due to e.g., golang panic
BootReasonKernel // Set by dump-capture kernel, see docs/KERNEL-DUMPS.md and pkg/kdump/kdump.sh for details
BootReasonPowerFail // Known power failure e.g., from disk controller S.M.A.R.T counter increase
BootReasonUnknown // Could be power failure, kernel panic, or hardware watchdog
BootReasonVaultFailure // Vault was not ready within the expected time
BootReasonPoweroffCmd // Start after Local Profile Server poweroff
BootReasonParseFail = 255 // BootReasonFromString didn't find match
)
// String returns the string name
func (br BootReason) String() string {
switch br {
case BootReasonNone:
return "BootReasonNone"
case BootReasonFirst:
return "BootReasonFirst"
case BootReasonRebootCmd:
return "BootReasonRebootCmd"
case BootReasonUpdate:
return "BootReasonUpdate"
case BootReasonFallback:
return "BootReasonFallback"
case BootReasonDisconnect:
return "BootReasonDisconnect"
case BootReasonFatal:
return "BootReasonFatal"
case BootReasonOOM:
return "BootReasonOOM"
case BootReasonWatchdogHung:
return "BootReasonWatchdogHung"
case BootReasonWatchdogPid:
return "BootReasonWatchdogPid"
case BootReasonKernel:
return "BootReasonKernel"
case BootReasonPowerFail:
return "BootReasonPowerFail"
case BootReasonUnknown:
return "BootReasonUnknown"
case BootReasonVaultFailure:
return "BootReasonVaultFailure"
case BootReasonPoweroffCmd:
return "BootReasonPoweroffCmd"
default:
return fmt.Sprintf("Unknown BootReason %d", br)
}
}
// StartWithSavedConfig indicates a normal reboot where we should immediately
// start the applications.
// Note that on most platforms we get Unknown for a power cycle
func (br BootReason) StartWithSavedConfig() bool {
switch br {
case BootReasonNone:
return false
case BootReasonFirst:
return false
case BootReasonRebootCmd:
return true
case BootReasonUpdate:
return true
case BootReasonFallback:
return false
case BootReasonDisconnect:
return true
case BootReasonFatal:
return false
case BootReasonOOM:
return false
case BootReasonWatchdogHung:
return false
case BootReasonWatchdogPid:
return false
case BootReasonKernel:
return true // XXX get false Kernel for power cycle events?
case BootReasonPowerFail:
return true
case BootReasonUnknown:
return true
case BootReasonVaultFailure:
return false
case BootReasonPoweroffCmd:
return true
default:
return false
}
}
// BootReasonFromString parses what above String produced
// Empty string is returned as None
func BootReasonFromString(str string) BootReason {
str = strings.TrimSuffix(str, "\n")
str = strings.TrimSpace(str)
switch str {
case "", "BootReasonNone":
return BootReasonNone
case "BootReasonFirst":
return BootReasonFirst
case "BootReasonRebootCmd":
return BootReasonRebootCmd
case "BootReasonUpdate":
return BootReasonUpdate
case "BootReasonFallback":
return BootReasonFallback
case "BootReasonDisconnect":
return BootReasonDisconnect
case "BootReasonFatal":
return BootReasonFatal
case "BootReasonOOM":
return BootReasonOOM
case "BootReasonWatchdogHung":
return BootReasonWatchdogHung
case "BootReasonWatchdogPid":
return BootReasonWatchdogPid
case "BootReasonKernel":
return BootReasonKernel
case "BootReasonPowerFail":
return BootReasonPowerFail
case "BootReasonUnknown":
return BootReasonUnknown
case "BootReasonVaultFailure":
return BootReasonVaultFailure
case "BootReasonPoweroffCmd":
return BootReasonPoweroffCmd
default:
return BootReasonParseFail
}
}
// MaintenanceModeReason captures reason for entering into maintenance mode
type MaintenanceModeReason uint8
// MaintenanceModeReason codes for storing reason for getting into maintenance mode
const (
MaintenanceModeReasonNone MaintenanceModeReason = iota
MaintenanceModeReasonUserRequested
MaintenanceModeReasonVaultLockedUp
MaintenanceModeReasonNoDiskSpace
)
// String returns the verbose equivalent of MaintenanceModeReason code
func (mmr MaintenanceModeReason) String() string {
switch mmr {
case MaintenanceModeReasonNone:
return "MaintenanceModeReasonNone"
case MaintenanceModeReasonUserRequested:
return "MaintenanceModeReasonUserRequested"
case MaintenanceModeReasonVaultLockedUp:
return "MaintenanceModeReasonVaultLockedUp"
case MaintenanceModeReasonNoDiskSpace:
return "MaintenanceModeReasonNoDiskSpace"
default:
return fmt.Sprintf("Unknown MaintenanceModeReason %d", mmr)
}
}
// NodeAgentStatus :
type NodeAgentStatus struct {
Name string
CurPart string
UpdateInprogress bool
RemainingTestTime time.Duration
DeviceReboot bool
DeviceShutdown bool
DevicePoweroff bool
AllDomainsHalted bool // Progression of reboot etc
RebootReason string // From last reboot
BootReason BootReason // From last reboot
RebootStack string // From last reboot
RebootTime time.Time // From last reboot
RestartCounter uint32
RebootImage string
LocalMaintenanceMode bool //enter Maintenance Mode
LocalMaintenanceModeReason MaintenanceModeReason //reason for Maintenance Mode
HVTypeKube bool
}
// Key :
func (status NodeAgentStatus) Key() string {
return status.Name
}
// LogCreate :
func (status NodeAgentStatus) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.NodeAgentStatusLogType, status.Name,
nilUUID, status.LogKey())
if logObject == nil {
return
}
logObject.Noticef("Nodeagent status create")
}
// LogModify :
func (status NodeAgentStatus) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.NodeAgentStatusLogType, status.Name,
nilUUID, status.LogKey())
oldStatus, ok := old.(NodeAgentStatus)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of NodeAgentStatus type")
}
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldStatus, status)).
Noticef("Nodeagent status modify")
}
// LogDelete :
func (status NodeAgentStatus) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.NodeAgentStatusLogType, status.Name,
nilUUID, status.LogKey())
logObject.Noticef("Nodeagent status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey :
func (status NodeAgentStatus) LogKey() string {
return string(base.NodeAgentStatusLogType) + "-" + status.Key()
}
// ConfigGetStatus : Config Get Status from Controller
type ConfigGetStatus uint8
// ConfigGetSuccess : Config get is successful
const (
ConfigGetSuccess ConfigGetStatus = iota + 1
ConfigGetFail
ConfigGetTemporaryFail
ConfigGetReadSaved
)
// DeviceOperation is an operation on device
type DeviceOperation uint8
const (
//DeviceOperationReboot reboot the device
DeviceOperationReboot DeviceOperation = iota
//DeviceOperationShutdown shutdown all app instances on device
DeviceOperationShutdown
//DeviceOperationPoweroff is shutdown plus poweroff. Not setable from controller
DeviceOperationPoweroff
)
// String returns the verbose equivalent of DeviceOperation code
func (do DeviceOperation) String() string {
switch do {
case DeviceOperationReboot:
return "reboot"
case DeviceOperationShutdown:
return "shutdown"
case DeviceOperationPoweroff:
return "poweroff"
default:
return fmt.Sprintf("Unknown DeviceOperation %d", do)
}
}
// ZedAgentStatus :
type ZedAgentStatus struct {
Name string
ConfigGetStatus ConfigGetStatus
RebootCmd bool
ShutdownCmd bool
PoweroffCmd bool
RequestedRebootReason string // Why we will reboot
RequestedBootReason BootReason // Why we will reboot
MaintenanceMode bool // Don't run apps etc
ForceFallbackCounter int // Try image fallback when counter changes
CurrentProfile string // Current profile
RadioSilence RadioSilence // Currently requested state of radio devices
DeviceState DeviceState
AttestState AttestState
AttestError string
VaultStatus info.DataSecAtRestStatus
PCRStatus info.PCRStatus
VaultErr string
}
// DeviceState represents overall state
type DeviceState uint8
// Integer values must match those in ZDeviceState in lf-edge/eve-api/proto/info/info.proto
//
//revive:disable:var-naming
const (
DEVICE_STATE_UNSPECIFIED DeviceState = iota
DEVICE_STATE_ONLINE = 1
DEVICE_STATE_REBOOTING = 2
DEVICE_STATE_MAINTENANCE_MODE = 3
DEVICE_STATE_BASEOS_UPDATING = 4
DEVICE_STATE_BOOTING = 5
DEVICE_STATE_PREPARING_POWEROFF = 6
DEVICE_STATE_POWERING_OFF = 7
DEVICE_STATE_PREPARED_POWEROFF = 8
)
//revive:enable:var-naming
func (ds DeviceState) String() string {
switch ds {
case DEVICE_STATE_UNSPECIFIED:
return "unspecified"
case DEVICE_STATE_ONLINE:
return "online"
case DEVICE_STATE_REBOOTING:
return "rebooting"
case DEVICE_STATE_MAINTENANCE_MODE:
return "maintenance_mode"
case DEVICE_STATE_BASEOS_UPDATING:
return "baseos_updating"
case DEVICE_STATE_BOOTING:
return "booting"
case DEVICE_STATE_PREPARING_POWEROFF:
return "preparing_poweroff"
case DEVICE_STATE_POWERING_OFF:
return "powering_off"
case DEVICE_STATE_PREPARED_POWEROFF:
return "prepared_poweroff"
default:
return fmt.Sprintf("Unknown state %d", ds)
}
}
// Key :
func (status ZedAgentStatus) Key() string {
return status.Name
}
// LogCreate :
func (status ZedAgentStatus) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.ZedAgentStatusLogType, status.Name,
nilUUID, status.LogKey())
if logObject == nil {
return
}
logObject.Noticef("Zedagent status create")
}
// LogModify :
func (status ZedAgentStatus) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.ZedAgentStatusLogType, status.Name,
nilUUID, status.LogKey())
oldStatus, ok := old.(ZedAgentStatus)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of ZedAgentStatus type")
}
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldStatus, status)).
Noticef("Zedagent status modify")
}
// LogDelete :
func (status ZedAgentStatus) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.ZedAgentStatusLogType, status.Name,
nilUUID, status.LogKey())
logObject.Noticef("Zedagent status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey :
func (status ZedAgentStatus) LogKey() string {
return string(base.ZedAgentStatusLogType) + "-" + status.Key()
}
// DeviceOpsCmd - copy of zconfig.DeviceOpsCmd
type DeviceOpsCmd struct {
Counter uint32
DesiredState bool
OpsTime string
}
// BaseOSMgrStatus : for sending from baseosmgr
type BaseOSMgrStatus struct {
CurrentRetryUpdateCounter uint32 // CurrentRetryUpdateCounter from baseosmgr
}
// RadioSilence : used in ZedAgentStatus to record the *requested* state of radio devices.
// Also used in DeviceNetworkStatus to publish the *actual* state of radios.
// InProgress is used to wait for the operation changing the radio state
// to finalize before publishing the status update.
// RequestedAt is used to match the request published by zedagent with the response
// published by nim.
//
// When zedagent receives new radio configuration from the local profile server,
// it publishes new ZedAgentStatus with RadioSilence.ChangeRequestedAt set to time.Now(),
// RadioSilence.ChangeInProgress set to true and RadioSilence.Imposed copying RadioConfig.RadioSilence
// (true or false).
// When nim receives ZedAgentStatus, it checks if ChangeRequestedAt is greater than
// the timestamp of the last seen radio configuration change. If it is the case, it copies
// ChangeRequestedAt and ChangeInProgress (=true) from ZedAgentStatus. RadioSilence to
// DeviceNetworkStatus.RadioSilence and starts switching radios of wireless devices ON/OFF
// (in cooperation with wwan service).
// Once nim is done with all radio devices, it updates RadioSilence of DeviceNetworkStatus and sets
// ChangeInProgress to false and Imposed to reflect the actual radio state (could be different
// from the intended state if operation failed).
// When zedagent sees DeviceNetworkStatus with RadioSilence where CHangeRequestedAt equals
// the last configuration request time and ChangeInProgress has changed to false, it knows
// that the operation has finalized and it can publish the status up to the local profile server.
// Note that while ChangeInProgress is true, zedagent is neither publishing radio status
// nor obtaining configuration updates from the local profile server.
type RadioSilence struct {
// If true, all radio devices are switched off.
Imposed bool
// ChangeInProgress is true if change in the radio state is still in-progress.
ChangeInProgress bool
// Time when the last change in the radio state was requested (by a local profile server).
ChangeRequestedAt time.Time
// If the last radio configuration change failed, error message is reported here.
ConfigError string
}
// String prints the currently imposed state for radio transmitting.
// Note: to print the whole structure (including Change* and ConfigError fields), use %#v
// as the formatting directive.
func (am RadioSilence) String() string {
if am.Imposed {
return "Radio transmitters OFF"
}
return "Radio transmitters ON"
}
// LocalCommands : commands triggered locally via Local profile server.
type LocalCommands struct {
// Locally issued app commands.
// For every app there is entry only for the last command (completed
// or still in progress). Previous commands are not remembered.
AppCommands map[string]*LocalAppCommand // key: app UUID
// Counters for locally issued app commands.
AppCounters map[string]*LocalAppCounters // key: app UUID
// Local volume generation counters.
VolumeGenCounters map[string]int64 // key: volume UUID
}
// Empty : returns true if there were no commands triggered locally
// (for currently deployed apps and volumes).
func (lc *LocalCommands) Empty() bool {
return len(lc.AppCommands) == 0 && len(lc.AppCounters) == 0 &&
len(lc.VolumeGenCounters) == 0
}
// AppCommand : application command requested to run by a local server.
type AppCommand uint8
// Integer values are in-sync with proto enum AppCommand_Command.
const (
// AppCommandUnspecified : command was not specified (invalid input).
AppCommandUnspecified AppCommand = iota
// AppCommandRestart : restart application without re-creating volumes.
AppCommandRestart
// AppCommandPurge : purge application with ALL of its volumes.
AppCommandPurge
)
// LocalAppCommand : An application command requested from a local server.
type LocalAppCommand struct {
// Command to execute.
Command AppCommand
// LocalServerTimestamp : timestamp made by the local server when the request was created.
LocalServerTimestamp uint64
// DeviceTimestamp : timestamp made by EVE when the request was received.
DeviceTimestamp time.Time
// Completed is set to true by zedagent once the command completes.
Completed bool
// LastCompletedTimestamp : (server) timestamp of the last command completed for this app.
// If Completed is true, then this happens to be the same as LocalServerTimestamp.
LastCompletedTimestamp uint64
}
// LocalAppCounters : counters for locally issued application commands.
type LocalAppCounters struct {
// RestartCmd : contains counter counting how many restart requests have been submitted
// via local server for this application in total (including uncompleted requests).
RestartCmd AppInstanceOpsCmd
// PurgeCounter : contains counter counting how many purge requests have been submitted
// via local server for this application in total (including uncompleted requests).
PurgeCmd AppInstanceOpsCmd
}
// DevCommand : application command requested to run by a local server.
type DevCommand uint8
// Integer values are in-sync with proto enum LocalDevCmd_Command.
const (
// DevCommandUnspecified : command was not specified (invalid input).
DevCommandUnspecified DevCommand = iota
// DevCommandShutdown : shut down all app instances
DevCommandShutdown
// DevCommandShutdownPoweroff : shut down all app instances + poweroff
DevCommandShutdownPoweroff
)
// LOCConfig : configuration of the Local Operator Console
type LOCConfig struct {
// LOC URL
LocURL string
}