Add file stubs, add comments to guide dev in host

Signed-off-by: Matthew Stobbs <matthew@stobbs.ca>
This commit is contained in:
Matthew Stobbs 2024-03-12 01:38:29 -06:00
parent b5ab70fc25
commit 1bfdaf28c7
6 changed files with 87 additions and 9 deletions

0
lib/device/lib.go Normal file
View File

View File

@ -18,13 +18,35 @@ import (
// If a connection is closed prematurely, will re-open the connection and
// try the attempted method again
type Host struct {
HostName string
SystemHomeName string
FreeMemory uint64
LibVersion uint32
HostInfo NodeInfo
HostSEVInfo SEVInfo
AvailableCPUTypes []string
HostName string
SystemHostName string
FreeMemory uint64
LibVersion uint32
HostInfo NodeInfo
HostSEVInfo SEVInfo
AvailableCPUTypes []string
NodeMemory NodeMemoryInfo
StorageCapabilities string
SysInfo string
Alive bool
Encrypted bool
Secure bool
//alldomains
//allinterfaces
//allnetworks
//alldevices
//allsecrets
//allstoragepools
//defineddomains
//definedinterfaces
//definednetworks
//definedstoragepools
//listdomains []int id
//listinterfaces []string interfacename
//listnetworks []string networkname
//listserets []string secretname
//liststoragepools []string storagepoolname
uri *URI
conn *libvirt.Connect
@ -46,9 +68,9 @@ type NodeInfo struct {
}
// SEVInfo provides information about AMD SEV support
type SEVInfo struct{
type SEVInfo struct {
// livirt.NodeSEVParameters section
SEVEnabled bool
SEVEnabled bool
PDH string
CertChain string
CBitPos uint
@ -58,6 +80,14 @@ type SEVInfo struct{
CPU0ID string
}
// NodeMemoryInfo provides statistis about node memory usage from libvirt.NodeMemoryStats
type NodeMemoryInfo struct {
Total uint64
Free uint64
Buffers uint64
Cached uint64
}
// ConnectHost creates a host connection wrapper that can be used regularly
func ConnectHost(uri *URI, host string) (*Host, error) {
h := &Host{
@ -118,6 +148,54 @@ func ConnectHost(uri *URI, host string) (*Host, error) {
h.HostSEVInfo.CPU0ID = util.SetNotSet(ns.CPU0ID, ns.CPU0IDSet)
}
h.SystemHostName, err = h.conn.GetHostname()
if err != nil {
log.Println(err)
}
if h.SystemHostName == "" {
h.SystemHostName = h.HostName
}
h.LibVersion, err = h.conn.GetLibVersion()
if err != nil {
log.Println(err)
}
h.FreeMemory, err = h.conn.GetFreeMemory()
if err != nil {
log.Println(err)
}
mi, err := h.conn.GetMemoryStats(libvirt.NODE_MEMORY_STATS_ALL_CELLS, 0)
if err != nil {
log.Println(err)
}
h.NodeMemory.Total = mi.Total
h.NodeMemory.Free = mi.Free
h.NodeMemory.Buffers = mi.Buffers
h.NodeMemory.Cached = mi.Cached
h.StorageCapabilities, err = h.conn.GetStoragePoolCapabilities(0)
if err != nil {
log.Println(err)
}
h.SysInfo, err = h.conn.GetSysinfo(0)
if err != nil {
log.Println(err)
}
h.Alive, err = h.conn.IsAlive()
if err != nil {
log.Println(err)
}
h.Encrypted, err = h.conn.IsEncrypted()
if err != nil {
log.Println(err)
}
h.Secure, err = h.conn.IsSecure()
if err != nil {
log.Println(err)
}
go func() {
defer close(h.closeErr)
<-h.close

0
lib/interface/lib.go Normal file
View File

0
lib/network/lib.go Normal file
View File

0
lib/secret/lib.go Normal file
View File

0
lib/storagepool/lib.go Normal file
View File