Documentation ¶
Index ¶
- Constants
- Variables
- func DecimalToIPv4(addr uint32) net.IP
- func ExactScopeMatch(addr Address, addrScopes ...Scope) bool
- func HostPortsToStrings(hps []HostPort) []string
- func IPv4ToDecimal(ipv4Addr net.IP) (uint32, error)
- func InitializeFromConfig(config PreferIPv6Getter)
- func IsNoAddress(err error) bool
- func NoAddressf(format string, args ...interface{}) error
- func ResetGlobalPreferIPv6()
- func SelectInternalHostPort(hps []HostPort, machineLocal bool) string
- func SelectPublicHostPort(hps []HostPort) string
- func SortAddresses(addrs []Address, preferIPv6 bool)
- func SortHostPorts(hps []HostPort, preferIPv6 bool)
- func SortInterfaceInfo(interfaces []InterfaceInfo)
- func SortPortRanges(portRanges []PortRange)
- type Address
- func FilterLXCAddresses(addresses []Address) []Address
- func HostsWithoutPort(hps []HostPort) []Address
- func NewAddress(value string) Address
- func NewAddresses(inAddresses ...string) (outAddresses []Address)
- func NewScopedAddress(value string, scope Scope) Address
- func SelectInternalAddress(addresses []Address, machineLocal bool) (Address, bool)
- func SelectPublicAddress(addresses []Address) (Address, bool)
- type AddressType
- type BySpaceName
- type HostPort
- func AddressesWithPort(addrs []Address, port int) []HostPort
- func CollapseHostPorts(serversHostPorts [][]HostPort) []HostPort
- func DropDuplicatedHostPorts(hps []HostPort) []HostPort
- func EnsureFirstHostPort(first HostPort, hps []HostPort) []HostPort
- func FilterUnusableHostPorts(hps []HostPort) []HostPort
- func NewHostPorts(port int, addresses ...string) []HostPort
- func ParseHostPorts(hostPorts ...string) ([]HostPort, error)
- func ResolveOrDropHostnames(hps []HostPort) []HostPort
- type Id
- type InterfaceConfigType
- type InterfaceInfo
- type Port
- type PortRange
- type PortSet
- func (ps *PortSet) Add(protocol string, port int)
- func (ps *PortSet) AddRanges(portRanges ...PortRange)
- func (ps *PortSet) Contains(protocol string, port int) bool
- func (ps *PortSet) ContainsRanges(portRanges ...PortRange) bool
- func (ps PortSet) Difference(other PortSet) PortSet
- func (ps PortSet) Intersection(other PortSet) PortSet
- func (ps PortSet) IsEmpty() bool
- func (ps PortSet) PortNumbers(protocol string) []int
- func (ps PortSet) PortRanges(protocols ...string) []PortRange
- func (ps PortSet) PortStrings(protocol string) []string
- func (ps PortSet) Ports(protocols ...string) []Port
- func (ps PortSet) Protocols() []string
- func (ps *PortSet) Remove(protocol string, port int)
- func (ps *PortSet) RemoveRanges(portRanges ...PortRange)
- func (ps PortSet) Size() int
- func (ps PortSet) Union(other PortSet) PortSet
- func (ps PortSet) Values() []Port
- type PreferIPv6Getter
- type Scope
- type SpaceInfo
- type SubnetInfo
Constants ¶
const ( // Id of the default public juju network DefaultPublic = "juju-public" // Id of the default private juju network DefaultPrivate = "juju-private" // Provider Id for the default network DefaultProviderId = "juju-unknown" )
TODO(dimitern): Remove this once we use spaces as per the model.
Variables ¶
var InterfaceByNameAddrs = func(name string) ([]net.Addr, error) { iface, err := net.InterfaceByName(name) if err != nil { return nil, err } return iface.Addrs() }
InterfaceByNameAddrs returns the addresses for the given interface name. It's exported to facilitate cross-package testing.
var LXCNetDefaultConfig = "/etc/default/lxc-net"
LXCNetDefaultConfig is the location of the default network config of the lxc package. It's exported to allow cross-package testing.
Functions ¶
func DecimalToIPv4 ¶
DecimalToIPv4 converts a decimal to the dotted quad IP address format.
func ExactScopeMatch ¶
ExactScopeMatch checks if an address exactly matches any of the specified scopes. An address will not match if globalPreferIPv6 is set and it isn't an IPv6 address.
func HostPortsToStrings ¶
HostPortsToStrings converts each HostPort to string calling its NetAddr() method.
func IPv4ToDecimal ¶
IPv4ToDecimal converts a dotted quad IP address to its decimal equivalent.
func InitializeFromConfig ¶
func InitializeFromConfig(config PreferIPv6Getter)
InitializeFromConfig needs to be called once after the environment or agent configuration is available to configure networking settings.
func IsNoAddress ¶
IsNoAddress reports whether err was created with NoAddressf().
func NoAddressf ¶
NoAddressf returns an error which satisfies IsNoAddress().
func ResetGlobalPreferIPv6 ¶
func ResetGlobalPreferIPv6()
ResetGlobalPreferIPv6 resets the global variable back to the default, and is called only from the isolation test suite to make sure we have a clean environment.
func SelectInternalHostPort ¶
SelectInternalHostPort picks one HostPort from a slice that can be used as an endpoint for juju internal communication and returns it in its NetAddr form. If there are no suitable addresses, the empty string is returned.
func SelectPublicHostPort ¶
SelectPublicHostPort picks one HostPort from a slice that would be appropriate to display as a publicly accessible endpoint. If there are no suitable candidates, the empty string is returned.
func SortAddresses ¶
SortAddresses sorts the given Address slice according to the sortOrder of each address and the preferIpv6 flag. See Address.sortOrder() for more info.
func SortHostPorts ¶
SortHostPorts sorts the given HostPort slice according to the sortOrder of each HostPort's embedded Address and the preferIpv6 flag. See Address.sortOrder() for more info.
func SortInterfaceInfo ¶
func SortInterfaceInfo(interfaces []InterfaceInfo)
SortInterfaceInfo sorts a slice of InterfaceInfo on DeviceIndex in ascending order.
func SortPortRanges ¶
func SortPortRanges(portRanges []PortRange)
SortPortRanges sorts the given ports, first by protocol, then by number.
Types ¶
type Address ¶
type Address struct { Value string Type AddressType NetworkName string Scope }
Address represents the location of a machine, including metadata about what kind of location the address describes.
func FilterLXCAddresses ¶
FilterLXCAddresses tries to discover the default lxc bridge name and all of its addresses, then filters those addresses out of the given ones and returns the result. Any errors encountered during this process are logged, but not considered fatal. See LP bug #1416928.
func HostsWithoutPort ¶
HostsWithoutPort strips the port from each HostPort, returning just the addresses.
func NewAddress ¶
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 NewAddresses ¶
NewAddresses is a convenience function to create addresses from a string slice.
func NewScopedAddress ¶
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 SelectInternalAddress ¶
SelectInternalAddress picks one address from a slice that can be used as an endpoint for juju internal communication. If there are are no suitable addresses, then ok is false (and an empty address is returned). If a suitable address is then ok is true.
func SelectPublicAddress ¶
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) String ¶
String returns a string representation of the address, in the form: scope:address(network name); for example:
public:c2-54-226-162-124.compute-1.amazonaws.com(ec2network)
If the scope is NetworkUnknown, the initial scope: prefix will be omitted. If the NetworkName is blank, the (network name) suffix will be omitted.
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 DeriveAddressType ¶
func DeriveAddressType(value string) AddressType
DeriveAddressType attempts to detect the type of address given.
type BySpaceName ¶
type BySpaceName []SpaceInfo
func (BySpaceName) Len ¶
func (s BySpaceName) Len() int
func (BySpaceName) Less ¶
func (s BySpaceName) Less(i, j int) bool
func (BySpaceName) Swap ¶
func (s BySpaceName) Swap(i, j int)
type HostPort ¶
HostPort associates an address with a port.
func AddressesWithPort ¶
AddressesWithPort returns the given addresses all associated with the given port.
func CollapseHostPorts ¶
CollapseHostPorts returns a flattened list of HostPorts keeping the same order they appear in serversHostPorts.
func DropDuplicatedHostPorts ¶
DropDuplicatedHostPorts removes any HostPorts duplicates from the given slice and returns the result.
func EnsureFirstHostPort ¶
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 ¶
FilterUnusableHostPorts returns a copy of the given HostPorts after removing any addresses unlikely to be usable (ScopeMachineLocal or ScopeLinkLocal).
func NewHostPorts ¶
NewHostPorts creates a list of HostPorts from each given string address and port.
func ParseHostPorts ¶
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 ResolveOrDropHostnames ¶
ResolveOrDropHostnames tries to resolve each address of type HostName (except for "localhost" - it's kept unchanged) using the local resolver. If successful, each IP address corresponding to the hostname is inserted in the same order. If not successful, a debug log is added and the hostname is removed from the list. Duplicated addresses after the resolving is done are removed.
type Id ¶
type Id string
Id defines a provider-specific network id.
const AnySubnet Id = ""
AnySubnet when passed as a subnet id should be interpreted by the providers as "the subnet id does not matter". It's up to the provider how to handle this case - it might return an error.
type InterfaceConfigType ¶
type InterfaceConfigType string
InterfaceConfigType defines valid network interface configuration types. See interfaces(5) for details
const ( ConfigUnknown InterfaceConfigType = "" ConfigDHCP InterfaceConfigType = "dhcp" ConfigStatic InterfaceConfigType = "static" ConfigManual InterfaceConfigType = "manual" )
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 // CIDR of the network, in 123.45.67.89/24 format. CIDR string // NetworkName is juju-internal name of the network. NetworkName string // ProviderId is a provider-specific NIC id. ProviderId Id // ProviderSubnetId is the provider-specific id for the associated // subnet. ProviderSubnetId 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 // 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 InterfaceConfigType // Address contains an optional static IP address to configure for // this network interface. The subnet mask to set will be inferred // from the CIDR value. Address Address // DNSServers contains an optional list of IP addresses and/or // hostnames to configure as DNS servers for this network // interface. DNSServers []Address // DNSSearch contains the default DNS domain to use for // non-FQDN lookups. DNSSearch 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 Address // ExtraConfig can contain any valid setting and its value allowed // inside an "iface" section of a interfaces(5) config file, e.g. // "up", "down", "mtu", etc. ExtraConfig map[string]string }
InterfaceInfo describes a single network interface available on an instance. For providers that support networks, this will be available at StartInstance() time. TODO(mue): Rename to InterfaceConfig due to consistency later.
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 or a network alias)
type Port ¶
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.
type PortRange ¶
PortRange represents a single range of ports.
func CollapsePorts ¶
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 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".
func ParsePortRanges ¶
ParsePortRanges splits the provided string on commas and extracts a PortRange from each part of the split string. Whitespace is ignored. Example strings: "80/tcp", "80,443,1234/udp", "123-456, 25/tcp".
func (PortRange) ConflictsWith ¶
ConflictsWith determines if the two port ranges conflict.
type PortSet ¶
type PortSet struct {
// contains filtered or unexported fields
}
PortSet is a set-like container of Port values.
func NewPortSet ¶
NewPortSet creates a map of protocols to sets of stringified port numbers.
func (*PortSet) ContainsRanges ¶
ContainsRanges returns true if the provided port ranges are in the set.
func (PortSet) Difference ¶
Difference returns a new PortSet of the values that are not in the other PortSet.
func (PortSet) Intersection ¶
Intersection returns a new PortSet of the values that are in both this set and the other, but not in just one of either.
func (PortSet) PortNumbers ¶
PortNumbers returns a list of all the port numbers in the set for the given protocol.
func (PortSet) PortRanges ¶
PortRanges returns a list of all the port ranges in the set for the given protocols. If no protocols are provided all known protocols in the set are used.
func (PortSet) PortStrings ¶
PortStrings returns a list of stringified ports in the set for the given protocol. This is strictly a convenience method for situations where another API requires a list of strings.
func (PortSet) Ports ¶
PortNumbers returns a list of all the port numbers in the set for the given protocols. If no protocols are provided then all known protocols in the set are used.
func (*PortSet) RemoveRanges ¶
RemoveRanges removes all ports in the given PortRange values from the set.
type PreferIPv6Getter ¶
type PreferIPv6Getter interface {
PreferIPv6() bool
}
PreferIPv6Getter will be implemented by both the environment and agent config.
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 SubnetInfo ¶
type SubnetInfo struct { // CIDR of the network, in 123.45.67.89/24 format. Can be empty if // unknown. CIDR string // ProviderId is a provider-specific network id. This the only // required field. ProviderId 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 // AllocatableIPLow and AllocatableIPHigh describe the allocatable // portion of the subnet. The provider will only permit allocation // between these limits. If they are empty then none of the subnet is // allocatable. AllocatableIPLow net.IP AllocatableIPHigh net.IP // AvailabilityZones describes which availability zone(s) this // subnet is in. It can be empty if the provider does not support // availability zones. AvailabilityZones []string // SpaceName holds the juju network space associated with this // subnet. Can be empty if not supported. SpaceName string }
SubnetInfo describes the bare minimum information for a subnet, which the provider knows about but juju might not yet.