mkvm/networks.go

31 lines
496 B
Go
Raw Normal View History

2024-12-03 04:22:30 +00:00
package main
import (
"encoding/xml"
"mkvm/config"
"libvirt.org/go/libvirt"
"libvirt.org/go/libvirtxml"
)
func getNetwork(conn *libvirt.Connect) (libvirtxml.Network, error) {
var net libvirtxml.Network
libvirtnet, err := conn.LookupNetworkByName(config.C.Network)
if err != nil {
return net, err
}
xmlstr, err := libvirtnet.GetXMLDesc(0)
if err != nil {
return net, err
}
if err := xml.Unmarshal([]byte(xmlstr), &net); err != nil {
return net, err
}
return net, nil
}