Skip to content

Commit

Permalink
Relocate network.InterfaceInfo (and friends) to core/network
Browse files Browse the repository at this point in the history
  • Loading branch information
achilleasa committed Nov 27, 2019
1 parent cc20d07 commit 0df6067
Show file tree
Hide file tree
Showing 57 changed files with 715 additions and 702 deletions.
19 changes: 10 additions & 9 deletions api/common/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/juju/loggo"

"github.com/juju/juju/apiserver/params"
corenetwork "github.com/juju/juju/core/network"
"github.com/juju/juju/network"
)

Expand Down Expand Up @@ -113,7 +114,7 @@ func GetObservedNetworkConfig(source NetworkConfigSource) ([]params.NetworkConfi
nicConfig.GatewayAddress = defaultRoute.String()
}

if nicType == network.BridgeInterface {
if nicType == corenetwork.BridgeInterface {
updateParentForBridgePorts(nic.Name, sysClassNetPath, nameToConfigs)
}

Expand Down Expand Up @@ -167,18 +168,18 @@ func GetObservedNetworkConfig(source NetworkConfigSource) ([]params.NetworkConfi
return observedConfig, nil
}

func interfaceToNetworkConfig(nic net.Interface, nicType network.InterfaceType) params.NetworkConfig {
configType := network.ConfigManual // assume manual initially, until we parse the address.
func interfaceToNetworkConfig(nic net.Interface, nicType corenetwork.InterfaceType) params.NetworkConfig {
configType := corenetwork.ConfigManual // assume manual initially, until we parse the address.
isUp := nic.Flags&net.FlagUp > 0
isLoopback := nic.Flags&net.FlagLoopback > 0
isUnknown := nicType == network.UnknownInterface
isUnknown := nicType == corenetwork.UnknownInterface

switch {
case isUnknown && isLoopback:
nicType = network.LoopbackInterface
configType = network.ConfigLoopback
nicType = corenetwork.LoopbackInterface
configType = corenetwork.ConfigLoopback
case isUnknown:
nicType = network.EthernetInterface
nicType = corenetwork.EthernetInterface
}

return params.NetworkConfig{
Expand Down Expand Up @@ -235,8 +236,8 @@ func interfaceAddressToNetworkConfig(interfaceName, configType string, address n
config.CIDR = ipNet.String()
}
config.Address = ip.String()
if configType != string(network.ConfigLoopback) {
config.ConfigType = string(network.ConfigStatic)
if configType != string(corenetwork.ConfigLoopback) {
config.ConfigType = string(corenetwork.ConfigStatic)
}

// TODO(dimitern): Add DNS servers, search domains, and gateway
Expand Down
18 changes: 9 additions & 9 deletions api/provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ func (st *State) ReleaseContainerAddresses(containerTag names.MachineTag) (err e

// PrepareContainerInterfaceInfo allocates an address and returns information to
// configure networking for a container. It accepts container tags as arguments.
func (st *State) PrepareContainerInterfaceInfo(containerTag names.MachineTag) ([]network.InterfaceInfo, error) {
func (st *State) PrepareContainerInterfaceInfo(containerTag names.MachineTag) ([]corenetwork.InterfaceInfo, error) {
return st.prepareOrGetContainerInterfaceInfo(containerTag, true)
}

// GetContainerInterfaceInfo returns information to configure networking
// for a container. It accepts container tags as arguments.
func (st *State) GetContainerInterfaceInfo(containerTag names.MachineTag) ([]network.InterfaceInfo, error) {
func (st *State) GetContainerInterfaceInfo(containerTag names.MachineTag) ([]corenetwork.InterfaceInfo, error) {
return st.prepareOrGetContainerInterfaceInfo(containerTag, false)
}

Expand All @@ -264,7 +264,7 @@ func (st *State) GetContainerInterfaceInfo(containerTag names.MachineTag) ([]net
// InterfaceConfig.
func (st *State) prepareOrGetContainerInterfaceInfo(
containerTag names.MachineTag, allocateNewAddress bool) (
[]network.InterfaceInfo, error) {
[]corenetwork.InterfaceInfo, error) {
var result params.MachineNetworkConfigResults
args := params.Entities{
Entities: []params.Entity{{Tag: containerTag.String()}},
Expand All @@ -285,19 +285,19 @@ func (st *State) prepareOrGetContainerInterfaceInfo(
return nil, err
}
machineConf := result.Results[0]
ifaceInfo := make([]network.InterfaceInfo, len(machineConf.Config))
ifaceInfo := make([]corenetwork.InterfaceInfo, len(machineConf.Config))
for i, cfg := range machineConf.Config {
routes := make([]network.Route, len(cfg.Routes))
routes := make([]corenetwork.Route, len(cfg.Routes))
for j, route := range cfg.Routes {
routes[j] = network.Route{
routes[j] = corenetwork.Route{
DestinationCIDR: route.DestinationCIDR,
GatewayIP: route.GatewayIP,
Metric: route.Metric,
}
}
// TODO(achilleasa): do we need to define interfaces for the
// non-primary private addresses (if present)?
ifaceInfo[i] = network.InterfaceInfo{
ifaceInfo[i] = corenetwork.InterfaceInfo{
DeviceIndex: cfg.DeviceIndex,
MACAddress: cfg.MACAddress,
CIDR: cfg.CIDR,
Expand All @@ -310,10 +310,10 @@ func (st *State) prepareOrGetContainerInterfaceInfo(
VLANTag: cfg.VLANTag,
InterfaceName: cfg.InterfaceName,
ParentInterfaceName: cfg.ParentInterfaceName,
InterfaceType: network.InterfaceType(cfg.InterfaceType),
InterfaceType: corenetwork.InterfaceType(cfg.InterfaceType),
Disabled: cfg.Disabled,
NoAutoStart: cfg.NoAutoStart,
ConfigType: network.InterfaceConfigType(cfg.ConfigType),
ConfigType: corenetwork.InterfaceConfigType(cfg.ConfigType),
Addresses: corenetwork.ProviderAddresses{corenetwork.NewProviderAddress(cfg.Address)},
DNSServers: corenetwork.NewProviderAddresses(cfg.DNSServers...),
DNSSearchDomains: cfg.DNSSearchDomains,
Expand Down
6 changes: 3 additions & 3 deletions api/provisioner/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ func (s *provisionerContainerSuite) TestPrepareContainerInterfaceInfoNoValues(c

networkInfo, err := provisionerApi.PrepareContainerInterfaceInfo(s.containerTag)
c.Assert(err, gc.IsNil)
c.Check(networkInfo, jc.DeepEquals, []network.InterfaceInfo{})
c.Check(networkInfo, jc.DeepEquals, []corenetwork.InterfaceInfo{})
}

func (s *provisionerContainerSuite) TestPrepareContainerInterfaceInfoSingleNIC(c *gc.C) {
Expand Down Expand Up @@ -952,7 +952,7 @@ func (s *provisionerContainerSuite) TestPrepareContainerInterfaceInfoSingleNIC(c
provisionerApi := provisioner.NewStateFromFacade(facadeCaller)
networkInfo, err := provisionerApi.PrepareContainerInterfaceInfo(s.containerTag)
c.Assert(err, gc.IsNil)
c.Check(networkInfo, jc.DeepEquals, []network.InterfaceInfo{{
c.Check(networkInfo, jc.DeepEquals, []corenetwork.InterfaceInfo{{
DeviceIndex: 1,
MACAddress: "de:ad:be:ff:11:22",
CIDR: "192.168.0.5/24",
Expand All @@ -973,7 +973,7 @@ func (s *provisionerContainerSuite) TestPrepareContainerInterfaceInfoSingleNIC(c
DNSServers: corenetwork.NewProviderAddresses("8.8.8.8"),
DNSSearchDomains: []string{"mydomain"},
GatewayAddress: corenetwork.NewProviderAddress("192.168.0.1"),
Routes: []network.Route{{
Routes: []corenetwork.Route{{
DestinationCIDR: "10.0.0.0/16",
GatewayIP: "192.168.0.1",
Metric: 55,
Expand Down
4 changes: 2 additions & 2 deletions apiserver/common/networkingcommon/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ func BackingSubnetToParamsSubnet(subnet BackingSubnet) params.Subnet {
}
}

// NetworkConfigFromInterfaceInfo converts a slice of network.InterfaceInfo into
// NetworkConfigFromInterfaceInfo converts a slice of corenetwork.InterfaceInfo into
// the equivalent params.NetworkConfig slice.
func NetworkConfigFromInterfaceInfo(interfaceInfos []network.InterfaceInfo) []params.NetworkConfig {
func NetworkConfigFromInterfaceInfo(interfaceInfos []corenetwork.InterfaceInfo) []params.NetworkConfig {
result := make([]params.NetworkConfig, len(interfaceInfos))
for i, v := range interfaceInfos {
var dnsServers []string
Expand Down
Loading

0 comments on commit 0df6067

Please sign in to comment.