Documentation ¶
Index ¶
- Constants
- Variables
- func APIHostPortsToNoProxyString(ahp []SpaceHostPorts) string
- func CalculateOverlaySegment(underlayCIDR string, fan FanConfigEntry) (*net.IPNet, error)
- func ConvertSpaceName(name string, existing set.Strings) string
- func DialAddress(a HostPort) string
- func ExactScopeMatch(addr Address, addrScopes ...Scope) bool
- func GetBridgePorts(sysPath, bridgeName string) []string
- func GetDefaultRoute() (net.IP, string, error)
- func IPRangeForCIDR(cidr string) (net.IP, net.IP, error)
- func IsInFanNetwork(network Id) bool
- func IsNoAddressError(err error) bool
- func IsValidAddressConfigType(value string) bool
- func IsValidCIDR(cidr string) bool
- func IsValidLinkLayerDeviceName(name string) bool
- func IsValidLinkLayerDeviceType(value string) bool
- func NetworkCIDRFromIPAndMask(ip net.IP, netmask net.IPMask) string
- func NoAddressError(addressKind string) error
- func OvsManagedBridges() (set.Strings, error)
- func SortOrderMostPublic(a Address) int
- func SortPortRanges(portRanges []PortRange)
- func SortSubnetInfos(s SubnetInfos)
- func SubnetsForAddresses(addrs []string) []string
- func WithCIDR(cidr string) func(AddressMutator)
- func WithConfigType(configType AddressConfigType) func(AddressMutator)
- func WithScope(scope Scope) func(AddressMutator)
- func WithSecondary(isSecondary bool) func(AddressMutator)
- type Address
- type AddressConfigType
- type AddressMutator
- type AddressType
- type AvailabilityZone
- type AvailabilityZones
- type ConfigSource
- type ConfigSourceAddr
- type ConfigSourceNIC
- type DNSConfig
- type FanCIDRs
- type FanConfig
- type FanConfigEntry
- type GroupedPortRanges
- type HostPort
- type HostPorts
- type IDSet
- type Id
- type InterfaceFilterFunc
- type InterfaceInfo
- type InterfaceInfos
- type LinkLayerDeviceType
- type MachineAddress
- func (a MachineAddress) AddressCIDR() string
- func (a MachineAddress) AddressConfigType() AddressConfigType
- func (a MachineAddress) AddressIsSecondary() bool
- func (a MachineAddress) AddressScope() Scope
- func (a MachineAddress) AddressType() AddressType
- func (a MachineAddress) GoString() string
- func (a MachineAddress) Host() string
- func (a MachineAddress) IP() net.IP
- func (a *MachineAddress) SetCIDR(cidr string)
- func (a *MachineAddress) SetConfigType(configType AddressConfigType)
- func (a *MachineAddress) SetScope(scope Scope)
- func (a *MachineAddress) SetSecondary(isSecondary bool)
- func (a MachineAddress) String() string
- func (a MachineAddress) ValueWithMask() (string, error)
- type MachineHostPort
- type MachineHostPorts
- type NetPort
- type Origin
- type PortRange
- type ProviderAddress
- type ProviderAddresses
- type ProviderHostPort
- type ProviderHostPorts
- type ProviderInterfaceInfo
- type Route
- type Scope
- type ScopeMatch
- type ScopeMatchFunc
- type SpaceAddress
- type SpaceAddressCandidate
- type SpaceAddresses
- func (sas SpaceAddresses) AllMatchingScope(getMatcher ScopeMatchFunc) SpaceAddresses
- func (sas SpaceAddresses) EqualTo(other SpaceAddresses) bool
- func (sas SpaceAddresses) InSpaces(spaces ...SpaceInfo) (SpaceAddresses, bool)
- func (sas SpaceAddresses) Len() int
- func (sas SpaceAddresses) Less(i, j int) bool
- func (sas SpaceAddresses) OneMatchingScope(getMatcher ScopeMatchFunc) (SpaceAddress, bool)
- func (sas SpaceAddresses) Swap(i, j int)
- func (sas SpaceAddresses) ToProviderAddresses(lookup SpaceLookup) (ProviderAddresses, error)
- func (sas SpaceAddresses) Values() []string
- type SpaceHostPort
- type SpaceHostPorts
- func (hps SpaceHostPorts) AllMatchingScope(getMatcher ScopeMatchFunc) []string
- func (hps SpaceHostPorts) HostPorts() HostPorts
- func (hps SpaceHostPorts) InSpaces(spaces ...SpaceInfo) (SpaceHostPorts, bool)
- func (hps SpaceHostPorts) Len() int
- func (hps SpaceHostPorts) Less(i, j int) bool
- func (hps SpaceHostPorts) Swap(i, j int)
- func (hps SpaceHostPorts) ToProviderHostPorts(lookup SpaceLookup) (ProviderHostPorts, error)
- type SpaceInfo
- type SpaceInfos
- func (s SpaceInfos) AllSpaceInfos() (SpaceInfos, error)
- func (s SpaceInfos) AllSubnetInfos() (SubnetInfos, error)
- func (s SpaceInfos) ContainsID(id string) bool
- func (s SpaceInfos) ContainsName(name string) bool
- func (s SpaceInfos) FanOverlaysFor(subnetIDs IDSet) (SubnetInfos, error)
- func (s SpaceInfos) GetByID(id string) *SpaceInfo
- func (s SpaceInfos) GetByName(name string) *SpaceInfo
- func (s SpaceInfos) IDs() []string
- func (s SpaceInfos) InferSpaceFromAddress(addr string) (*SpaceInfo, error)
- func (s SpaceInfos) InferSpaceFromCIDRAndSubnetID(cidr, providerSubnetID string) (*SpaceInfo, error)
- func (s SpaceInfos) Minus(other SpaceInfos) SpaceInfos
- func (s SpaceInfos) MoveSubnets(subnetIDs IDSet, spaceName string) (SpaceInfos, error)
- func (s SpaceInfos) Names() []string
- func (s SpaceInfos) String() string
- func (s SpaceInfos) SubnetCIDRsBySpaceID() map[string][]string
- type SpaceLookup
- type SpaceName
- type SubnetInfo
- type SubnetInfos
- func (s SubnetInfos) AllSubnetInfos() (SubnetInfos, error)
- func (s SubnetInfos) ContainsID(id Id) bool
- func (s SubnetInfos) EqualTo(other SubnetInfos) bool
- func (s SubnetInfos) GetByAddress(addr string) (SubnetInfos, error)
- func (s SubnetInfos) GetByCIDR(cidr string) (SubnetInfos, error)
- func (s SubnetInfos) GetByID(id Id) *SubnetInfo
- func (s SubnetInfos) GetBySpaceID(spaceID string) (SubnetInfos, error)
- func (s SubnetInfos) GetByUnderlayCIDR(cidr string) (SubnetInfos, error)
- func (s SubnetInfos) Len() int
- func (s SubnetInfos) Less(i, j int) bool
- func (s SubnetInfos) SpaceIDs() set.Strings
- func (s SubnetInfos) Swap(i, j int)
- type SubnetLookup
- type VirtualPortType
Constants ¶
const ( // AlphaSpaceId is the ID of the alpha network space. // Application endpoints are bound to this space by default // if no explicit binding is specified. AlphaSpaceId = "0" // AlphaSpaceName is the name of the alpha network space. AlphaSpaceName = "alpha" )
const InFan = "INFAN"
InFan describes a network fan type.
const SysClassNetPath = "/sys/class/net"
SysClassNetPath is the full Linux SYSFS path containing information about each network interface on the system. TODO (manadart 2021-02-12): This remains in the main "source.go" module because there was previously only one ConfigSource implementation, which presumably did not work on Windows. When the netlinkConfigSource was introduced for use on Linux, we retained the old universal config source for use on Windows. If there comes a time when we properly implement a Windows source, this should be relocated to the Linux module and an appropriate counterpart introduced for Windows.
Variables ¶
var GenerateVirtualMACAddress = func() string { digits := make([]interface{}, 3) for i := range digits { digits[i] = rand.Intn(256) } return fmt.Sprintf(macAddressTemplate, digits...) }
GenerateVirtualMACAddress creates a random MAC address within the address space implied by macAddressTemplate above.
Functions ¶
func APIHostPortsToNoProxyString ¶
func APIHostPortsToNoProxyString(ahp []SpaceHostPorts) string
APIHostPortsToNoProxyString converts list of lists of NetAddrs() to a NoProxy-like comma separated string, ignoring local addresses
func CalculateOverlaySegment ¶
func CalculateOverlaySegment(underlayCIDR string, fan FanConfigEntry) (*net.IPNet, error)
CalculateOverlaySegment takes underlay CIDR and FAN config entry and cuts the segment of overlay that corresponds to this underlay: eg. for FAN 172.31/16 -> 243/8 and physical subnet 172.31.64/20 we get FAN subnet 243.64/12.
func ConvertSpaceName ¶
ConvertSpaceName is used to massage provider-sourced (i.e. MAAS) space names so that they conform to Juju's space name rules.
func DialAddress ¶
DialAddress returns a string value for the input HostPort, suitable for passing as an argument to net.Dial.
func ExactScopeMatch ¶
ExactScopeMatch checks if an address exactly matches any of the specified scopes.
func GetBridgePorts ¶
GetBridgePorts extracts and returns the names of all interfaces configured as ports of the given bridgeName from the Linux kernel userspace SYSFS location "<sysPath/<bridgeName>/brif/*". SysClassNetPath should be passed as sysPath. Returns an empty result if the ports cannot be determined reliably for any reason, or if there are no configured ports for the bridge. Example call: network.GetBridgePorts(network.SysClassNetPath, "br-eth1") TODO (manadart 2021-02-12): As with SysClassNetPath above, specific implementations should be sought for this that are OS-dependent.
func GetDefaultRoute ¶
GetDefaultRoute returns the IP address and device name of default gateway on the machine. If we don't support OS, or we don't have a default route, we return nothing (not an error!).
func IPRangeForCIDR ¶
IPRangeForCIDR returns the first and last addresses that correspond to the provided CIDR. The first address will always be the network address. The returned range also includes the broadcast address. For example, a CIDR of 10.0.0.0/24 yields: [10.0.0.0, 10.0.0.255].
func IsInFanNetwork ¶
func IsNoAddressError ¶
IsNoAddressError reports whether err was created with NoAddressError().
func IsValidAddressConfigType ¶
IsValidAddressConfigType returns whether the given value is a valid method to configure a link-layer network device's IP address. TODO (manadart 2021-05-04): There is an issue with the usage of this method in state where we have denormalised the config method so it is against device addresses. This is because "manual" indicates a device that has no configuration by default. This could never apply to an address.
func IsValidCIDR ¶
IsValidCIDR returns whether cidr is a valid subnet CIDR.
func IsValidLinkLayerDeviceName ¶
IsValidLinkLayerDeviceName returns whether the given name is a valid network link-layer device name, depending on the runtime.GOOS value.
func IsValidLinkLayerDeviceType ¶
IsValidLinkLayerDeviceType returns whether the given value is a valid link-layer network device type.
func NetworkCIDRFromIPAndMask ¶
NetworkCIDRFromIPAndMask constructs a CIDR for a network by applying the provided netmask to the specified address (can be either a host or network address) and formatting the result as a CIDR.
For example, passing 10.0.0.4 and a /24 mask yields 10.0.0.0/24.
func NoAddressError ¶
NoAddressError returns an error which satisfies IsNoAddressError(). The given addressKind specifies what kind of address(es) is(are) missing, usually "private" or "public".
func OvsManagedBridges ¶
OvsManagedBridges returns a set containing the names of all bridge interfaces that are managed by openvswitch.
func SortOrderMostPublic ¶
SortOrderMostPublic calculates the "weight" of the address to use when sorting such that the most accessible addresses will appear first: - public IPs first; - hostnames after that, but "localhost" will be last if present; - cloud-local next; - fan-local next; - machine-local next; - link-local next; - non-hostnames with unknown scope last. Secondary addresses with otherwise equal weight will be sorted to come after primary addresses, including host names *except* localhost.
func SortPortRanges ¶
func SortPortRanges(portRanges []PortRange)
SortPortRanges sorts the given ports, first by protocol, then by number.
func SubnetsForAddresses ¶
SubnetsForAddresses returns subnets corresponding to the addresses in the input address list. There can be situations (observed for CAAS) where the addresses can contain a FQDN. For these cases we log a warning and eschew subnet determination.
func WithCIDR ¶
func WithCIDR(cidr string) func(AddressMutator)
WithCIDR returns a functional option that can be used to set the input CIDR on an address.
func WithConfigType ¶
func WithConfigType(configType AddressConfigType) func(AddressMutator)
func WithScope ¶
func WithScope(scope Scope) func(AddressMutator)
WithScope returns a functional option that can be used to set the input scope on an address.
func WithSecondary ¶
func WithSecondary(isSecondary bool) func(AddressMutator)
WithSecondary returns a functional option that can be used to indicate whether an address is not the primary for its NIC.
Types ¶
type Address ¶
type Address interface { // Host returns the value for the host-name/IP address. Host() string // AddressType returns the type of the address. AddressType() AddressType // AddressScope returns the scope of the address. AddressScope() Scope // AddressCIDR returns the subnet CIDR of the address. AddressCIDR() string // AddressConfigType returns the configuration method of the address. AddressConfigType() AddressConfigType // AddressIsSecondary returns whether this address is not the // primary address associated with the network device. AddressIsSecondary() bool }
Address describes methods for returning details about an IP address or host name.
type AddressConfigType ¶
type AddressConfigType string
AddressConfigType defines valid network link configuration types. See interfaces(5) for details.
const ( ConfigUnknown AddressConfigType = "" ConfigDHCP AddressConfigType = "dhcp" ConfigStatic AddressConfigType = "static" ConfigManual AddressConfigType = "manual" ConfigLoopback AddressConfigType = "loopback" )
type AddressMutator ¶
type AddressMutator interface { // SetScope sets the scope property of the address. SetScope(Scope) // SetCIDR sets the CIDR property of the address. SetCIDR(string) // SetSecondary indicates whether this address is not the // primary address of the device it is associated with. SetSecondary(bool) // SetConfigType indicates how this address was configured. SetConfigType(AddressConfigType) }
AddressMutator describes setter methods for an address.
type AddressType ¶
type AddressType string
AddressType represents the possible ways of specifying a machine location by either a hostname resolvable by dns lookup, or IPv4 or IPv6 address.
const ( HostName AddressType = "hostname" IPv4Address AddressType = "ipv4" IPv6Address AddressType = "ipv6" )
func CIDRAddressType ¶
func CIDRAddressType(cidr string) (AddressType, error)
CIDRAddressType returns back an AddressType to indicate whether the supplied CIDR corresponds to an IPV4 or IPV6 range. An error will be returned if a non-valid CIDR is provided.
Caveat: if the provided CIDR corresponds to an IPV6 range with a 4in6 prefix, the function will classify it as an IPV4 address. This is a known limitation of the go stdlib IP parsing code but it's not something that we are likely to encounter in the wild so there is no need to add extra logic to work around it.
func DeriveAddressType ¶
func DeriveAddressType(value string) AddressType
DeriveAddressType attempts to detect the type of address given.
type AvailabilityZone ¶
type AvailabilityZone interface { // Name returns the name of the availability zone. Name() string // Available reports whether the availability zone is currently available. Available() bool }
AvailabilityZone describes the common methods for general interaction with an AZ.
type AvailabilityZones ¶
type AvailabilityZones []AvailabilityZone
AvailabilityZones is a collection of AvailabilityZone.
func (AvailabilityZones) Validate ¶
func (a AvailabilityZones) Validate(zoneName string) error
Validate checks that a zone with the input name exists and is available according to the topology represented by the receiver. An error is returned if either of these conditions are not met.
type ConfigSource ¶
type ConfigSource interface { // Interfaces returns information about all // network interfaces on the machine. Interfaces() ([]ConfigSourceNIC, error) // DefaultRoute returns the gateway IP address and device name of the // default route on the machine. If there is no default route (known), // then zero values are returned. DefaultRoute() (net.IP, string, error) // OvsManagedBridges returns the names of network interfaces that // correspond to OVS-managed bridges. OvsManagedBridges() (set.Strings, error) // GetBridgePorts returns the names of network interfaces that are ports ot // the bridge with the input device name. GetBridgePorts(string) []string }
ConfigSource defines the necessary calls to obtain the network configuration of a machine.
func DefaultConfigSource ¶
func DefaultConfigSource() ConfigSource
DefaultConfigSource returns a NetworkConfigSource backed by the netlink library, to be used with GetObservedNetworkConfig().
type ConfigSourceAddr ¶
type ConfigSourceAddr interface { // IP returns the address in net.IP form. IP() net.IP // IPNet returns the subnet corresponding with the address // provided that it can be determined. IPNet() *net.IPNet // IsSecondary returns true if this address can be determined not to be // the primary address of its NIC. // Such addresses are added by HA setups like Corosync+Pacemaker. IsSecondary() bool // String returns the address in string form, // including the subnet mask if known. String() string }
ConfigSourceAddr describes addresses detected on a network interface represented by an implementation of ConfigSourceAddr.
type ConfigSourceNIC ¶
type ConfigSourceNIC interface { // Name returns the name of the network interface; E.g. "eth0". Name() string // Type returns the type of the interface - Ethernet, VLAN, Loopback etc. // TODO (manadart 2021-03-03): We do not recognise device types such as // veth, tuntap, macvtap et al. Our parsing falls back to ethernet for such // devices, which we should change in order to have a better informed // networking model. Type() LinkLayerDeviceType // Index returns the index of the interface. Index() int // HardwareAddr returns the hardware address of the interface. // It is the MAC address for ethernet devices. HardwareAddr() net.HardwareAddr // Addresses returns IP addresses associated with the network interface. Addresses() ([]ConfigSourceAddr, error) // MTU returns the maximum transmission unit for the interface. MTU() int // IsUp returns true if the interface is in the "up" state. IsUp() bool }
ConfigSourceNIC describes a network interface detected on the local machine by an implementation of ConfigSource.
type DNSConfig ¶
type DNSConfig struct { Nameservers []ProviderAddress SearchDomains []string }
DNSConfig holds a list of DNS nameserver addresses and default search domains.
func ParseResolvConf ¶
ParseResolvConf parses a resolv.conf(5) file at the given path (usually "/etc/resolv.conf"), if present. Returns the values of any 'nameserver' stanzas, and the last 'search' stanza found. Values in the result will appear in the order found, including duplicates. Parsing errors will be returned in these cases:
- if a 'nameserver' or 'search' without a value is found;
- 'nameserver' with more than one value (trailing comments starting with '#' or ';' after the value are allowed).
- if any value containing '#' or ';' (e.g. 'nameserver 8.8.8.8#bad'), because values and comments following them must be separated by whitespace.
No error is returned if the file is missing. See resolv.conf(5) man page for details.
type FanCIDRs ¶
type FanCIDRs struct { // FanLocalUnderlay is the CIDR of the local underlying fan network. // It allows easy identification of the device the fan is running on. FanLocalUnderlay string // FanOverlay is the CIDR of the complete fan setup. FanOverlay string }
FanCIDRs describes the subnets relevant to a fan network.
type FanConfig ¶
type FanConfig []FanConfigEntry
FanConfig defines a set of fan configurations for the model.
func ParseFanConfig ¶
ParseFanConfig parses fan configuration from model-config in the format: "underlay1=overlay1 underlay2=overlay2" eg. "172.16.0.0/16=253.0.0.0/8 10.0.0.0/12=254.0.0.0/7"
type FanConfigEntry ¶
FanConfigEntry defines a configuration for single fan.
type GroupedPortRanges ¶
GroupedPortRanges represents a list of PortRange instances grouped by a particular feature.
func (GroupedPortRanges) Clone ¶
func (grp GroupedPortRanges) Clone() GroupedPortRanges
Clone returns a copy of this port range grouping.
func (GroupedPortRanges) EqualTo ¶
func (grp GroupedPortRanges) EqualTo(other GroupedPortRanges) bool
EqualTo returns true if this set of grouped port ranges are equal to other.
func (GroupedPortRanges) UniquePortRanges ¶
func (grp GroupedPortRanges) UniquePortRanges() []PortRange
UniquePortRanges returns the unique set of PortRanges in this group.
type HostPort ¶
HostPort describes methods on an object that represents a network connection endpoint.
type HostPorts ¶
type HostPorts []HostPort
HostPorts derives from a slice of HostPort and allows bulk operations on its members.
func CollapseToHostPorts ¶
func CollapseToHostPorts(serversHostPorts []MachineHostPorts) HostPorts
CollapseToHostPorts returns the input nested slice of MachineHostPort as a flat slice of HostPort, preserving the order.
func (HostPorts) FilterUnusable ¶
FilterUnusable returns a copy of the receiver HostPorts after removing any addresses unlikely to be usable (ScopeMachineLocal or ScopeLinkLocal).
func (HostPorts) PrioritizedForScope ¶
func (hps HostPorts) PrioritizedForScope(getMatcher ScopeMatchFunc) []string
PrioritizedForScope orders the HostPorts by best match for the input scope matching function and returns them in NetAddr form. If there are no suitable addresses then an empty slice is returned.
type IDSet ¶
type IDSet map[Id]struct{}
IDSet represents the classic "set" data structure, and contains Id. IDSet is used as a typed version to prevent string -> Id -> string conversion when using set.Strings
func MakeIDSet ¶
MakeIDSet creates and initializes a IDSet and populates it with initial values as specified in the parameters.
func (IDSet) Difference ¶
Difference returns a new IDSet representing all the values in the target that are not in the parameter.
func (IDSet) SortedValues ¶
SortedValues returns an ordered slice containing all the values in the set.
type Id ¶
type Id string
Id defines a provider-specific network ID.
func FilterInFanNetwork ¶
FilterInFanNetwork filters out any fan networks.
func FindSubnetIDsForAvailabilityZone ¶
func FindSubnetIDsForAvailabilityZone(zoneName string, subnetsToZones map[Id][]string) ([]Id, error)
FindSubnetIDsForAvailabilityZone returns a series of subnet IDs from a series of zones, if zones match the zoneName.
Returns an error if no matching subnets match the zoneName.
type InterfaceFilterFunc ¶
type InterfaceFilterFunc func(InterfaceInfo) bool
InterfaceFilterFunc is a function that can be applied to filter a slice of InterfaceInfo instances. Calls to this function should return false if the specified InterfaceInfo should be filtered out.
type InterfaceInfo ¶
type InterfaceInfo struct { // DeviceIndex specifies the order in which the network interface // appears on the host. The primary interface has an index of 0. DeviceIndex int // MACAddress is the network interface's hardware MAC address // (e.g. "aa:bb:cc:dd:ee:ff"). MACAddress string // ProviderId is a provider-specific NIC id. ProviderId Id // ProviderSubnetId is the provider-specific id for the associated // subnet. ProviderSubnetId Id // ProviderNetworkId is the provider-specific id for the // associated network. ProviderNetworkId Id // ProviderSpaceId is the provider-specific id for the associated space, // if known and supported. ProviderSpaceId Id // ProviderVLANId is the provider-specific id of the VLAN for this // interface. ProviderVLANId Id // ProviderAddressId is the provider-specific id of the assigned address. ProviderAddressId Id // AvailabilityZones describes the availability zones the associated // subnet is in. AvailabilityZones []string // VLANTag needs to be between 1 and 4094 for VLANs and 0 for // normal networks. It's defined by IEEE 802.1Q standard. VLANTag int // InterfaceName is the raw OS-specific network device name (e.g. // "eth1", even for a VLAN eth1.42 virtual interface). InterfaceName string // ParentInterfaceName is the name of the parent interface to use, // if known. ParentInterfaceName string // InterfaceType is the type of the interface. InterfaceType LinkLayerDeviceType // Disabled is true when the interface needs to be disabled on the // machine, e.g. not to configure it. Disabled bool // NoAutoStart is true when the interface should not be configured // to start automatically on boot. // By default and for backwards-compatibility, interfaces are // configured to auto-start. NoAutoStart bool // ConfigType determines whether the interface should be // configured via DHCP, statically, manually, etc. See // interfaces(5) for more information. ConfigType AddressConfigType // Addresses contains an optional list of static IP address to // configure for this network interface. The subnet mask to set will be // inferred from the CIDR value of the first entry which is always // assumed to be the primary IP address for the interface. Addresses ProviderAddresses // ShadowAddresses contains an optional list of additional IP addresses // that the underlying network provider associates with this network // interface instance. These IP addresses are not typically visible // to the machine that the interface is connected to. ShadowAddresses ProviderAddresses // DNSServers contains an optional list of IP addresses and/or // host names to configure as DNS servers for this network interface. DNSServers ProviderAddresses // MTU is the Maximum Transmission Unit controlling the maximum size of the // protocol packets that the interface can pass through. It is only used // when > 0. MTU int // DNSSearchDomains contains the default DNS domain to use for non-FQDN // lookups. DNSSearchDomains []string // Gateway address, if set, defines the default gateway to // configure for this network interface. For containers this // usually is (one of) the host address(es). GatewayAddress ProviderAddress // Routes defines a list of routes that should be added when this interface // is brought up, and removed when this interface is stopped. Routes []Route // IsDefaultGateway is set if this device is a default gw on a machine. IsDefaultGateway bool // VirtualPortType provides additional information about the type of // this device if it belongs to a virtual switch (e.g. when using // open-vswitch). VirtualPortType VirtualPortType // Origin represents the authoritative source of the InterfaceInfo. // It is expected that either the provider gave us this info or the // machine gave us this info. // Giving us this information allows us to reason about when a InterfaceInfo // is in use. Origin Origin }
InterfaceInfo describes a single network interface.
A note on ConfigType stored against the interface, and on members of the Addresses collection: Addresses detected for machines during discovery (on-machine or via the instance-poller) are denormalised for storage in that the configuration method (generally associated with the device) is stored for each address. So when incoming, ConfigType supplied with *addresses* is prioritised. Alternatively, when supplied to instance provisioning as network configuration for cloud-init, we are informing how a *device* should be configured for addresses and so we use the ConfigType against the interface.
func (*InterfaceInfo) ActualInterfaceName ¶
func (i *InterfaceInfo) ActualInterfaceName() string
ActualInterfaceName returns raw interface name for raw interface (e.g. "eth0") and virtual interface name for virtual interface (e.g. "eth0.42")
func (*InterfaceInfo) IsVLAN ¶
func (i *InterfaceInfo) IsVLAN() bool
IsVLAN returns true when the interface is a VLAN interface.
func (*InterfaceInfo) IsVirtual ¶
func (i *InterfaceInfo) IsVirtual() bool
IsVirtual returns true when the interface is a virtual device, as opposed to a physical device (e.g. a VLAN, network alias or OVS-managed device).
func (*InterfaceInfo) PrimaryAddress ¶
func (i *InterfaceInfo) PrimaryAddress() ProviderAddress
PrimaryAddress returns the primary address for the interface.
func (*InterfaceInfo) Validate ¶
func (i *InterfaceInfo) Validate() error
Validate checks that the receiver looks like a real interface. An error is returned if invalid members are detected.
type InterfaceInfos ¶
type InterfaceInfos []InterfaceInfo
InterfaceInfos is a slice of InterfaceInfo for a single host/machine/container.
func OvsManagedBridgeInterfaces ¶
func OvsManagedBridgeInterfaces(ifaceList InterfaceInfos) (InterfaceInfos, error)
OvsManagedBridges returns a filtered version of ifaceList that only contains bridge interfaces managed by openvswitch.
func (InterfaceInfos) Filter ¶
func (s InterfaceInfos) Filter(predicateFn InterfaceFilterFunc) InterfaceInfos
Filter applies keepFn to each entry in a InterfaceInfos list and returns back a filtered list containing the entries for which predicateFn returned true.
func (InterfaceInfos) GetByName ¶
func (s InterfaceInfos) GetByName(name string) InterfaceInfos
GetByName returns a new collection containing any interfaces with the input device name.
func (InterfaceInfos) Validate ¶
func (s InterfaceInfos) Validate() error
Validate validates each interface, returning an error if any are invalid
type LinkLayerDeviceType ¶
type LinkLayerDeviceType string
LinkLayerDeviceType defines the type of a link-layer network device.
const ( // UnknownDevice indicates that the type of this device is not known. UnknownDevice LinkLayerDeviceType = "" // LoopbackDevice is used for loopback devices. LoopbackDevice LinkLayerDeviceType = "loopback" // EthernetDevice is used for Ethernet (IEEE 802.3) devices. EthernetDevice LinkLayerDeviceType = "ethernet" // VLAN8021QDevice is used for IEEE 802.1Q VLAN devices. VLAN8021QDevice LinkLayerDeviceType = "802.1q" // BondDevice is used for bonding devices. BondDevice LinkLayerDeviceType = "bond" // BridgeDevice is used for OSI layer-2 bridge devices. BridgeDevice LinkLayerDeviceType = "bridge" // VXLANDevice is used for Virtual Extensible LAN devices. VXLANDevice LinkLayerDeviceType = "vxlan" )
func ParseInterfaceType ¶
func ParseInterfaceType(sysPath, interfaceName string) LinkLayerDeviceType
ParseInterfaceType parses the DEVTYPE attribute from the Linux kernel userspace SYSFS location "<sysPath/<interfaceName>/uevent" and returns it as InterfaceType. SysClassNetPath should be passed as sysPath. Returns UnknownInterface if the type cannot be reliably determined for any reason. Example call: network.ParseInterfaceType(network.SysClassNetPath, "br-eth1") TODO (manadart 2021-02-12): As with SysClassNetPath above, specific implementations should be sought for this that are OS-dependent.
type MachineAddress ¶
type MachineAddress struct { // Value is an IP address or hostname. Value string // Type indicates the form of the address value; // IPv4, IPv6 or host-name. Type AddressType // Scope indicates the visibility of this address. Scope Scope // CIDR is used for IP addresses to indicate // the subnet that they are part of. CIDR string // ConfigType denotes how this address was configured. ConfigType AddressConfigType // IsSecondary if true, indicates that this address is not the primary // address associated with the network device. IsSecondary bool }
MachineAddress represents an address without associated space or provider information. Addresses of this form will be supplied by an agent running directly on a machine or container, or returned for requests where space information is irrelevant to usage.
func NewMachineAddress ¶
func NewMachineAddress(value string, options ...func(AddressMutator)) MachineAddress
NewMachineAddress creates a new MachineAddress, applying any supplied options to the result.
func (MachineAddress) AddressCIDR ¶
func (a MachineAddress) AddressCIDR() string
AddressCIDR returns the subnet CIDR of the address.
func (MachineAddress) AddressConfigType ¶
func (a MachineAddress) AddressConfigType() AddressConfigType
AddressConfigType returns the configuration method of the address.
func (MachineAddress) AddressIsSecondary ¶
func (a MachineAddress) AddressIsSecondary() bool
AddressIsSecondary returns whether this address is not the primary address associated with the network device.
func (MachineAddress) AddressScope ¶
func (a MachineAddress) AddressScope() Scope
AddressScope returns the scope of the address.
func (MachineAddress) AddressType ¶
func (a MachineAddress) AddressType() AddressType
AddressType returns the type of the address.
func (MachineAddress) GoString ¶
func (a MachineAddress) GoString() string
GoString implements fmt.GoStringer.
func (MachineAddress) Host ¶
func (a MachineAddress) Host() string
Host returns the value for the host-name/IP address.
func (MachineAddress) IP ¶
func (a MachineAddress) IP() net.IP
IP returns the net.IP representation of this address.
func (*MachineAddress) SetCIDR ¶
func (a *MachineAddress) SetCIDR(cidr string)
SetCIDR (AddressMutator) sets the input CIDR on the address receiver.
func (*MachineAddress) SetConfigType ¶
func (a *MachineAddress) SetConfigType(configType AddressConfigType)
SetConfigType (AddressMutator) sets the input AddressConfigType on the address receiver.
func (*MachineAddress) SetScope ¶
func (a *MachineAddress) SetScope(scope Scope)
SetScope (AddressMutator) sets the input scope on the address receiver.
func (*MachineAddress) SetSecondary ¶
func (a *MachineAddress) SetSecondary(isSecondary bool)
SetSecondary (AddressMutator) sets the IsSecondary member to true on the address receiver.
func (MachineAddress) String ¶
func (a MachineAddress) String() string
String returns the address value, prefixed with the scope if known.
func (MachineAddress) ValueWithMask ¶
func (a MachineAddress) ValueWithMask() (string, error)
ValueWithMask returns the value of the address combined with the subnet mask indicated by its CIDR.
type MachineHostPort ¶
type MachineHostPort struct { MachineAddress NetPort }
MachineHostPort associates a space-unaware address with a port.
func ParseMachineHostPort ¶
func ParseMachineHostPort(hp string) (*MachineHostPort, error)
ParseMachineHostPort converts a string containing a single host and port value to a MachineHostPort.
func (MachineHostPort) GoString ¶
func (hp MachineHostPort) GoString() string
GoString implements fmt.GoStringer.
func (MachineHostPort) String ¶
func (hp MachineHostPort) String() string
String implements Stringer.
type MachineHostPorts ¶
type MachineHostPorts []MachineHostPort
MachineHostPorts is a slice of MachineHostPort allowing use as a receiver for bulk operations.
func NewMachineHostPorts ¶
func NewMachineHostPorts(port int, addresses ...string) MachineHostPorts
NewMachineHostPorts creates a list of MachineHostPorts from each given string address and port.
func (MachineHostPorts) HostPorts ¶
func (hp MachineHostPorts) HostPorts() HostPorts
HostPorts returns the slice as a new slice of the HostPort indirection.
type NetPort ¶
type NetPort int
NetPort represents a network port. TODO (manadart 2019-08-15): Finish deprecation of `Port` and use that name.
type Origin ¶
type Origin string
Origin specifies where an address comes from, whether it was reported by a provider or by a machine.
type PortRange ¶
PortRange represents a single range of ports on a particular subnet.
func CombinePortRanges ¶
CombinePortRanges groups together all port ranges according to protocol, and then combines then into contiguous port ranges. NOTE: Juju only allows its model to contain non-overlapping port ranges. This method operates on that assumption.
func MustParsePortRange ¶
MustParsePortRange converts a raw port-range string into a PortRange. If the string is invalid, the function panics.
func ParsePortRange ¶
ParsePortRange builds a PortRange from the provided string. If the string does not include a protocol then "tcp" is used. Validate() gets called on the result before returning. If validation fails the invalid PortRange is still returned. Example strings: "80/tcp", "443", "12345-12349/udp", "icmp".
func UniquePortRanges ¶
UniquePortRanges removes any duplicate port ranges from the input and returns de-dupped list back.
func (PortRange) ConflictsWith ¶
ConflictsWith determines if the two port ranges conflict.
func (PortRange) Length ¶
Length returns the number of ports in the range. If the range is not valid, it returns 0. If this range uses ICMP as the protocol then a -1 is returned instead.
func (PortRange) LessThan ¶
LessThan returns true if other should appear after p when sorting a port range list.
func (PortRange) SanitizeBounds ¶
SanitizeBounds returns a copy of the port range, which is guaranteed to have FromPort >= ToPort and both FromPort and ToPort fit into the valid range from 1 to 65535, inclusive.
type ProviderAddress ¶
type ProviderAddress struct { MachineAddress SpaceName SpaceName ProviderSpaceID Id }
ProviderAddress represents an address supplied by provider logic. It can include the provider's knowledge of the space in which the address resides.
func NewProviderAddress ¶
func NewProviderAddress(value string, options ...func(AddressMutator)) ProviderAddress
NewProviderAddress creates a new ProviderAddress, applying any supplied options to the result.
func NewProviderAddressInSpace ¶
func NewProviderAddressInSpace(spaceName string, value string, options ...func(AddressMutator)) ProviderAddress
NewProviderAddressInSpace creates a new ProviderAddress, associating it with the given space name.
func (ProviderAddress) GoString ¶
func (a ProviderAddress) GoString() string
GoString implements fmt.GoStringer.
func (ProviderAddress) String ¶
func (a ProviderAddress) String() string
String returns a string representation of the address, in the form: `<scope>:<address-value>@<space-name>(id:<space-provider-id)`; for example:
public:c2-54-226-162-124.compute-1.amazonaws.com@public-api(id:42)
If the SpaceName is blank, the "@<space-name>" suffix will be omitted. Finally, if the ProviderSpaceID is empty the suffix "(id:<space-provider-id>)" part will be omitted as well.
type ProviderAddresses ¶
type ProviderAddresses []ProviderAddress
ProviderAddresses is a slice of ProviderAddress supporting conversion to SpaceAddresses.
func NewProviderAddresses ¶
func NewProviderAddresses(inAddresses ...string) (outAddresses ProviderAddresses)
NewProviderAddresses is a convenience function to create addresses from a variable number of string arguments.
func NewProviderAddressesInSpace ¶
func NewProviderAddressesInSpace(spaceName string, inAddresses ...string) (outAddresses ProviderAddresses)
NewProviderAddressesInSpace is a convenience function to create addresses in the same space, from a a variable number of string arguments.
func (ProviderAddresses) OneMatchingScope ¶
func (pas ProviderAddresses) OneMatchingScope(getMatcher ScopeMatchFunc) (ProviderAddress, bool)
OneMatchingScope returns the address that best satisfies the input scope matching function. The boolean return indicates if a match was found.
func (ProviderAddresses) ToIPAddresses ¶
func (pas ProviderAddresses) ToIPAddresses() []string
ToIPAddresses transforms the ProviderAddresses to a string slice containing their raw IP values.
func (ProviderAddresses) ToSpaceAddresses ¶
func (pas ProviderAddresses) ToSpaceAddresses(lookup SpaceLookup) (SpaceAddresses, error)
ToSpaceAddresses transforms the ProviderAddresses to SpaceAddresses by using the input lookup for conversion of space name to space ID.
type ProviderHostPort ¶
type ProviderHostPort struct { ProviderAddress NetPort }
ProviderHostPort associates a provider/space aware address with a port.
func (ProviderHostPort) GoString ¶
func (hp ProviderHostPort) GoString() string
GoString implements fmt.GoStringer.
func (ProviderHostPort) String ¶
func (hp ProviderHostPort) String() string
String implements Stringer.
type ProviderHostPorts ¶
type ProviderHostPorts []ProviderHostPort
ProviderHostPorts is a slice of ProviderHostPort allowing use as a receiver for bulk operations.
func ParseProviderHostPorts ¶
func ParseProviderHostPorts(hostPorts ...string) (ProviderHostPorts, error)
ParseProviderHostPorts creates a slice of MachineHostPorts parsing each given string containing address:port. An error is returned if any string cannot be parsed as a MachineHostPort.
func (ProviderHostPorts) Addresses ¶
func (hp ProviderHostPorts) Addresses() ProviderAddresses
Addresses extracts the ProviderAddress from each member of the collection, then returns them as a new collection, effectively discarding the port.
func (ProviderHostPorts) HostPorts ¶
func (hp ProviderHostPorts) HostPorts() HostPorts
HostPorts returns the slice as a new slice of the HostPort indirection.
type ProviderInterfaceInfo ¶
type ProviderInterfaceInfo struct { // InterfaceName is the raw OS-specific network device name (e.g. // "eth1", even for a VLAN eth1.42 virtual interface). InterfaceName string // ProviderId is a provider-specific NIC id. ProviderId Id // HardwareAddress is the network interface's hardware address. The // contents of this field depend on the NIC type (a MAC address for an // ethernet device, a GUID for an infiniband device etc.) HardwareAddress string }
ProviderInterfaceInfo holds enough information to identify an interface or link layer device to a provider so that it can be queried or manipulated. Its initial purpose is to pass to provider.ReleaseContainerAddresses.
type Route ¶
type Route struct { // DestinationCIDR is the subnet that we want a controlled route to. DestinationCIDR string // GatewayIP is the IP (v4 or v6) that should be used for traffic that is // bound for DestinationCIDR GatewayIP string // Metric is the weight to apply to this route. Metric int }
Route defines a single route to a subnet via a defined gateway.
type Scope ¶
type Scope string
Scope denotes the context a location may apply to. If a name or address can be reached from the wider internet, it is considered public. A private network address is either specific to the cloud or cloud subnet a machine belongs to, or to the machine itself for containers.
type ScopeMatch ¶
type ScopeMatch int
ScopeMatch is a numeric designation of how well the requirement for satisfying a scope is met.
func ScopeMatchCloudLocal ¶
func ScopeMatchCloudLocal(addr Address) ScopeMatch
ScopeMatchCloudLocal is an address scope matching function for determining the extent to which the input address' scope satisfies a requirement for accessibility from within the local cloud. Machine-only addresses do not satisfy this matcher.
func ScopeMatchMachineOrCloudLocal ¶
func ScopeMatchMachineOrCloudLocal(addr Address) ScopeMatch
func ScopeMatchPublic ¶
func ScopeMatchPublic(addr Address) ScopeMatch
ScopeMatchPublic is an address scope matching function for determining the extent to which the input address' scope satisfies a requirement for public accessibility.
type ScopeMatchFunc ¶
type ScopeMatchFunc = func(addr Address) ScopeMatch
ScopeMatchFunc is an alias for a function that accepts an Address, and returns what kind of scope match is determined by the body.
type SpaceAddress ¶
type SpaceAddress struct { MachineAddress SpaceID string }
SpaceAddress represents the location of a machine, including metadata about what kind of location the address describes. This is a server-side type that may include a space reference. It is used in logic for filtering addresses by space.
func ConvertToSpaceAddress ¶
func ConvertToSpaceAddress(addr SpaceAddressCandidate, lookup SubnetLookup) (SpaceAddress, error)
ConvertToSpaceAddress returns a SpaceAddress representing the input candidate address, by using the input subnet lookup to associate the address with a space..
func MergedAddresses ¶
func MergedAddresses(machineAddresses, providerAddresses []SpaceAddress) []SpaceAddress
MergedAddresses provides a single list of addresses without duplicates suitable for returning as an address list for a machine. TODO (cherylj) Add explicit unit tests - tracked with bug #1544158
func NewSpaceAddress ¶
func NewSpaceAddress(value string, options ...func(mutator AddressMutator)) SpaceAddress
NewSpaceAddress creates a new SpaceAddress, applying any supplied options to the result.
func (SpaceAddress) GoString ¶
func (a SpaceAddress) GoString() string
GoString implements fmt.GoStringer.
func (SpaceAddress) String ¶
func (a SpaceAddress) String() string
String returns a string representation of the address, in the form: `<scope>:<address-value>@space:<space-id>`; for example:
public:c2-54-226-162-124.compute-1.amazonaws.com@space:1
If the Space ID is empty, the @space:<space-id> suffix will be omitted.
type SpaceAddressCandidate ¶
type SpaceAddressCandidate interface { Value() string ConfigMethod() AddressConfigType SubnetCIDR() string IsSecondary() bool }
SpaceAddressCandidate describes property methods required for conversion to sortable space addresses.
type SpaceAddresses ¶
type SpaceAddresses []SpaceAddress
SpaceAddresses is a slice of SpaceAddress supporting conversion to ProviderAddresses.
func NewSpaceAddresses ¶
func NewSpaceAddresses(inAddresses ...string) (outAddresses SpaceAddresses)
NewSpaceAddresses is a convenience function to create addresses from a variable number of string arguments.
func (SpaceAddresses) AllMatchingScope ¶
func (sas SpaceAddresses) AllMatchingScope(getMatcher ScopeMatchFunc) SpaceAddresses
AllMatchingScope returns the addresses that best satisfy the input scope matching function.
func (SpaceAddresses) EqualTo ¶
func (sas SpaceAddresses) EqualTo(other SpaceAddresses) bool
EqualTo returns true if this set of SpaceAddresses is equal to other.
func (SpaceAddresses) InSpaces ¶
func (sas SpaceAddresses) InSpaces(spaces ...SpaceInfo) (SpaceAddresses, bool)
InSpaces returns the SpaceAddresses that are in the input spaces.
func (SpaceAddresses) Len ¶
func (sas SpaceAddresses) Len() int
func (SpaceAddresses) Less ¶
func (sas SpaceAddresses) Less(i, j int) bool
func (SpaceAddresses) OneMatchingScope ¶
func (sas SpaceAddresses) OneMatchingScope(getMatcher ScopeMatchFunc) (SpaceAddress, bool)
OneMatchingScope returns the address that best satisfies the input scope matching function. The boolean return indicates if a match was found.
func (SpaceAddresses) Swap ¶
func (sas SpaceAddresses) Swap(i, j int)
func (SpaceAddresses) ToProviderAddresses ¶
func (sas SpaceAddresses) ToProviderAddresses(lookup SpaceLookup) (ProviderAddresses, error)
ToProviderAddresses transforms the SpaceAddresses to ProviderAddresses by using the input lookup for conversion of space ID to space info.
func (SpaceAddresses) Values ¶
func (sas SpaceAddresses) Values() []string
Values returns a slice of strings containing the IP/host-name of each of the receiver addresses.
type SpaceHostPort ¶
type SpaceHostPort struct { SpaceAddress NetPort }
SpaceHostPort associates a space ID decorated address with a port.
func (SpaceHostPort) GoString ¶
func (hp SpaceHostPort) GoString() string
GoString implements fmt.GoStringer.
func (SpaceHostPort) Less ¶
func (hp SpaceHostPort) Less(hp2 SpaceHostPort) bool
Less reports whether hp is ordered before hp2 according to the criteria used by SortHostPorts.
type SpaceHostPorts ¶
type SpaceHostPorts []SpaceHostPort
SpaceHostPorts is a slice of SpaceHostPort allowing use as a receiver for bulk operations.
func EnsureFirstHostPort ¶
func EnsureFirstHostPort(first SpaceHostPort, hps SpaceHostPorts) SpaceHostPorts
EnsureFirstHostPort scans the given list of SpaceHostPorts and if "first" is found, it moved to index 0. Otherwise, if "first" is not in the list, it's inserted at index 0.
func NewSpaceHostPorts ¶
func NewSpaceHostPorts(port int, addresses ...string) SpaceHostPorts
NewSpaceHostPorts creates a list of SpaceHostPorts from each input string address and port.
func SpaceAddressesWithPort ¶
func SpaceAddressesWithPort(addrs SpaceAddresses, port int) SpaceHostPorts
SpaceAddressesWithPort returns the input SpaceAddresses all associated with the given port.
func (SpaceHostPorts) AllMatchingScope ¶
func (hps SpaceHostPorts) AllMatchingScope(getMatcher ScopeMatchFunc) []string
AllMatchingScope returns the HostPorts that best satisfy the input scope matching function, as strings usable as arguments to net.Dial.
func (SpaceHostPorts) HostPorts ¶
func (hps SpaceHostPorts) HostPorts() HostPorts
HostPorts returns the slice as a new slice of the HostPort indirection.
func (SpaceHostPorts) InSpaces ¶
func (hps SpaceHostPorts) InSpaces(spaces ...SpaceInfo) (SpaceHostPorts, bool)
InSpaces returns the SpaceHostPorts that are in the input spaces.
func (SpaceHostPorts) Len ¶
func (hps SpaceHostPorts) Len() int
func (SpaceHostPorts) Less ¶
func (hps SpaceHostPorts) Less(i, j int) bool
func (SpaceHostPorts) Swap ¶
func (hps SpaceHostPorts) Swap(i, j int)
func (SpaceHostPorts) ToProviderHostPorts ¶
func (hps SpaceHostPorts) ToProviderHostPorts(lookup SpaceLookup) (ProviderHostPorts, error)
ToProviderHostPorts transforms the SpaceHostPorts to ProviderHostPorts by using the input lookup for conversion of space ID to space info.
type SpaceInfo ¶
type SpaceInfo struct { // ID is the unique identifier for the space. // TODO (manadart 2020-04-10): This should be a typed ID. ID string // Name is the name of the space. // It is used by operators for identifying a space and should be unique. Name SpaceName // ProviderId is the provider's unique identifier for the space, // such as used by MAAS. ProviderId Id // Subnets are the subnets that have been grouped into this network space. Subnets SubnetInfos }
SpaceInfo defines a network space.
type SpaceInfos ¶
type SpaceInfos []SpaceInfo
SpaceInfos is a collection of spaces.
func (SpaceInfos) AllSpaceInfos ¶
func (s SpaceInfos) AllSpaceInfos() (SpaceInfos, error)
AllSpaceInfos satisfies the SpaceLookup interface. It is useful for passing to conversions where we already have the spaces materialised and don't need to pull them from the DB again.
func (SpaceInfos) AllSubnetInfos ¶
func (s SpaceInfos) AllSubnetInfos() (SubnetInfos, error)
AllSubnetInfos returns all subnets contained in this collection of spaces. Since a subnet can only be in one space, we can simply accrue them all with the need for duplicate checking. As with AllSpaceInfos, it implements an interface that can be used to indirect state.
func (SpaceInfos) ContainsID ¶
func (s SpaceInfos) ContainsID(id string) bool
ContainsID returns true if the collection contains a space with the given ID.
func (SpaceInfos) ContainsName ¶
func (s SpaceInfos) ContainsName(name string) bool
ContainsName returns true if the collection contains a space with the given name.
func (SpaceInfos) FanOverlaysFor ¶
func (s SpaceInfos) FanOverlaysFor(subnetIDs IDSet) (SubnetInfos, error)
FanOverlaysFor returns any subnets in this network topology that are fan overlays for the input subnet IDs.
func (SpaceInfos) GetByID ¶
func (s SpaceInfos) GetByID(id string) *SpaceInfo
GetByID returns a reference to the space with the input ID if it exists in the collection. Otherwise nil is returned.
func (SpaceInfos) GetByName ¶
func (s SpaceInfos) GetByName(name string) *SpaceInfo
GetByName returns a reference to the space with the input name if it exists in the collection. Otherwise nil is returned.
func (SpaceInfos) IDs ¶
func (s SpaceInfos) IDs() []string
IDs returns a string slice with each of the space ids in the collection.
func (SpaceInfos) InferSpaceFromAddress ¶
func (s SpaceInfos) InferSpaceFromAddress(addr string) (*SpaceInfo, error)
func (SpaceInfos) InferSpaceFromCIDRAndSubnetID ¶
func (s SpaceInfos) InferSpaceFromCIDRAndSubnetID(cidr, providerSubnetID string) (*SpaceInfo, error)
func (SpaceInfos) Minus ¶
func (s SpaceInfos) Minus(other SpaceInfos) SpaceInfos
Minus returns a new SpaceInfos representing all the values in the target that are not in the parameter. Value matching is done by ID.
func (SpaceInfos) MoveSubnets ¶
func (s SpaceInfos) MoveSubnets(subnetIDs IDSet, spaceName string) (SpaceInfos, error)
MoveSubnets returns a new topology representing the movement of subnets to a new network space.
func (SpaceInfos) Names ¶
func (s SpaceInfos) Names() []string
Names returns a string slice with each of the space names in the collection.
func (SpaceInfos) String ¶
func (s SpaceInfos) String() string
String returns returns a quoted, comma-delimited names of the spaces in the collection, or <none> if the collection is empty.
func (SpaceInfos) SubnetCIDRsBySpaceID ¶
func (s SpaceInfos) SubnetCIDRsBySpaceID() map[string][]string
SubnetCIDRsBySpaceID returns the set of known subnet CIDRs grouped by the space ID they belong to.
type SpaceLookup ¶
type SpaceLookup interface {
AllSpaceInfos() (SpaceInfos, error)
}
SpaceLookup describes the ability to get a complete network topology, as understood by Juju.
type SubnetInfo ¶
type SubnetInfo struct { // ID is the unique ID of the subnet. ID Id // CIDR of the network, in 123.45.67.89/24 format. CIDR string // ProviderId is a provider-specific subnet ID. ProviderId Id // ProviderSpaceId holds the provider ID of the space associated // with this subnet. Can be empty if not supported. ProviderSpaceId Id // ProviderNetworkId holds the provider ID of the network // containing this subnet, for example VPC id for EC2. ProviderNetworkId Id // VLANTag needs to be between 1 and 4094 for VLANs and 0 for // normal networks. It's defined by IEEE 802.1Q standard, and used // to define a VLAN network. For more information, see: // http://en.wikipedia.org/wiki/IEEE_802.1Q. VLANTag int // AvailabilityZones describes which availability zones this // subnet is in. It can be empty if the provider does not support // availability zones. AvailabilityZones []string // SpaceID is the id of the space the subnet is associated with. // Default value should be AlphaSpaceId. It can be empty if // the subnet is returned from an networkingEnviron. SpaceID is // preferred over SpaceName in state and non networkingEnviron use. SpaceID string // SpaceName is the name of the space the subnet is associated with. // An empty string indicates it is part of the AlphaSpaceName OR // if the SpaceID is set. Should primarily be used in an networkingEnviron. SpaceName string // FanInfo describes the fan networking setup for the subnet. // It may be empty if this is not a fan subnet, // or if this subnet information comes from a provider. FanInfo *FanCIDRs // IsPublic describes whether a subnet is public or not. IsPublic bool // contains filtered or unexported fields }
SubnetInfo is a source-agnostic representation of a subnet. It may originate from state, or from a provider.
func (*SubnetInfo) FanLocalUnderlay ¶
func (s *SubnetInfo) FanLocalUnderlay() string
FanLocalUnderlay returns the fan underlay CIDR if known.
func (*SubnetInfo) FanOverlay ¶
func (s *SubnetInfo) FanOverlay() string
FanOverlay returns the fan overlay CIDR if known.
func (*SubnetInfo) ParsedCIDRNetwork ¶
func (s *SubnetInfo) ParsedCIDRNetwork() (*net.IPNet, error)
ParsedCIDRNetwork returns the network represented by the CIDR field.
func (*SubnetInfo) SetFan ¶
func (s *SubnetInfo) SetFan(underlay, overlay string)
SetFan sets the fan networking information for the subnet.
func (*SubnetInfo) Validate ¶
func (s *SubnetInfo) Validate() error
Validate validates the subnet, checking the CIDR, and VLANTag, if present.
type SubnetInfos ¶
type SubnetInfos []SubnetInfo
SubnetInfos is a collection of subnets.
func (SubnetInfos) AllSubnetInfos ¶
func (s SubnetInfos) AllSubnetInfos() (SubnetInfos, error)
AllSubnetInfos implements SubnetLookup by returning all of the subnets.
func (SubnetInfos) ContainsID ¶
func (s SubnetInfos) ContainsID(id Id) bool
ContainsID returns true if the collection contains a space with the given ID.
func (SubnetInfos) EqualTo ¶
func (s SubnetInfos) EqualTo(other SubnetInfos) bool
EqualTo returns true if this slice of SubnetInfo is equal to the input.
func (SubnetInfos) GetByAddress ¶
func (s SubnetInfos) GetByAddress(addr string) (SubnetInfos, error)
GetByAddress returns subnets that based on IP range, include the input IP address.
func (SubnetInfos) GetByCIDR ¶
func (s SubnetInfos) GetByCIDR(cidr string) (SubnetInfos, error)
GetByCIDR returns all subnets in the collection with a CIDR matching the input.
func (SubnetInfos) GetByID ¶
func (s SubnetInfos) GetByID(id Id) *SubnetInfo
GetByID returns a reference to the subnet with the input ID if one is found.
func (SubnetInfos) GetBySpaceID ¶
func (s SubnetInfos) GetBySpaceID(spaceID string) (SubnetInfos, error)
GetBySpaceID returns all subnets with the input space ID, including those inferred by being overlays of subnets in the space.
func (SubnetInfos) GetByUnderlayCIDR ¶
func (s SubnetInfos) GetByUnderlayCIDR(cidr string) (SubnetInfos, error)
GetByUnderlayCIDR returns any subnets in this collection that are fan overlays for the input CIDR. An error is returned if the input is not a valid CIDR. TODO (manadart 2020-04-15): Consider storing subnet IDs in FanInfo, so we can ensure uniqueness in multi-network deployments.
func (SubnetInfos) Len ¶
func (s SubnetInfos) Len() int
func (SubnetInfos) Less ¶
func (s SubnetInfos) Less(i, j int) bool
func (SubnetInfos) SpaceIDs ¶
func (s SubnetInfos) SpaceIDs() set.Strings
SpaceIDs returns the set of space IDs that these subnets are in.
func (SubnetInfos) Swap ¶
func (s SubnetInfos) Swap(i, j int)
type SubnetLookup ¶
type SubnetLookup interface {
AllSubnetInfos() (SubnetInfos, error)
}
SubnetLookup describes retrieving all subnets within a known set of spaces.
type VirtualPortType ¶
type VirtualPortType string
VirtualPortType defines the list of known port types for virtual NICs.
const ( NonVirtualPort VirtualPortType = "" OvsPort VirtualPortType = "openvswitch" )