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 21, 2024
1 parent ded9133 commit cc8bf9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions spread/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,15 @@ 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 {
debugf("considering interface %v\n", intf)
if addr.Family == "inet" && addr.Address != "" {
return addr.Address, nil
}
}
}
return "", &lxdNoAddrError{name}
Expand Down
3 changes: 3 additions & 0 deletions tests/lxd/spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ backends:
lxd:
systems:
- ubuntu-16.04
- ubuntu-18.04
- ubuntu-20.04
- ubuntu-22.04

path: /home/test

Expand Down

0 comments on commit cc8bf9d

Please sign in to comment.