Skip to content

Commit

Permalink
Updates LXD provider to send interfaces with configuration method
Browse files Browse the repository at this point in the history
against addresses instead of the device.
  • Loading branch information
manadart committed May 6, 2021
1 parent 3e1b212 commit 30accd5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
16 changes: 8 additions & 8 deletions provider/lxd/environ_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func makeSubnetInfo(subnetID network.Id, networkID network.Id, cidr, azName stri
// was no other error, it will return ErrNoInstances. If some but not all of
// the instances were found, the returned slice will have some nil slots, and
// an ErrPartialInstances error will be returned.
func (e *environ) NetworkInterfaces(ctx context.ProviderCallContext, ids []instance.Id) ([]network.InterfaceInfos, error) {
func (e *environ) NetworkInterfaces(_ context.ProviderCallContext, ids []instance.Id) ([]network.InterfaceInfos, error) {
var (
missing int
srv = e.server()
Expand Down Expand Up @@ -262,7 +262,7 @@ func (e *environ) NetworkInterfaces(ctx context.ProviderCallContext, ids []insta

ni, err := makeInterfaceInfo(container, guestNetworkName, netInfo)
if err != nil {
return nil, errors.Annotatef(err, "retrieving network interface info for instane %q", id)
return nil, errors.Annotatef(err, "retrieving network interface info for instance %q", id)
} else if len(ni.Addresses) == 0 {
continue
}
Expand Down Expand Up @@ -292,15 +292,14 @@ func makeInterfaceInfo(container *lxdapi.Container, guestNetworkName string, net
ParentInterfaceName: hostNetworkForGuestNetwork(container, guestNetworkName),
InterfaceType: detectInterfaceType(netInfo.Type),
Origin: network.OriginProvider,

// We cannot tell from the API response whether the interface
// uses a static or DHCP configuration; assume static unless
// this is a loopback device (see below).
ConfigType: network.ConfigStatic,
}

// We cannot tell from the API response whether the
// interface uses a static or DHCP configuration.
// Assume static unless this is a loopback device.
configType := network.ConfigStatic
if ni.InterfaceType == network.LoopbackDevice {
ni.ConfigType = network.ConfigLoopback
configType = network.ConfigLoopback
}

if ni.ParentInterfaceName != "" {
Expand All @@ -325,6 +324,7 @@ func makeInterfaceInfo(container *lxdapi.Container, guestNetworkName string, net
}

netAddr.CIDR = cidr
netAddr.ConfigType = configType
ni.Addresses = append(ni.Addresses, netAddr)

// Only set provider IDs based on the first address.
Expand Down
21 changes: 9 additions & 12 deletions provider/lxd/environ_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,12 @@ func (s *environNetSuite) TestNetworkInterfaces(c *gc.C) {
ParentInterfaceName: "lxdbr0",
InterfaceType: network.EthernetDevice,
Origin: network.OriginProvider,
ConfigType: network.ConfigStatic,
ProviderId: "nic-00:16:3e:19:29:cb",
ProviderSubnetId: "subnet-lxdbr0-10.55.158.0/24",
ProviderNetworkId: "net-lxdbr0",
Addresses: network.ProviderAddresses{
network.NewProviderAddress("10.55.158.99", network.WithCIDR("10.55.158.0/24")),
},
Addresses: network.ProviderAddresses{network.NewProviderAddress(
"10.55.158.99", network.WithCIDR("10.55.158.0/24"), network.WithConfigType(network.ConfigStatic),
)},
},
{
DeviceIndex: 1,
Expand All @@ -400,13 +399,12 @@ func (s *environNetSuite) TestNetworkInterfaces(c *gc.C) {
ParentInterfaceName: "ovsbr0",
InterfaceType: network.EthernetDevice,
Origin: network.OriginProvider,
ConfigType: network.ConfigStatic,
ProviderId: "nic-00:16:3e:fe:fe:fe",
ProviderSubnetId: "subnet-ovsbr0-10.42.42.0/24",
ProviderNetworkId: "net-ovsbr0",
Addresses: network.ProviderAddresses{
network.NewProviderAddress("10.42.42.99", network.WithCIDR("10.42.42.0/24")),
},
Addresses: network.ProviderAddresses{network.NewProviderAddress(
"10.42.42.99", network.WithCIDR("10.42.42.0/24"), network.WithConfigType(network.ConfigStatic),
)},
},
},
}
Expand Down Expand Up @@ -462,13 +460,12 @@ func (s *environNetSuite) TestNetworkInterfacesPartialResults(c *gc.C) {
ParentInterfaceName: "lxdbr0",
InterfaceType: network.EthernetDevice,
Origin: network.OriginProvider,
ConfigType: network.ConfigStatic,
ProviderId: "nic-00:16:3e:19:29:cb",
ProviderSubnetId: "subnet-lxdbr0-10.55.158.0/24",
ProviderNetworkId: "net-lxdbr0",
Addresses: network.ProviderAddresses{
network.NewProviderAddress("10.55.158.99", network.WithCIDR("10.55.158.0/24")),
},
Addresses: network.ProviderAddresses{network.NewProviderAddress(
"10.55.158.99", network.WithCIDR("10.55.158.0/24"), network.WithConfigType(network.ConfigStatic),
)},
},
},
nil, // slot for second instance is nil as the container was not found
Expand Down

0 comments on commit 30accd5

Please sign in to comment.