clustvirt/util/pcidb.go
Matthew Stobbs ffca8c3970 done migrating host module to libvirtxml
- need to add accessor methods
- eventually will move the VMList to the local guest module
2024-03-21 11:15:23 -06:00

47 lines
937 B
Go

package util
import (
"git.staur.ca/stobbsm/clustvirt/lib/log"
"github.com/jaypipes/pcidb"
)
var (
pcidbInitDone = false
db *pcidb.PCIDB
)
const (
pcidbNOTFOUND string = `NOTFOUND`
pcidbNODB string = `NODBFOUND`
)
func initPCIDB() {
var err error
// Attempt to use local sources first, fallback to network if
// local sources aren't found
db, err = pcidb.New()
if err != nil {
log.Warn("util.initPCIDB").Err(err).Msg("fallback to downloading pcidb")
db, err = pcidb.New(pcidb.WithEnableNetworkFetch())
if err != nil {
log.Error("util.initPCIDB").Err(err).Msg("no more fallbacks available")
}
}
pcidbInitDone = true
}
func GetPCIClass(id string) string {
if !pcidbInitDone {
initPCIDB()
}
if pcidbInitDone && db == nil {
log.Warn("util.GetPCIClass").Msg("no pcidb to do lookup")
return pcidbNODB
}
if class, ok := db.Classes[id]; ok {
return class.Name
}
return pcidbNOTFOUND
}