Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertSpaceName(name string, existing set.Strings) string
- 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 IsNoAddress(err error) bool
- func NoAddressf(format string, args ...interface{}) error
- func PreferIPv6() bool
- func PrioritizeInternalHostPorts(hps []HostPort, machineLocal bool) []string
- func SelectInternalHostPort(hps []HostPort, machineLocal bool) string
- func SelectInternalHostPorts(hps []HostPort, machineLocal bool) []string
- func SelectMongoHostPortsByScope(hostPorts []HostPort, machineLocal bool) []string
- func SelectMongoHostPortsBySpaces(hostPorts []HostPort, spaces []SpaceName) ([]string, bool)
- func SelectPublicHostPort(hps []HostPort) string
- func SetPreferIPv6(prefer bool)
- 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 MergedAddresses(machineAddresses, providerAddresses []Address) []Address
- func NewAddress(value string) Address
- func NewAddressOnSpace(spaceName string, value string) Address
- func NewAddresses(inAddresses ...string) (outAddresses []Address)
- func NewAddressesOnSpace(spaceName string, inAddresses ...string) (outAddresses []Address)
- func NewScopedAddress(value string, scope Scope) Address
- func ResolvableHostnames(addrs []Address) []Address
- func SelectAddressBySpaces(addresses []Address, spaceNames ...SpaceName) (Address, bool)
- func SelectControllerAddress(addresses []Address, machineLocal bool) (Address, bool)
- 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 ParseHostPort(hp string) (*HostPort, error)
- func ParseHostPorts(hostPorts ...string) ([]HostPort, error)
- func ResolveOrDropHostnames(hps []HostPort) []HostPort
- func SelectHostsPortBySpaces(hps []HostPort, spaceNames ...SpaceName) ([]HostPort, bool)
- type Id
- type InterfaceConfigType
- type InterfaceInfo
- type InterfaceType
- 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 Scope
- type SpaceInfo
- type SpaceName
- type SubnetInfo
Constants ¶
const ( // LoopbackIPv4CIDR is the loopback CIDR range for IPv4. LoopbackIPv4CIDR = "127.0.0.0/8" // LoopbackIPv6CIDR is the loopback CIDR range for IPv6. LoopbackIPv6CIDR = "::1/128" )
const UnknownId = ""
UnknownId can be used whenever an Id is needed but not known.
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.
var SpaceInvalidChars = regexp.MustCompile("[^0-9a-z-]")
SpaceInvalidChars is a regexp for validating that space names contain no invalid characters.
Functions ¶
func ConvertSpaceName ¶
ConvertSpaceName converts names between provider space names and valid juju space names. TODO(mfoord): once MAAS space name rules are in sync with juju space name rules this can go away.
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 IsNoAddress ¶
IsNoAddress reports whether err was created with NoAddressf().
func NoAddressf ¶
NoAddressf returns an error which satisfies IsNoAddress().
func PrioritizeInternalHostPorts ¶
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 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 SelectInternalHostPorts ¶
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 SelectMongoHostPortsBySpaces ¶
SelectMongoHostPorts returns the most suitable HostPort (as string) to use as a Juju Controller (API/state server) endpoint given the list of hostPorts. It first tries to find the first HostPort bound to the spaces provided, then, if that fails, uses the older selection method based on scope. When machineLocal is true and an address can't be selected by space both ScopeCloudLocal and ScopeMachineLocal addresses are considered during the selection, otherwise just ScopeCloudLocal are.
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 SetPreferIPv6 ¶
func SetPreferIPv6(prefer bool)
SetPreferIPv6 determines whether IPv6 addresses will be preferred when selecting a public or internal addresses, using the Select*() methods. SetPreferIPV6 needs to be called to set this flag globally at the earliest time possible (e.g. at bootstrap, agent startup, before any CLI command).
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 Scope SpaceName SpaceProviderId Id }
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 MergedAddresses ¶
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 ¶
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 ¶
NewAddressOnSpace creates a new Address, deriving its type and scope from the value and associating it with the given spaceName.
func NewAddresses ¶
NewAddresses is a convenience function to create addresses from a a variable number of string arguments.
func NewAddressesOnSpace ¶
NewAddressesOnSpace is a convenience function to create addresses on the same space, from a a variable number of string arguments.
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 ResolvableHostnames ¶
ResolvableHostnames returns the set of all DNS resolvable names from addrs. Note that 'localhost' is always considered resolvable because it can be used both as an IPv4 or IPv6 endpoint (e.g., in IPv6-only networks).
func SelectAddressBySpaces ¶
SelectAddressBySpaces picks the first address from the given slice that has the given space name associated.
func SelectControllerAddress ¶
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 ¶
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 was found 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-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 ¶
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 ParseHostPort ¶
ParseHostPort converts a string containing a single host and port value to a HostPort.
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.
func SelectHostsPortBySpaces ¶
SelectHostsPortBySpaces picks the first HostPort from the given slice that has the given space name associated.
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" ConfigLoopback InterfaceConfigType = "loopback" )
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 // ProviderId is a provider-specific NIC id. ProviderId Id // ProviderSubnetId is the provider-specific id for the associated // subnet. ProviderSubnetId 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 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 // MTU is the Maximum Transmission Unit controlling the maximum size of the // protocol packats 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 Address }
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) CIDRAddress ¶
func (i *InterfaceInfo) CIDRAddress() string
CIDRAddress returns Address.Value combined with CIDR mask.
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 InterfaceType ¶
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 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 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 SpaceInfo ¶
type SpaceInfo struct { Name string ProviderId Id Subnets []SubnetInfo }
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 // SpaceProviderId holds the provider Id of the space associated with // this subnet. Can be empty if not supported. SpaceProviderId Id }
SubnetInfo describes the bare minimum information for a subnet, which the provider knows about but juju might not yet.