Skip to content

Commit

Permalink
backends: LXD: don't hardcode eth0
Browse files Browse the repository at this point in the history
With the ubuntu-22.04 image, the network interface seems
to be named "enp5s0" instead of "eth0". To be compatible
with both old and new releases, consider any non-loopback
interface viable for retrieving an IP address.
  • Loading branch information
thp-canonical committed Feb 26, 2024
1 parent ded9133 commit 513f682
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions spread/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,14 @@ func (p *lxdProvider) address(name string) (string, error) {
if err != nil {
return "", err
}
for _, addr := range sjson.State.Network["eth0"].Addresses {
if addr.Family == "inet" && addr.Address != "" {
return addr.Address, nil
for intf, network := range sjson.State.Network {
if intf == "lo" {
continue
}
for _, addr := range network.Addresses {
if addr.Family == "inet" && addr.Address != "" {
return addr.Address, nil
}
}
}
return "", &lxdNoAddrError{name}
Expand Down

0 comments on commit 513f682

Please sign in to comment.