Skip to content

Commit 042062f

Browse files
pillar: report device name to controller/LOC
a DeviceInfoMsg is used for that Signed-off-by: Christoph Ostarek <[email protected]>
1 parent 8d05306 commit 042062f

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

pkg/pillar/cmd/zedagent/handleconfig.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ type L2Adapter struct {
7070
lowerPhysPorts []*types.PhysicalIOAdapter
7171
}
7272

73+
// contains fields that are sent in the DeviceInfo message to the
74+
// controller and to LOC
75+
type deviceInfoFields struct {
76+
deviceName string
77+
enterpriseName string
78+
enterpriseId string
79+
projectName string
80+
projectId string
81+
}
82+
7383
type getconfigContext struct {
7484
zedagentCtx *zedagentContext // Cross link
7585
ledBlinkCount types.LedBlinkCount // Current count
@@ -158,6 +168,8 @@ type getconfigContext struct {
158168
localCommands *types.LocalCommands
159169
}
160170

171+
deviceInfoFields deviceInfoFields
172+
161173
configRetryUpdateCounter uint32 // received from config
162174

163175
// Frequency in seconds at which metrics is published to the controller.
@@ -885,6 +897,11 @@ func getLatestConfig(getconfigCtx *getconfigContext, iteration int,
885897
url = controllerconn.URLPathString(locURL, ctrlClient.UsingV2API(),
886898
devUUID, "compound-config")
887899

900+
// send DeviceInfoMsg to inform LOC about device name, enterprise and project
901+
// send it regularly in case LOC exits (f.e. crash), as the LOC is expected
902+
// in to be in the local network, the traffic is negligible
903+
getconfigCtx.zedagentCtx.triggerDeviceInfo <- LOCDest
904+
888905
// Request compound config, if LOC configuration is outdated, then we
889906
// get @obsoleteConfig return value (see parseConfig() for details)
890907
// and we repeat on the next fetch attempt

pkg/pillar/cmd/zedagent/parseconfig.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ const (
4343
maxVlanID = 4094
4444
)
4545

46+
func (dif *deviceInfoFields) parseConfig(config *zconfig.EdgeDevConfig) {
47+
dif.deviceName = config.DeviceName
48+
dif.enterpriseName = config.EnterpriseName
49+
dif.enterpriseId = config.EnterpriseId
50+
dif.projectName = config.ProductName
51+
dif.projectId = config.ProjectId
52+
}
53+
4654
func parseConfig(getconfigCtx *getconfigContext, config *zconfig.EdgeDevConfig,
4755
source configSource) configProcessingRetval {
4856

@@ -51,6 +59,8 @@ func parseConfig(getconfigCtx *getconfigContext, config *zconfig.EdgeDevConfig,
5159
getconfigCtx.sideController.Lock()
5260
defer getconfigCtx.sideController.Unlock()
5361

62+
getconfigCtx.deviceInfoFields.parseConfig(config)
63+
5464
// Make sure we do not accidentally revert to an older configuration.
5565
// This depends on the controller attaching config timestamp.
5666
// If not provided, the check is skipped.

pkg/pillar/cmd/zedagent/reportinfo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ func PublishDeviceInfoToZedCloud(ctx *zedagentContext, dest destinationBitset) {
226226
log.Functionf("PublishDeviceInfoToZedCloud uuid %s", deviceUUID)
227227

228228
ReportDeviceInfo := new(info.ZInfoDevice)
229+
ReportDeviceInfo.DeviceName = ctx.getconfigCtx.deviceInfoFields.enterpriseName
230+
ReportDeviceInfo.EnterpriseName = ctx.getconfigCtx.deviceInfoFields.enterpriseName
231+
ReportDeviceInfo.EnterpriseId = ctx.getconfigCtx.deviceInfoFields.enterpriseId
232+
ReportDeviceInfo.ProjectName = ctx.getconfigCtx.deviceInfoFields.projectName
233+
ReportDeviceInfo.ProjectId = ctx.getconfigCtx.deviceInfoFields.projectId
229234

230235
// Get the remote access status
231236
ReportDeviceInfo.RemoteAccessDisabled = utils.RemoteAccessDisabled()

pkg/pillar/cmd/zedagent/zedagent.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"fmt"
3232
"os"
3333
"sort"
34+
"sync/atomic"
3435
"time"
3536

3637
"github.com/eriknordmark/ipinfo"
@@ -657,6 +658,7 @@ func (zedagentCtx *zedagentContext) init() {
657658
// edge-view configure
658659
configEdgeview: &types.EdgeviewConfig{},
659660
}
661+
getconfigCtx.sideControllerSentInitialDeviceInfoMsg.Store(false)
660662
getconfigCtx.sideController.localServerMap = &localServerMap{}
661663

662664
cipherCtx := &cipherContext{}

0 commit comments

Comments
 (0)