From 1bfdaf28c716b0b474d9e6b4c58fb2cea329bc76 Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Tue, 12 Mar 2024 01:38:29 -0600 Subject: [PATCH] Add file stubs, add comments to guide dev in host Signed-off-by: Matthew Stobbs --- lib/device/lib.go | 0 lib/host/host.go | 96 ++++++++++++++++++++++++++++++++++++++---- lib/interface/lib.go | 0 lib/network/lib.go | 0 lib/secret/lib.go | 0 lib/storagepool/lib.go | 0 6 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 lib/device/lib.go create mode 100644 lib/interface/lib.go create mode 100644 lib/network/lib.go create mode 100644 lib/secret/lib.go create mode 100644 lib/storagepool/lib.go diff --git a/lib/device/lib.go b/lib/device/lib.go new file mode 100644 index 0000000..e69de29 diff --git a/lib/host/host.go b/lib/host/host.go index 0960474..796d534 100644 --- a/lib/host/host.go +++ b/lib/host/host.go @@ -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 diff --git a/lib/interface/lib.go b/lib/interface/lib.go new file mode 100644 index 0000000..e69de29 diff --git a/lib/network/lib.go b/lib/network/lib.go new file mode 100644 index 0000000..e69de29 diff --git a/lib/secret/lib.go b/lib/secret/lib.go new file mode 100644 index 0000000..e69de29 diff --git a/lib/storagepool/lib.go b/lib/storagepool/lib.go new file mode 100644 index 0000000..e69de29