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

package network

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

Index

Package Files

address.go hostport.go network.go port.go portrange.go space.go subnet.go

Constants

const (
    // DefaultSpaceId is the ID of the default network space.
    // Application endpoints are bound to this space by default
    // if no explicit binding is specified.
    DefaultSpaceId = "0"

    // DefaultSpaceName is the name of the default network space.
    DefaultSpaceName = ""
)

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 [][]HostPort) string

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

func DecimalToIPv4 Uses

func DecimalToIPv4(addr uint32) net.IP

DecimalToIPv4 converts a decimal to the dotted quad IP address format.

func ExactScopeMatch Uses

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

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

func HostPortsToStrings Uses

func HostPortsToStrings(hps []HostPort) []string

HostPortsToStrings converts each HostPort to string calling its NetAddr() method.

func IPv4ToDecimal Uses

func IPv4ToDecimal(ipv4Addr net.IP) (uint32, error)

IPv4ToDecimal converts a dotted quad IP address to its decimal equivalent.

func IsValidCidr Uses

func IsValidCidr(cidr string) bool

IsValidCidr returns whether cidr is a valid subnet CIDR.

func PrioritizeInternalHostPorts Uses

func PrioritizeInternalHostPorts(hps []HostPort, machineLocal bool) []string

PrioritizeInternalHostPorts orders the provided addresses by best match for use as an endpoint for juju internal communication and returns them in NetAddr form. If there are no suitable addresses then an empty slice is returned.

func SelectInternalHostPorts Uses

func SelectInternalHostPorts(hps []HostPort, machineLocal bool) []string

SelectInternalHostPorts picks the best matching HostPorts from a slice that can be used as an endpoint for juju internal communication and returns them in NetAddr form. If there are no suitable addresses, an empty slice is returned.

func SortAddresses Uses

func SortAddresses(addrs []Address)

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 []HostPort)

SortHostPorts sorts the given HostPort slice according to the sortOrder of each HostPort'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.

type Address Uses

type Address struct {
    Value     string
    Type      AddressType
    Scope     Scope
    SpaceName SpaceName
    // TODO (manadart 2019-07-12): Rename to ProviderSpaceId for consistency.
    SpaceProviderId Id
}

Address represents the location of a machine, including metadata about what kind of location the address describes.

func HostsWithoutPort Uses

func HostsWithoutPort(hps []HostPort) []Address

HostsWithoutPort strips the port from each HostPort, returning just the addresses.

func MergedAddresses Uses

func MergedAddresses(machineAddresses, providerAddresses []Address) []Address

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

func NewAddress(value string) Address

NewAddress creates a new Address, deriving its type from the value and using ScopeUnknown as scope. It's a shortcut to calling NewScopedAddress(value, ScopeUnknown).

func NewAddressOnSpace Uses

func NewAddressOnSpace(spaceName string, value string) Address

NewAddressOnSpace creates a new Address, deriving its type and scope from the value and associating it with the given spaceName.

func NewAddresses Uses

func NewAddresses(inAddresses ...string) (outAddresses []Address)

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

func NewAddressesOnSpace Uses

func NewAddressesOnSpace(spaceName string, inAddresses ...string) (outAddresses []Address)

NewAddressesOnSpace is a convenience function to create addresses on the same space, from a a variable number of string arguments.

func NewScopedAddress Uses

func NewScopedAddress(value string, scope Scope) Address

NewScopedAddress creates a new Address, deriving its type from the value.

If the specified scope is ScopeUnknown, then NewScopedAddress will attempt derive the scope based on reserved IP address ranges. Because passing ScopeUnknown is fairly common, NewAddress() above does exactly that.

func SelectAddressesBySpaces Uses

func SelectAddressesBySpaces(addresses []Address, spaces ...SpaceInfo) ([]Address, bool)

SelectAddressesBySpaceNames filters the input slice of Addresses down to those in the input spaces.

func SelectControllerAddress Uses

func SelectControllerAddress(addresses []Address, machineLocal bool) (Address, bool)

SelectControllerAddress returns the most suitable address to use as a Juju Controller (API/state server) endpoint given the list of addresses. The second return value is false when no address can be returned. When machineLocal is true both ScopeCloudLocal and ScopeMachineLocal addresses are considered during the selection, otherwise just ScopeCloudLocal are.

func SelectInternalAddress Uses

func SelectInternalAddress(addresses []Address, machineLocal bool) (Address, bool)

SelectInternalAddress picks one address from a slice that can be used as an endpoint for juju internal communication. If there are no suitable addresses, then ok is false (and an empty address is returned). If a suitable address was found then ok is true.

func SelectInternalAddresses Uses

func SelectInternalAddresses(addresses []Address, machineLocal bool) []Address

SelectInternalAddresses picks the best addresses from a slice that can be used as an endpoint for juju internal communication. I nil slice is returned if there are no suitable addresses identified.

func SelectPublicAddress Uses

func SelectPublicAddress(addresses []Address) (Address, bool)

SelectPublicAddress picks one address from a slice that would be appropriate to display as a publicly accessible endpoint. If there are no suitable addresses, then ok is false (and an empty address is returned). If a suitable address is then ok is true.

func (Address) GoString Uses

func (a Address) GoString() string

GoString implements fmt.GoStringer.

func (Address) String Uses

func (a Address) 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 scope is ScopeUnknown, the initial "<scope>:" prefix will be omitted. If the SpaceName is blank, the "@<space-name>" suffix will be omitted. Finally, if the SpaceProviderId is empty the suffix "(id:<space-provider-id>)" part will be omitted as well.

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

type HostPort struct {
    Address
    Port int
}

HostPort associates an address with a port.

func AddressesWithPort Uses

func AddressesWithPort(addrs []Address, port int) []HostPort

AddressesWithPort returns the given addresses all associated with the given port.

func CollapseHostPorts Uses

func CollapseHostPorts(serversHostPorts [][]HostPort) []HostPort

CollapseHostPorts returns a flattened list of HostPorts keeping the same order they appear in serversHostPorts.

func EnsureFirstHostPort Uses

func EnsureFirstHostPort(first HostPort, hps []HostPort) []HostPort

EnsureFirstHostPort scans the given list of HostPorts 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 FilterUnusableHostPorts Uses

func FilterUnusableHostPorts(hps []HostPort) []HostPort

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

func NewHostPorts Uses

func NewHostPorts(port int, addresses ...string) []HostPort

NewHostPorts creates a list of HostPorts from each given string address and port.

func ParseHostPort Uses

func ParseHostPort(hp string) (*HostPort, error)

ParseHostPort converts a string containing a single host and port value to a HostPort.

func ParseHostPorts Uses

func ParseHostPorts(hostPorts ...string) ([]HostPort, error)

ParseHostPorts creates a list of HostPorts parsing each given string containing address:port. An error is returned if any string cannot be parsed as HostPort.

func SelectHostPortsBySpaces Uses

func SelectHostPortsBySpaces(hps []HostPort, spaces ...SpaceInfo) ([]HostPort, bool)

SelectHostPortsBySpaceNames filters the input slice of HostPorts down to those in the input space names.

func UniqueHostPorts Uses

func UniqueHostPorts(hostPorts []HostPort) []HostPort

UniqueHostPorts returns the given hostPorts after filtering out any duplicates, preserving the input order.

func (HostPort) GoString Uses

func (hp HostPort) GoString() string

GoString implements fmt.GoStringer.

func (HostPort) Less Uses

func (hp1 HostPort) Less(hp2 HostPort) bool

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

func (HostPort) NetAddr Uses

func (hp HostPort) NetAddr() string

NetAddr returns the host-port as an address suitable for calling net.Dial.

func (HostPort) String Uses

func (hp HostPort) String() string

String implements Stringer.

type Id Uses

type Id string

Id defines a provider-specific network ID.

type Port Uses

type Port struct {
    Protocol string
    Number   int
}

Port identifies a network port number for a particular protocol.

NOTE(dimitern): This is deprecated and should be removed, use PortRange instead. There are a few places which still use Port, especially in apiserver/params, so it can't be removed yet.

func (Port) GoString Uses

func (p Port) GoString() string

GoString implements fmt.GoStringer.

func (Port) String Uses

func (p Port) String() string

String implements Stringer.

type PortRange Uses

type PortRange struct {
    FromPort int
    ToPort   int
    Protocol string
}

PortRange represents a single range of ports.

func CollapsePorts Uses

func CollapsePorts(ports []Port) (result []PortRange)

CollapsePorts collapses a slice of ports into port ranges.

NOTE(dimitern): This is deprecated and should be removed when possible. It still exists, because in a few places slices of Ports are converted to PortRanges internally.

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 (PortRange) ConflictsWith Uses

func (a PortRange) ConflictsWith(b PortRange) bool

ConflictsWith determines if the two port ranges conflict.

func (PortRange) GoString Uses

func (p PortRange) GoString() string

func (PortRange) String Uses

func (p PortRange) String() string

func (PortRange) Validate Uses

func (p PortRange) Validate() error

IsValid determines if the port range is valid.

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

type SpaceInfo struct {
    // 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 []SubnetInfo
}

SpaceInfo defines a network space.

type SpaceInfos Uses

type SpaceInfos []SpaceInfo

SpaceInfos is a collection of spaces.

func (SpaceInfos) HasSpaceWithName Uses

func (s SpaceInfos) HasSpaceWithName(name SpaceName) bool

HasSpaceWithName returns true if there is a space in the collection, with the input name.

func (SpaceInfos) String Uses

func (s SpaceInfos) String() string

String returns the comma-delimited names of the spaces in the collection.

type SpaceName Uses

type SpaceName string

SpaceName is the name of a network space.

type SubnetInfo Uses

type SubnetInfo struct {
    // 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

    // SpaceName is the name of the space the subnet is associated with.
    // It can be empty if the subnet is not associated with a space yet.
    // TODO (manadart 2019-07-11): Remove in lieu of SpaceId?
    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
}

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) 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.

Package network imports 11 packages (graph) and is imported by 103 packages. Updated 2019-08-20. Refresh now. Tools for package owners.