-
Notifications
You must be signed in to change notification settings - Fork 156
/
handlebaseos.go
143 lines (123 loc) · 3.81 KB
/
handlebaseos.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
// Copyright (c) 2017-2018 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
// basic zboot partition status APIs
package zedagent
import (
"github.com/lf-edge/eve/pkg/pillar/types"
"strings"
)
// base os status event handlers
// Report BaseOsStatus to zedcloud
func handleBaseOsStatusCreate(ctxArg interface{}, key string,
statusArg interface{}) {
handleBaseOsStatusImpl(ctxArg, key, statusArg)
}
func handleBaseOsStatusModify(ctxArg interface{}, key string,
statusArg interface{}, oldStatusArg interface{}) {
handleBaseOsStatusImpl(ctxArg, key, statusArg)
}
func handleBaseOsStatusImpl(ctxArg interface{}, key string,
statusArg interface{}) {
ctx := ctxArg.(*zedagentContext)
triggerPublishDevInfo(ctx)
log.Functionf("handleBaseOsStatusImpl(%s) done", key)
}
func handleBaseOsStatusDelete(ctxArg interface{}, key string,
statusArg interface{}) {
log.Functionf("handleBaseOsStatusDelete(%s)", key)
ctx := ctxArg.(*zedagentContext)
triggerPublishDevInfo(ctx)
log.Functionf("handleBaseOsStatusDelete(%s) done", key)
}
func handleZbootStatusCreate(ctxArg interface{}, key string,
statusArg interface{}) {
handleZbootStatusImpl(ctxArg, key, statusArg)
}
func handleZbootStatusModify(ctxArg interface{}, key string,
statusArg interface{}, oldStatusArg interface{}) {
handleZbootStatusImpl(ctxArg, key, statusArg)
}
func handleZbootStatusImpl(ctxArg interface{}, key string,
statusArg interface{}) {
ctx := ctxArg.(*zedagentContext)
if !isZbootValidPartitionLabel(key) {
log.Errorf("handleZbootStatusImpl: invalid key %s", key)
return
}
log.Functionf("handleZbootStatusImpl: for %s", key)
// nothing to do
triggerPublishDevInfo(ctx)
}
func handleZbootStatusDelete(ctxArg interface{}, key string,
statusArg interface{}) {
if !isZbootValidPartitionLabel(key) {
log.Errorf("handleZbootStatusDelete: invalid key %s", key)
return
}
log.Functionf("handleZbootStatusDelete: for %s", key)
// Nothing to do
}
// utility routines to access baseos partition status
func isZbootValidPartitionLabel(name string) bool {
partitionNames := []string{"IMGA", "IMGB"}
for _, partName := range partitionNames {
if name == partName {
return true
}
}
return false
}
func getZbootPartitionStatusAll(ctx *zedagentContext) map[string]interface{} {
sub := ctx.subZbootStatus
items := sub.GetAll()
return items
}
func getZbootPartitionStatus(ctx *zedagentContext, partName string) *types.ZbootStatus {
partName = strings.TrimSpace(partName)
if !isZbootValidPartitionLabel(partName) {
log.Errorf("getZbootPartitionStatus(%s) invalid partition", partName)
return nil
}
sub := ctx.subZbootStatus
st, err := sub.Get(partName)
if err != nil {
log.Errorf("getZbootPartitionStatus(%s) not found", partName)
return nil
}
status := st.(types.ZbootStatus)
return &status
}
func getZbootCurrentPartition(ctx *zedagentContext) string {
var partName string
items := getZbootPartitionStatusAll(ctx)
for _, st := range items {
status := st.(types.ZbootStatus)
if status.CurrentPartition {
log.Tracef("getZbootCurrentPartition:%s", status.PartitionLabel)
return status.PartitionLabel
}
}
log.Errorf("getZbootCurrentPartition() not found")
return partName
}
func getZbootOtherPartition(ctx *zedagentContext) string {
var partName string
items := getZbootPartitionStatusAll(ctx)
for _, st := range items {
status := st.(types.ZbootStatus)
if !status.CurrentPartition {
log.Tracef("getZbootOtherPartition:%s", status.PartitionLabel)
return status.PartitionLabel
}
}
log.Errorf("getZbootOtherPartition() not found")
return partName
}
func signalBaseOSConfigConfigRestarted(ctx *getconfigContext) {
log.Trace("signalBaseOSConfigConfigRestarted")
pub := ctx.pubBaseOsConfig
if err := pub.SignalRestarted(); err != nil {
log.Errorf("failed to SignalRestarted: %s", err)
}
log.Trace("signalBaseOSConfigConfigRestarted done")
}