-
Notifications
You must be signed in to change notification settings - Fork 21
Add collector to get pci device data #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,57 @@ | ||
| package connect | ||
|
|
||
| import ( | ||
| "github.com/SUSE/connect-ng/internal/collectors" | ||
| "github.com/SUSE/connect-ng/pkg/collectors" | ||
| "github.com/SUSE/connect-ng/pkg/profiles" | ||
| ) | ||
|
|
||
| // Collectors which are to be used when fetching the system information. | ||
| var usedCollectors = []collectors.Collector{ | ||
| collectors.CPU{}, | ||
| collectors.Hostname{}, | ||
| collectors.Memory{}, | ||
| collectors.UUID{}, | ||
| collectors.Virtualization{}, | ||
| collectors.CloudProvider{}, | ||
| collectors.Architecture{}, | ||
| collectors.ContainerRuntime{}, | ||
|
|
||
| // Optional collectors | ||
| collectors.Uname{}, | ||
| collectors.SAP{}, | ||
| } | ||
|
|
||
| // Fetch system information based on the available collectors for the system. | ||
| func FetchSystemInformation() (collectors.Result, error) { | ||
| arch, err := collectors.DetectArchitecture() | ||
| func FetchSystemInformation(arch string) (collectors.Result, error) { | ||
| var usedCollectors = []collectors.Collector{ | ||
| collectors.CPU{}, | ||
| collectors.Hostname{}, | ||
| collectors.Memory{}, | ||
| collectors.UUID{}, | ||
| collectors.Virtualization{}, | ||
| collectors.CloudProvider{}, | ||
| collectors.Architecture{}, | ||
| collectors.ContainerRuntime{}, | ||
|
|
||
| // Optional collectors | ||
| collectors.Uname{}, | ||
| collectors.SAP{}, | ||
| } | ||
|
|
||
| var err error = nil | ||
| if arch == "" { | ||
| arch, err = collectors.DetectArchitecture() | ||
| } | ||
|
|
||
| if err != nil { | ||
| return collectors.NoResult, err | ||
| } | ||
| return collectors.CollectInformation(arch, usedCollectors) | ||
| } | ||
|
|
||
| // Fetch system profile information | ||
| func FetchSystemProfiles(arch string, updateCache bool) (collectors.Result, error) { | ||
| var usedCollectors = []collectors.Collector{ | ||
| collectors.PCI{UpdateDataIDs: updateCache}, | ||
| collectors.LSMOD{UpdateDataIDs: updateCache}, | ||
| } | ||
|
|
||
| var err error = nil | ||
| if arch == "" { | ||
| arch, err = collectors.DetectArchitecture() | ||
| } | ||
|
|
||
| if err != nil { | ||
| return collectors.NoResult, err | ||
| } | ||
| profile, err := collectors.CollectInformation(arch, usedCollectors) | ||
| if err != nil { | ||
| profiles.DeleteProfileCache() | ||
| return collectors.NoResult, err | ||
| } | ||
| return profile, err | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package collectors | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "bytes" | ||
| "sort" | ||
| "strings" | ||
|
|
||
| "github.com/SUSE/connect-ng/internal/util" | ||
| "github.com/SUSE/connect-ng/pkg/profiles" | ||
| ) | ||
|
|
||
| type LSMOD struct { | ||
| UpdateDataIDs bool | ||
| } | ||
|
|
||
| const kernModChecksumFile = "kernel-modules.txt" | ||
| const lsmodTag = "mod_list" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can make the change, but should wait for next office hours, since mod_list is what is expected by the RMT code. Not sure about SCC. |
||
|
|
||
| // Process output from lsmod to remove dups and get sorted list of kernel mods. | ||
| func getKernelMods(inputStream []byte) ([]string, error) { | ||
| scanner := bufio.NewScanner(bytes.NewReader(inputStream)) | ||
|
|
||
| itemMap := make(map[string]bool) | ||
| list := []string{} | ||
| // Skip header line | ||
| scanner.Scan() | ||
| for scanner.Scan() { | ||
| item := strings.Fields(scanner.Text())[0] | ||
| if _, exists := itemMap[item]; !exists { | ||
| itemMap[item] = true | ||
| list = append(list, item) | ||
| } | ||
| } | ||
|
|
||
| if err := scanner.Err(); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| sort.Strings(list) | ||
| return list, nil | ||
| } | ||
|
|
||
| func (lsmod LSMOD) run(arch string) (Result, error) { | ||
| util.Debug.Print("lsmod.UpdateDataIDs: ", lsmod.UpdateDataIDs) | ||
| modInfo, err := util.Execute([]string{"lsmod"}, nil) | ||
| if err != nil { | ||
| return Result{}, err | ||
| } | ||
|
|
||
| sortedMods, _ := getKernelMods(modInfo) | ||
| result, _ := profiles.BuildProfile(lsmod.UpdateDataIDs, lsmodTag, kernModChecksumFile, sortedMods) | ||
|
|
||
| return result, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.