Skip to content

Commit 2f62aed

Browse files
committed
source/system: Add reading vendor information
Add reading vendor information from /sys/devices/virtual/dmi/id/sys_vendor Signed-off-by: Oleg Zhurakivskyy <[email protected]>
1 parent 491627e commit 2f62aed

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

docs/usage/customization-guide.md

+2
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,8 @@ The following features are available for matching:
979979
| | | **`<sysfs-attribute>`** | string | Sysfs network interface attribute, available attributes: `dax`, `rotational`, `nr_zones`, `zoned` |
980980
| **`system.osrelease`** | attribute | | | System identification data from `/etc/os-release` |
981981
| | | **`<parameter>`** | string | One parameter from `/etc/os-release` |
982+
| **`system.dmiid`** | attribute | | | DMI identification data from `/sys/devices/virtual/dmi/id/` |
983+
| | | **`sys_vendor`** | string | Vendor name from `/sys/devices/virtual/dmi/id/sys_vendor` |
982984
| **`system.name`** | attribute | | | System name information |
983985
| | | **`nodename`** | string | Name of the kubernetes node object |
984986
| **`usb.device`** | instance | | | USB devices present in the system |

examples/nodefeature.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ spec:
6565
VERSION_ID: "22.04"
6666
VERSION_ID.major: "22"
6767
VERSION_ID.minor: "04"
68+
system.dmiid:
69+
elements:
70+
sys_vendor: VendorUnknown
6871
flags:
6972
cpu.cpuid:
7073
elements:

source/system/system.go

+27
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const Name = "system"
4343
const (
4444
OsReleaseFeature = "osrelease"
4545
NameFeature = "name"
46+
DmiIdFeature = "dmiid"
4647
)
4748

4849
// systemSource implements the FeatureSource and LabelSource interfaces.
@@ -101,6 +102,22 @@ func (s *systemSource) Discover() error {
101102
}
102103
}
103104

105+
// Get DMI ID attributes
106+
dmiIDAttributeNames := []string{"sys_vendor"}
107+
dmiAttrs := make(map[string]string)
108+
for _, name := range dmiIDAttributeNames {
109+
val, err := getDmiIDAttribute(name)
110+
if err != nil {
111+
klog.ErrorS(err, "failed to get DMI entry", "attributeName", name)
112+
} else {
113+
dmiAttrs[name] = val
114+
}
115+
}
116+
117+
if len(dmiAttrs) > 0 {
118+
s.features.Attributes[DmiIdFeature] = nfdv1alpha1.NewAttributeFeatures(dmiAttrs)
119+
}
120+
104121
klog.V(3).InfoS("discovered features", "featureSource", s.Name(), "features", utils.DelayedDumper(s.features))
105122

106123
return nil
@@ -153,6 +170,16 @@ func splitVersion(version string) map[string]string {
153170
return components
154171
}
155172

173+
// Read /sys/devices/virtual/dmi/id attribute
174+
func getDmiIDAttribute(name string) (string, error) {
175+
s, err := os.ReadFile(hostpath.SysfsDir.Path("devices/virtual/dmi/id/", name))
176+
if err != nil {
177+
return "", err
178+
}
179+
180+
return strings.TrimSpace(string(s)), nil
181+
}
182+
156183
func init() {
157184
source.Register(&src)
158185
}

0 commit comments

Comments
 (0)