-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathphysicalioadapters.go
113 lines (98 loc) · 3.52 KB
/
physicalioadapters.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
// Copyright (c) 2019 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package types
// PhysicalIoAdapters on the device given by the cloud.
// These are translated to AssignableAdapters
import (
"github.com/google/go-cmp/cmp"
zcommon "github.com/lf-edge/eve-api/go/evecommon"
"github.com/lf-edge/eve/pkg/pillar/base"
"github.com/lf-edge/eve/pkg/pillar/sriov"
)
// PhysicalAddress - Structure that represents various attributes related
// to the addressing of the Adapter
type PhysicalAddress struct {
PciLong string
Ifname string
Serial string
Irq string
Ioports string
UsbAddr string
UsbProduct string
// unknownType - If a type in config is unknown, store it here.
UnknownType string
}
// PhyIOUsagePolicy - Usage policy for the Adapter
// This is constructed from api/proto/config/devmodel.proto PhyIOUsagePolicy
// Keep the two structures consistent
type PhyIOUsagePolicy struct {
// FreeUplink is needed while we transition to just a Cost integer
FreeUplink bool
}
// PhysicalIOAdapter - Object used to store Adapter configuration (L1)
// from controller for each Adapter.
type PhysicalIOAdapter struct {
Ptype zcommon.PhyIoType // Type of IO Device
Phylabel string // Label printed on the enclosure
Phyaddr PhysicalAddress
Logicallabel string // Label assigned by model creator
Assigngrp string
Parentassigngrp string
Usage zcommon.PhyIoMemberUsage
UsagePolicy PhyIOUsagePolicy
Vfs sriov.VFList // Used only for Physical Functions PFs
Cbattr map[string]string // Used for additional attributes
}
// PhysicalIOAdapterList - List of Physical Adapters to be used on the
// device by EVE from the controller
type PhysicalIOAdapterList struct {
Initialized bool
AdapterList []PhysicalIOAdapter
}
// Key returns the key for pubsub
func (ioAdapterList PhysicalIOAdapterList) Key() string {
return "global"
}
// LogCreate :
func (ioAdapterList PhysicalIOAdapterList) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.PhysicalIOAdapterListLogType, "",
nilUUID, ioAdapterList.LogKey())
if logObject == nil {
return
}
logObject.Noticef("Onboarding ioAdapterList create")
}
// LogModify :
func (ioAdapterList PhysicalIOAdapterList) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.PhysicalIOAdapterListLogType, "",
nilUUID, ioAdapterList.LogKey())
oldIoAdapterList, ok := old.(PhysicalIOAdapterList)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of PhysicalIOAdapterList type")
}
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldIoAdapterList, ioAdapterList)).
Noticef("Onboarding ioAdapterList modify")
}
// LogDelete :
func (ioAdapterList PhysicalIOAdapterList) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.PhysicalIOAdapterListLogType, "",
nilUUID, ioAdapterList.LogKey())
logObject.Noticef("Onboarding ioAdapterList delete")
base.DeleteLogObject(logBase, ioAdapterList.LogKey())
}
// LogKey :
func (ioAdapterList PhysicalIOAdapterList) LogKey() string {
return string(base.PhysicalIOAdapterListLogType) + "-" + ioAdapterList.Key()
}
// LookupAdapter - look up an Adapter by its phylabel
func (ioAdapterList *PhysicalIOAdapterList) LookupAdapter(
phylabel string) *PhysicalIOAdapter {
for indx := range ioAdapterList.AdapterList {
adapter := &ioAdapterList.AdapterList[indx]
if adapter.Phylabel == phylabel {
return adapter
}
}
return nil
}