@@ -5,9 +5,10 @@ package validation
55
66import (
77 "fmt"
8+ "net/url"
89 "strings"
910
10- "github.com/libvirt/libvirt-go "
11+ libvirt "github.com/digitalocean/go-libvirt "
1112 "github.com/pkg/errors"
1213 "k8s.io/apimachinery/pkg/util/validation/field"
1314
@@ -59,36 +60,35 @@ func interfaceValidator(libvirtURI string) (func(string) error, error) {
5960 // Connect to libvirt and obtain a list of interface names
6061 interfaces := make (map [string ]struct {})
6162 var exists = struct {}{}
62- conn , err := libvirt .NewConnect (libvirtURI )
63+
64+ uri , err := url .Parse (libvirtURI )
65+ if err != nil {
66+ return nil , err
67+ }
68+
69+ virt , err := libvirt .ConnectToURI (uri )
6370 if err != nil {
64- return nil , errors . Wrap ( err , "could not connect to libvirt" )
71+ return nil , err
6572 }
73+ defer virt .Disconnect ()
6674
67- networks , err := conn . ListAllNetworks ( libvirt .CONNECT_LIST_NETWORKS_ACTIVE )
75+ networks , _ , err := virt . ConnectListAllNetworks ( 1 , libvirt .ConnectListNetworksActive )
6876 if err != nil {
6977 return nil , errors .Wrap (err , "could not list libvirt networks" )
7078 }
7179 for _ , network := range networks {
72- networkName , err := network .GetName ()
73- if err == nil {
74- bridgeName , err := network .GetBridgeName ()
75- if err == nil && bridgeName == networkName {
76- interfaces [networkName ] = exists
77- }
80+ bridgeName , err := virt .NetworkGetBridgeName (network )
81+ if err == nil && bridgeName == network .Name {
82+ interfaces [network .Name ] = exists
7883 }
7984 }
80- bridges , err := conn . ListAllInterfaces ( libvirt .CONNECT_LIST_INTERFACES_ACTIVE )
85+ bridges , _ , err := virt . ConnectListAllInterfaces ( 1 , libvirt .ConnectListInterfacesActive )
8186 if err != nil {
8287 return nil , errors .Wrap (err , "could not list libvirt interfaces" )
8388 }
8489
8590 for _ , bridge := range bridges {
86- bridgeName , err := bridge .GetName ()
87- if err == nil {
88- interfaces [bridgeName ] = exists
89- } else {
90- return nil , errors .Wrap (err , "could not get interface name from libvirt" )
91- }
91+ interfaces [bridge .Name ] = exists
9292 }
9393 interfaceNames := make ([]string , len (interfaces ))
9494 idx := 0
0 commit comments