mirror of
https://github.com/openshift/installer.git
synced 2026-02-05 06:46:36 +01:00
Merge pull request #3691 from karmab/baremetal_bridges
baremetal: allow bootstrap vm to use libvirt nat networks
This commit is contained in:
@@ -40,25 +40,45 @@ func validateInterfaces(p *baremetal.Platform, fldPath *field.Path) field.ErrorL
|
||||
// to validate if an interface is found among them
|
||||
func interfaceValidator(libvirtURI string) (func(string) error, error) {
|
||||
// Connect to libvirt and obtain a list of interface names
|
||||
interfaces := make(map[string]struct{})
|
||||
var exists = struct{}{}
|
||||
conn, err := libvirt.NewConnect(libvirtURI)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not connect to libvirt")
|
||||
}
|
||||
|
||||
interfaces, err := conn.ListAllInterfaces(libvirt.CONNECT_LIST_INTERFACES_ACTIVE)
|
||||
networks, err := conn.ListAllNetworks(libvirt.CONNECT_LIST_NETWORKS_ACTIVE)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not list libvirt networks")
|
||||
}
|
||||
for _, network := range networks {
|
||||
networkName, err := network.GetName()
|
||||
if err == nil {
|
||||
bridgeName, err := network.GetBridgeName()
|
||||
if err == nil && bridgeName == networkName {
|
||||
interfaces[networkName] = exists
|
||||
}
|
||||
}
|
||||
}
|
||||
bridges, err := conn.ListAllInterfaces(libvirt.CONNECT_LIST_INTERFACES_ACTIVE)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not list libvirt interfaces")
|
||||
}
|
||||
|
||||
interfaceNames := make([]string, len(interfaces))
|
||||
for idx, iface := range interfaces {
|
||||
iface, err := iface.GetName()
|
||||
for _, bridge := range bridges {
|
||||
bridgeName, err := bridge.GetName()
|
||||
if err == nil {
|
||||
interfaceNames[idx] = iface
|
||||
interfaces[bridgeName] = exists
|
||||
} else {
|
||||
return nil, errors.Wrap(err, "could not get interface name from libvirt")
|
||||
}
|
||||
}
|
||||
interfaceNames := make([]string, len(interfaces))
|
||||
idx := 0
|
||||
for key := range interfaces {
|
||||
interfaceNames[idx] = key
|
||||
idx++
|
||||
}
|
||||
|
||||
// Return a closure to validate if any particular interface is found among interfaceNames
|
||||
return func(interfaceName string) error {
|
||||
|
||||
Reference in New Issue
Block a user