From 99fcb2b36047221f7e3aef1f529dc990245e7dce Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Wed, 20 Mar 2024 15:45:25 -0600 Subject: [PATCH] more migrations done --- lib/host/lib.go | 72 +++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/lib/host/lib.go b/lib/host/lib.go index 062ef0a..32c9bda 100644 --- a/lib/host/lib.go +++ b/lib/host/lib.go @@ -176,10 +176,10 @@ func (h *Host) memoryInfo() { log.Println(err) } h.NodeMemory = &NodeMemoryInfo{ - Total: mi.Total, - Free: mi.Free, + Total: mi.Total, + Free: mi.Free, Buffers: mi.Buffers, - Cached: mi.Cached, + Cached: mi.Cached, } h.SysInfo, err = h.conn.GetSysinfo(0) @@ -303,58 +303,46 @@ func (h *Host) getDomainInfo() { log.Println(err) } if len(doms) > 0 { - h.VMList = make([]VMInfo, len(doms)) + h.VMList = make([]*libvirtxml.Domain, len(doms)) for i, d := range doms { - // Just going to log errors here, and free the dom after getting what we can - if h.VMList[i].Name, err = d.GetName(); err != nil { - log.Println(err) - } - if h.VMList[i].UUID, err = d.GetUUID(); err != nil { - log.Println(err) - } - if h.VMList[i].ID, err = d.GetID(); err != nil { - log.Println(err) - } - if h.VMList[i].XML, err = d.GetXMLDesc(0); err != nil { - log.Println(err) - } - vmXML := &libvirtxml.Domain{} - if err = vmXML.Unmarshal(h.VMList[i].XML); err != nil { - log.Println(err) - } - h.VMList[i].VCPUs = vmXML.VCPU.Value - h.VMList[i].Memory = vmXML.CurrentMemory.Value - if h.VMList[i].Active, err = d.IsActive(); err != nil { - log.Println(err) - } + func() { + defer d.Free() + rawxml, err := d.GetXMLDesc(0) + if err != nil { + log.Printf("error getting domain XML: %s", err) + } + h.VMList[i] = &libvirtxml.Domain{} + if err = h.VMList[i].Unmarshal(rawxml); err != nil { + log.Printf("error parsing domain XML: %s", err) + } + }() - d.Free() } } } func (h *Host) getIfaceInfo() { // getIfaceInfo - ifaces, err := h.conn.ListInterfaces() + ifaces, err := h.conn.ListAllInterfaces(0) if err != nil { log.Println(err) } if len(ifaces) > 0 { - h.NetIfFList = make([]NetIfInfo, len(ifaces)) + h.NetIfFList = make([]*libvirtxml.Interface, len(ifaces)) for i, ni := range ifaces { - h.NetIfFList[i].Name = ni - iface, err := h.conn.LookupInterfaceByName(ni) - if err != nil { - log.Println(err) - } - if h.NetIfFList[i].MacAddr, err = iface.GetMACString(); err != nil { - log.Println(err) - } - if h.NetIfFList[i].XML, err = iface.GetXMLDesc(0); err != nil { - log.Println(err) - } - - iface.Free() + func() { + defer ni.Free() + rawxml, err := ni.GetXMLDesc(0) + if err != nil { + log.Printf("error getting interface XML: %s") + return + } + h.NetIfFList[i] = &libvirtxml.Interface{} + if err = h.NetIfFList[i].Unmarshal(rawxml); err != nil { + log.Printf("error parsing interface XML: %s") + return + } + }() } } }