Skip to content

Commit

Permalink
source/system: Add reading vendor information
Browse files Browse the repository at this point in the history
Add reading vendor information from /sys/devices/virtual/dmi/id/sys_vendor

Signed-off-by: Oleg Zhurakivskyy <[email protected]>
  • Loading branch information
ozhuraki committed Jan 31, 2024
1 parent 5c99ae8 commit 4bf7cf5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/usage/customization-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,8 @@ The following features are available for matching:
| | | **`<sysfs-attribute>`** | string | Sysfs network interface attribute, available attributes: `dax`, `rotational`, `nr_zones`, `zoned` |
| **`system.osrelease`** | attribute | | | System identification data from `/etc/os-release` |
| | | **`<parameter>`** | string | One parameter from `/etc/os-release` |
| **`system.dmiid`** | attribute | | | DMI identification data from `/sys/devices/virtual/dmi/id/` |
| | | **`sys_vendor`** | string | Vendor name from `/sys/devices/virtual/dmi/id/sys_vendor` |
| **`system.name`** | attribute | | | System name information |
| | | **`nodename`** | string | Name of the kubernetes node object |
| **`usb.device`** | instance | | | USB devices present in the system |
Expand Down
3 changes: 3 additions & 0 deletions examples/nodefeature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ spec:
VERSION_ID: "22.04"
VERSION_ID.major: "22"
VERSION_ID.minor: "04"
system.dmiid:
elements:
sys_vendor: VendorUnknown
flags:
cpu.cpuid:
elements:
Expand Down
20 changes: 20 additions & 0 deletions source/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const Name = "system"
const (
OsReleaseFeature = "osrelease"
NameFeature = "name"
DmiIdFeature = "dmiid"
)

// systemSource implements the FeatureSource and LabelSource interfaces.
Expand Down Expand Up @@ -101,6 +102,15 @@ func (s *systemSource) Discover() error {
}
}

// Get vendor information
sys_vendor, err := getDmiIdAttribute("sys_vendor")
if err != nil {
klog.ErrorS(err, "failed to get sys_vendor")
} else {
s.features.Attributes[DmiIdFeature] = nfdv1alpha1.NewAttributeFeatures(nil)
s.features.Attributes[DmiIdFeature].Elements["sys_vendor"] = sys_vendor
}

Check warning on line 112 in source/system/system.go

View check run for this annotation

Codecov / codecov/patch

source/system/system.go#L106-L112

Added lines #L106 - L112 were not covered by tests

klog.V(3).InfoS("discovered features", "featureSource", s.Name(), "features", utils.DelayedDumper(s.features))

return nil
Expand Down Expand Up @@ -153,6 +163,16 @@ func splitVersion(version string) map[string]string {
return components
}

// Read /sys/devices/virtual/dmi/id attribute
func getDmiIdAttribute(name string) (string, error) {
s, err := os.ReadFile(hostpath.SysfsDir.Path("devices/virtual/dmi/id/", name))
if err != nil {
return "", err
}

Check warning on line 171 in source/system/system.go

View check run for this annotation

Codecov / codecov/patch

source/system/system.go#L167-L171

Added lines #L167 - L171 were not covered by tests

return strings.TrimSpace(string(s)), nil

Check warning on line 173 in source/system/system.go

View check run for this annotation

Codecov / codecov/patch

source/system/system.go#L173

Added line #L173 was not covered by tests
}

func init() {
source.Register(&src)
}

0 comments on commit 4bf7cf5

Please sign in to comment.