juju: github.com/juju/juju/core/network Index | Files | Directories

package network

import "github.com/juju/juju/core/network"

Index

Package Files

address.go gateway.go hostport.go linklayer.go network.go nic.go origin.go ovs.go portrange.go space.go subnet.go zone.go

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.

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.

func APIHostPortsToNoProxyString Uses

func APIHostPortsToNoProxyString(ahp []SpaceHostPorts) string

APIHostPortsToNoProxyString converts list of lists of NetAddrs() to a NoProxy-like comma separated string, ignoring local addresses

func ConvertSpaceName Uses

func ConvertSpaceName(name string, existing set.Strings) string

ConvertSpaceName is used to massage provider-sourced (i.e. MAAS) space names so that they conform to Juju's space name rules.

func DialAddress Uses

func DialAddress(a HostPort) string

DialAddress returns a string value for the input HostPort, suitable for passing as an argument to net.Dial.

func ExactScopeMatch Uses

func ExactScopeMatch(addr Address, addrScopes ...Scope) bool

ExactScopeMatch checks if an address exactly matches any of the specified scopes.

func GetDefaultRoute Uses

func GetDefaultRoute() (net.IP, string, error)

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 IsInFanNetwork Uses

func IsInFanNetwork(network Id) bool

func IsValidAddressConfigMethod Uses

func IsValidAddressConfigMethod(value string) bool

IsValidAddressConfigMethod returns whether the given value is a valid method to configure a link-layer network device's IP address.

func IsValidCIDR Uses

func IsValidCIDR(cidr string) bool

IsValidCIDR returns whether cidr is a valid subnet CIDR.

func IsValidLinkLayerDeviceName Uses

func IsValidLinkLayerDeviceName(name string) bool

IsValidLinkLayerDeviceName returns whether the given name is a valid network link-layer device name, depending on the runtime.GOOS value.

func IsValidLinkLayerDeviceType Uses

func IsValidLinkLayerDeviceType(value string) bool

IsValidLinkLayerDeviceType returns whether the given value is a valid link-layer network device type.

func OvsManagedBridges Uses

func OvsManagedBridges() (set.Strings, error)

OvsManagedBridges returns a set containing the names of all bridge interfaces that are managed by openvswitch.

func SortAddresses Uses

func SortAddresses(addrs []SpaceAddress)

SortAddresses sorts the given Address slice according to the sortOrder of each address. See Address.sortOrder() for more info.

func SortHostPorts Uses

func SortHostPorts(hps []SpaceHostPort)

SortHostPorts sorts the given SpaceHostPort slice according to the sortOrder of each SpaceHostPort's embedded Address. See Address.sortOrder() for more info.

func SortPortRanges Uses

func SortPortRanges(portRanges []PortRange)

SortPortRanges sorts the given ports, first by protocol, then by number.

func SortSubnetInfos Uses

func SortSubnetInfos(s SubnetInfos)

SortSubnetInfos sorts subnets by ID.

type Address Uses

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
}

Address describes methods for returning details about an IP address or host name.

type AddressConfigMethod Uses

type AddressConfigMethod string

AddressConfigMethod is the method used to configure a link-layer device's IP address.

const (
    // LoopbackAddress is used for IP addresses of LoopbackDevice types.
    LoopbackAddress AddressConfigMethod = "loopback"

    // StaticAddress is used for statically configured addresses.
    StaticAddress AddressConfigMethod = "static"

    // DynamicAddress is used for addresses dynamically configured via DHCP.
    DynamicAddress AddressConfigMethod = "dynamic"

    // ManualAddress is used for manually configured addresses.
    ManualAddress AddressConfigMethod = "manual"
)

type AddressConfigType Uses

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 AddressType Uses

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 DeriveAddressType Uses

func DeriveAddressType(value string) AddressType

DeriveAddressType attempts to detect the type of address given.

type AvailabilityZone Uses

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 Uses

type AvailabilityZones []AvailabilityZone

AvailabilityZones is a collection of AvailabilityZone.

func (AvailabilityZones) Validate Uses

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 FanCIDRs Uses

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 GroupedPortRanges Uses

type GroupedPortRanges map[string][]PortRange

GroupedPortRanges represents a list of PortRange instances grouped by a particular feature.

func (GroupedPortRanges) Clone Uses

func (grp GroupedPortRanges) Clone() GroupedPortRanges

Clone returns a copy of this port range grouping.

func (GroupedPortRanges) UniquePortRanges Uses

func (grp GroupedPortRanges) UniquePortRanges() []PortRange

UniquePortRanges returns the unique set of PortRanges in this group.

type HostPort Uses

type HostPort interface {
    Address
    Port() int
}

HostPort describes methods on an object that represents a network connection endpoint.

type HostPorts Uses

type HostPorts []HostPort

HostPorts derives from a slice of HostPort and allows bulk operations on its members.

func CollapseToHostPorts Uses

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 Uses

func (hps HostPorts) FilterUnusable() HostPorts

FilterUnusable returns a copy of the receiver HostPorts after removing any addresses unlikely to be usable (ScopeMachineLocal or ScopeLinkLocal).

func (HostPorts) PrioritizedForScope Uses

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.

func (HostPorts) Strings Uses

func (hps HostPorts) Strings() []string

Strings returns the HostPorts as a slice of strings suitable for passing to net.Dial.

func (HostPorts) Unique Uses

func (hps HostPorts) Unique() HostPorts

Unique returns a copy of the receiver HostPorts with duplicate endpoints removed. Note that this only applies to dial addresses; spaces are ignored.

type IDSet Uses

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 Uses

func MakeIDSet(values ...Id) IDSet

MakeIDSet creates and initializes a IDSet and populates it with initial values as specified in the parameters.

func (IDSet) Add Uses

func (s IDSet) Add(value Id)

Add puts a value into the set.

func (IDSet) Contains Uses

func (s IDSet) Contains(id Id) bool

Contains returns true if the value is in the set, and false otherwise.

func (IDSet) Difference Uses

func (s IDSet) Difference(other IDSet) IDSet

Difference returns a new IDSet representing all the values in the target that are not in the parameter.

func (IDSet) IsEmpty Uses

func (s IDSet) IsEmpty() bool

IsEmpty is true for empty or uninitialized sets.

func (IDSet) Size Uses

func (s IDSet) Size() int

Size returns the number of elements in the set.

func (IDSet) SortedValues Uses

func (s IDSet) SortedValues() []Id

SortedValues returns an ordered slice containing all the values in the set.

func (IDSet) Values Uses

func (s IDSet) Values() []Id

Values returns an unordered slice containing all the values in the set.

type Id Uses

type Id string

Id defines a provider-specific network ID.

func FilterInFanNetwork Uses

func FilterInFanNetwork(networks []Id) []Id

FilterInFanNetwork filters out any fan networks.

func FindSubnetIDsForAvailabilityZone Uses

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.

func (Id) String Uses

func (id Id) String() string

String returns the underlying string representation of the Id. This method helps with formatting and type inference.

type InterfaceFilterFunc Uses

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 Uses

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

    // CIDR of the network, in 123.45.67.89/24 format.
    CIDR 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 InterfaceType

    // 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 available on an instance.

func (*InterfaceInfo) ActualInterfaceName Uses

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) CIDRAddress Uses

func (i *InterfaceInfo) CIDRAddress() (string, error)

CIDRAddress returns Address.Value combined with subnet mask. TODO (manadart 2020-07-02): Usage of this method should be phased out in favour of calling ValueForCIDR on each member of the addresses slice.

func (*InterfaceInfo) IsVLAN Uses

func (i *InterfaceInfo) IsVLAN() bool

IsVLAN returns true when the interface is a VLAN interface.

func (*InterfaceInfo) IsVirtual Uses

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 Uses

func (i *InterfaceInfo) PrimaryAddress() ProviderAddress

PrimaryAddress returns the primary address for the interface.

func (*InterfaceInfo) Validate Uses

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 Uses

type InterfaceInfos []InterfaceInfo

InterfaceInfos is a slice of InterfaceInfo for a single host/machine/container.

func OvsManagedBridgeInterfaces Uses

func OvsManagedBridgeInterfaces(ifaceList InterfaceInfos) (InterfaceInfos, error)

OvsManagedBridges returns a filtered version of ifaceList that only contains bridge interfaces managed by openvswitch.

func (InterfaceInfos) Filter Uses

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) GetByHardwareAddress Uses

func (s InterfaceInfos) GetByHardwareAddress(hwAddr string) InterfaceInfos

GetByHardwareAddress returns a new collection containing any interfaces with the input hardware (MAC) address.

func (InterfaceInfos) Validate Uses

func (s InterfaceInfos) Validate() error

Validate validates each interface, returning an error if any are invalid

type InterfaceType Uses

type InterfaceType string

InterfaceType defines valid network interface types.

const (
    UnknownInterface    InterfaceType = ""
    LoopbackInterface   InterfaceType = "loopback"
    EthernetInterface   InterfaceType = "ethernet"
    VLAN_8021QInterface InterfaceType = "802.1q"
    BondInterface       InterfaceType = "bond"
    BridgeInterface     InterfaceType = "bridge"
)

type LinkLayerDeviceType Uses

type LinkLayerDeviceType string

LinkLayerDeviceType defines the type of a link-layer network device.

const (
    // 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"
)

type MachineAddress Uses

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
}

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 Uses

func NewMachineAddress(value string) MachineAddress

NewMachineAddress creates a new MachineAddress, deriving its type from the value and using ScopeUnknown as scope. It is a shortcut to calling NewScopedMachineAddress(value, ScopeUnknown).

func NewScopedMachineAddress Uses

func NewScopedMachineAddress(value string, scope Scope) MachineAddress

NewScopedMachineAddress creates a new MachineAddress, deriving its type from the value. If the specified scope is ScopeUnknown, then NewScopedSpaceAddress will attempt to derive the scope based on reserved IP address ranges. Because passing ScopeUnknown is fairly common, NewMachineAddress() above does exactly that.

func (MachineAddress) AddressCIDR Uses

func (a MachineAddress) AddressCIDR() string

AddressCIDR returns the subnet CIDR of the address.

func (MachineAddress) AddressConfigType Uses

func (a MachineAddress) AddressConfigType() AddressConfigType

AddressConfigType returns the configuration method of the address.

func (MachineAddress) AddressScope Uses

func (a MachineAddress) AddressScope() Scope

AddressScope returns the scope of the address.

func (MachineAddress) AddressType Uses

func (a MachineAddress) AddressType() AddressType

AddressType returns the type of the address.

func (MachineAddress) GoString Uses

func (a MachineAddress) GoString() string

GoString implements fmt.GoStringer.

func (MachineAddress) Host Uses

func (a MachineAddress) Host() string

Host returns the value for the host-name/IP address.

func (MachineAddress) IP Uses

func (a MachineAddress) IP() net.IP

IP returns the net.IP representation of this address.

func (MachineAddress) String Uses

func (a MachineAddress) String() string

String returns the address value, prefixed with the scope if known.

func (MachineAddress) ValueForCIDR Uses

func (a MachineAddress) ValueForCIDR(cidr string) (string, error)

ValueForCIDR returns the value of the address combined with a subnet mask indicated by the input CIDR. TODO (manadart 2020-07-10): This should evolve to use the address CIDR directly instead of receiving a value, once we clean up InterfaceInfo.

type MachineHostPort Uses

type MachineHostPort struct {
    MachineAddress
    NetPort
}

MachineHostPort associates a space-unaware address with a port.

func ParseMachineHostPort Uses

func ParseMachineHostPort(hp string) (*MachineHostPort, error)

ParseMachineHostPort converts a string containing a single host and port value to a MachineHostPort.

func (MachineHostPort) GoString Uses

func (hp MachineHostPort) GoString() string

GoString implements fmt.GoStringer.

func (MachineHostPort) String Uses

func (hp MachineHostPort) String() string

String implements Stringer.

type MachineHostPorts Uses

type MachineHostPorts []MachineHostPort

MachineHostPorts is a slice of MachineHostPort allowing use as a receiver for bulk operations.

func NewMachineHostPorts Uses

func NewMachineHostPorts(port int, addresses ...string) MachineHostPorts

NewMachineHostPorts creates a list of MachineHostPorts from each given string address and port.

func (MachineHostPorts) HostPorts Uses

func (hp MachineHostPorts) HostPorts() HostPorts

HostPorts returns the slice as a new slice of the HostPort indirection.

type NetPort Uses

type NetPort int

NetPort represents a network port. TODO (manadart 2019-08-15): Finish deprecation of `Port` and use that name.

func (NetPort) Port Uses

func (p NetPort) Port() int

Port returns the port number.

type Origin Uses

type Origin string

Origin specifies where an address comes from, whether it was reported by a provider or by a machine.

const (
    // OriginUnknown address origin unknown.
    OriginUnknown Origin = ""
    // OriginProvider address comes from a provider.
    OriginProvider Origin = "provider"
    // OriginMachine address comes from a machine.
    OriginMachine Origin = "machine"
)

type PortRange Uses

type PortRange struct {
    FromPort int
    ToPort   int
    Protocol string
}

PortRange represents a single range of ports on a particular subnet.

func CombinePortRanges Uses

func CombinePortRanges(ranges ...PortRange) []PortRange

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 Uses

func MustParsePortRange(portRange string) PortRange

MustParsePortRange converts a raw port-range string into a PortRange. If the string is invalid, the function panics.

func ParsePortRange Uses

func ParsePortRange(inPortRange string) (PortRange, error)

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 Uses

func UniquePortRanges(portRanges []PortRange) []PortRange

UniquePortRanges removes any duplicate port ranges from the input and returns de-dupped list back.

func (PortRange) ConflictsWith Uses

func (p PortRange) ConflictsWith(other PortRange) bool

ConflictsWith determines if the two port ranges conflict.

func (PortRange) GoString Uses

func (p PortRange) GoString() string

func (PortRange) Length Uses

func (p PortRange) Length() int

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 Uses

func (p PortRange) LessThan(other PortRange) bool

LessThan returns true if other should appear after p when sorting a port range list.

func (PortRange) SanitizeBounds Uses

func (p PortRange) SanitizeBounds() PortRange

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.

func (PortRange) String Uses

func (p PortRange) String() string

String returns a formatted representation of this port range.

func (PortRange) Validate Uses

func (p PortRange) Validate() error

IsValid determines if the port range is valid.

type ProviderAddress Uses

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 Uses

func NewProviderAddress(value string) ProviderAddress

NewProviderAddress creates a new ProviderAddress, deriving its type from the value and using ScopeUnknown as scope. It is a shortcut to calling NewScopedProvider(value, ScopeUnknown).

func NewProviderAddressInSpace Uses

func NewProviderAddressInSpace(spaceName string, value string) ProviderAddress

NewProviderAddressInSpace creates a new ProviderAddress, deriving its type and scope from the value, and associating it with the given space name.

func NewScopedProviderAddress Uses

func NewScopedProviderAddress(value string, scope Scope) ProviderAddress

NewScopedProviderAddress creates a new ProviderAddress by embedding the result of NewScopedMachineAddress. No space information is populated.

func NewScopedProviderAddressInSpace Uses

func NewScopedProviderAddressInSpace(spaceName string, value string, scope Scope) ProviderAddress

NewScopedProviderAddressInSpace creates a new ProviderAddress, deriving its type from the value, and associating it with the given scope and space name.

func (ProviderAddress) GoString Uses

func (a ProviderAddress) GoString() string

GoString implements fmt.GoStringer.

func (ProviderAddress) String Uses

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 Uses

type ProviderAddresses []ProviderAddress

ProviderAddresses is a slice of ProviderAddress supporting conversion to SpaceAddresses.

func NewProviderAddresses Uses

func NewProviderAddresses(inAddresses ...string) (outAddresses ProviderAddresses)

NewProviderAddresses is a convenience function to create addresses from a variable number of string arguments.

func NewProviderAddressesInSpace Uses

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 Uses

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 Uses

func (pas ProviderAddresses) ToIPAddresses() []string

ToIPAddresses transforms the ProviderAddresses to a string slice containing their raw IP values.

func (ProviderAddresses) ToSpaceAddresses Uses

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 Uses

type ProviderHostPort struct {
    ProviderAddress
    NetPort
}

ProviderHostPort associates a provider/space aware address with a port.

func (ProviderHostPort) GoString Uses

func (hp ProviderHostPort) GoString() string

GoString implements fmt.GoStringer.

func (ProviderHostPort) String Uses

func (hp ProviderHostPort) String() string

String implements Stringer.

type ProviderHostPorts Uses

type ProviderHostPorts []ProviderHostPort

ProviderHostPorts is a slice of ProviderHostPort allowing use as a receiver for bulk operations.

func ParseProviderHostPorts Uses

func ParseProviderHostPorts(hostPorts ...string) (ProviderHostPorts, error)

ParseMachineHostPorts 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 Uses

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 Uses

func (hp ProviderHostPorts) HostPorts() HostPorts

HostPorts returns the slice as a new slice of the HostPort indirection.

type ProviderInterfaceInfo Uses

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 Uses

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.

func (Route) Validate Uses

func (r Route) Validate() error

Validate that this Route is properly formed.

type Scope Uses

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.

const (
    ScopeUnknown      Scope = ""
    ScopePublic       Scope = "public"
    ScopeCloudLocal   Scope = "local-cloud"
    ScopeFanLocal     Scope = "local-fan"
    ScopeMachineLocal Scope = "local-machine"
    ScopeLinkLocal    Scope = "link-local"
)

type ScopeMatch Uses

type ScopeMatch int

ScopeMatch is a numeric designation of how well the requirement for satisfying a scope is met.

func ScopeMatchCloudLocal Uses

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 Uses

func ScopeMatchMachineOrCloudLocal(addr Address) ScopeMatch

func ScopeMatchPublic Uses

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 Uses

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 Uses

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 MergedAddresses Uses

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 NewScopedSpaceAddress Uses

func NewScopedSpaceAddress(value string, scope Scope) SpaceAddress

NewScopedSpaceAddress creates a new SpaceAddress, deriving its type from the input value. If the specified scope is ScopeUnknown, then NewScopedSpaceAddress will attempt to derive the scope based on reserved IP address ranges. Because passing ScopeUnknown is fairly common, NewSpaceAddress() above does exactly that.

func NewSpaceAddress Uses

func NewSpaceAddress(value string) SpaceAddress

NewSpaceAddress creates a new SpaceAddress, deriving its type from the input value and using ScopeUnknown as scope.

func (SpaceAddress) GoString Uses

func (a SpaceAddress) GoString() string

GoString implements fmt.GoStringer.

func (SpaceAddress) String Uses

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 SpaceAddresses Uses

type SpaceAddresses []SpaceAddress

SpaceAddresses is a slice of SpaceAddress supporting conversion to ProviderAddresses.

func NewSpaceAddresses Uses

func NewSpaceAddresses(inAddresses ...string) (outAddresses SpaceAddresses)

NewSpaceAddresses is a convenience function to create addresses from a variable number of string arguments.

func (SpaceAddresses) AllMatchingScope Uses

func (sas SpaceAddresses) AllMatchingScope(getMatcher ScopeMatchFunc) SpaceAddresses

AllMatchingScope returns the addresses that best satisfy the input scope matching function.

func (SpaceAddresses) EqualTo Uses

func (sas SpaceAddresses) EqualTo(other SpaceAddresses) bool

EqualTo returns true if this set of SpaceAddresses is equal to other.

func (SpaceAddresses) InSpaces Uses

func (sas SpaceAddresses) InSpaces(spaces ...SpaceInfo) (SpaceAddresses, bool)

InSpaces returns the SpaceAddresses that are in the input spaces.

func (SpaceAddresses) OneMatchingScope Uses

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) ToProviderAddresses Uses

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.

type SpaceHostPort Uses

type SpaceHostPort struct {
    SpaceAddress
    NetPort
}

SpaceHostPort associates a space ID decorated address with a port.

func (SpaceHostPort) GoString Uses

func (hp SpaceHostPort) GoString() string

GoString implements fmt.GoStringer.

func (SpaceHostPort) Less Uses

func (hp SpaceHostPort) Less(hp2 SpaceHostPort) bool

Less reports whether hp is ordered before hp2 according to the criteria used by SortHostPorts.

func (SpaceHostPort) String Uses

func (hp SpaceHostPort) String() string

String implements Stringer.

type SpaceHostPorts Uses

type SpaceHostPorts []SpaceHostPort

SpaceHostPorts is a slice of SpaceHostPort allowing use as a receiver for bulk operations.

func EnsureFirstHostPort Uses

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 Uses

func NewSpaceHostPorts(port int, addresses ...string) SpaceHostPorts

NewSpaceHostPorts creates a list of SpaceHostPorts from each input string address and port.

func SpaceAddressesWithPort Uses

func SpaceAddressesWithPort(addrs SpaceAddresses, port int) SpaceHostPorts

SpaceAddressesWithPort returns the input SpaceAddresses all associated with the given port.

func (SpaceHostPorts) AllMatchingScope Uses

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 Uses

func (hps SpaceHostPorts) HostPorts() HostPorts

HostPorts returns the slice as a new slice of the HostPort indirection.

func (SpaceHostPorts) InSpaces Uses

func (hps SpaceHostPorts) InSpaces(spaces ...SpaceInfo) (SpaceHostPorts, bool)

InSpaces returns the SpaceHostPorts that are in the input spaces.

func (SpaceHostPorts) ToProviderHostPorts Uses

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 Uses

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 Uses

type SpaceInfos []SpaceInfo

SpaceInfos is a collection of spaces.

func (SpaceInfos) AllSpaceInfos Uses

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 Uses

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 Uses

func (s SpaceInfos) ContainsID(id string) bool

ContainsID returns true if the collection contains a space with the given ID.

func (SpaceInfos) ContainsName Uses

func (s SpaceInfos) ContainsName(name string) bool

ContainsName returns true if the collection contains a space with the given name.

func (SpaceInfos) FanOverlaysFor Uses

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 Uses

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 Uses

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 Uses

func (s SpaceInfos) IDs() []string

IDs returns a string slice with each of the space ids in the collection.

func (SpaceInfos) InferSpaceFromAddress Uses

func (s SpaceInfos) InferSpaceFromAddress(addr string) (*SpaceInfo, error)

func (SpaceInfos) InferSpaceFromCIDRAndSubnetID Uses

func (s SpaceInfos) InferSpaceFromCIDRAndSubnetID(cidr, providerSubnetID string) (*SpaceInfo, error)

func (SpaceInfos) Minus Uses

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 Uses

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 Uses

func (s SpaceInfos) Names() []string

Names returns a string slice with each of the space names in the collection.

func (SpaceInfos) String Uses

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 Uses

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 Uses

type SpaceLookup interface {
    AllSpaceInfos() (SpaceInfos, error)
}

SpaceLookup describes the ability to get a complete network topology, as understood by Juju.

type SpaceName Uses

type SpaceName string

SpaceName is the name of a network space.

type SubnetInfo Uses

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 Uses

func (s *SubnetInfo) FanLocalUnderlay() string

FanLocalUnderlay returns the fan underlay CIDR if known.

func (*SubnetInfo) FanOverlay Uses

func (s *SubnetInfo) FanOverlay() string

FanOverlay returns the fan overlay CIDR if known.

func (*SubnetInfo) ParsedCIDRNetwork Uses

func (s *SubnetInfo) ParsedCIDRNetwork() (*net.IPNet, error)

ParsedCIDRNetwork returns the network represented by the CIDR field.

func (*SubnetInfo) SetFan Uses

func (s *SubnetInfo) SetFan(underlay, overlay string)

SetFan sets the fan networking information for the subnet.

func (*SubnetInfo) Validate Uses

func (s *SubnetInfo) Validate() error

Validate validates the subnet, checking the CIDR, and VLANTag, if present.

type SubnetInfos Uses

type SubnetInfos []SubnetInfo

SubnetInfos is a collection of subnets.

func (SubnetInfos) ContainsID Uses

func (s SubnetInfos) ContainsID(id Id) bool

ContainsID returns true if the collection contains a space with the given ID.

func (SubnetInfos) EqualTo Uses

func (s SubnetInfos) EqualTo(other SubnetInfos) bool

EqualTo returns true if this slice of SubnetInfo is equal to the input.

func (SubnetInfos) GetByAddress Uses

func (s SubnetInfos) GetByAddress(addr string) (SubnetInfos, error)

GetByAddress returns subnets that based on IP range, include the input IP address.

func (SubnetInfos) GetByCIDR Uses

func (s SubnetInfos) GetByCIDR(cidr string) (SubnetInfos, error)

GetByCIDR returns all subnets in the collection with a CIDR matching the input.

func (SubnetInfos) GetByID Uses

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 Uses

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 Uses

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 Uses

func (s SubnetInfos) Len() int

func (SubnetInfos) Less Uses

func (s SubnetInfos) Less(i, j int) bool

func (SubnetInfos) SpaceIDs Uses

func (s SubnetInfos) SpaceIDs() set.Strings

SpaceIDs returns the set of space IDs that these subnets are in.

func (SubnetInfos) Swap Uses

func (s SubnetInfos) Swap(i, j int)

type SubnetLookup Uses

type SubnetLookup interface {
    AllSubnetInfos() (SubnetInfos, error)
}

SubnetLookup describes retrieving all subnets within a known set of spaces.

type VirtualPortType Uses

type VirtualPortType string

VirtualPortType defines the list of known port types for virtual NICs.

const (
    NonVirtualPort VirtualPortType = ""
    OvsPort        VirtualPortType = "openvswitch"
)

Directories

PathSynopsis
testing

Package network imports 13 packages (graph) and is imported by 224 packages. Updated 2020-08-13. Refresh now. Tools for package owners.