30 lines
496 B
Go
30 lines
496 B
Go
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
|
|
|
|
}
|