Documentation
¶
Overview ¶
Package networking provides IP address management functionality. Mostly a copy/paste from https://github.com/giantswarm/ipam without proprietary service/error handling
Index ¶
- Constants
- Variables
- func Add(ip net.IP, number int) net.IP
- func Broadcast(network net.IPNet) net.IP
- func CalculateSubnetMask(networkMask net.IPMask, n uint) (net.IPMask, error)
- func CanonicalizeSubnets(networkRange net.IPNet, subnets []net.IPNet) []net.IPNet
- func Contains(network, subnet net.IPNet) bool
- func Free(network net.IPNet, mask net.IPMask, subnets []net.IPNet) (net.IPNet, error)
- func Half(network net.IPNet) (first, second net.IPNet, err error)
- func IPLessThan(a, b net.IP) bool
- func IPNetfromCIDRString(mynet string) *net.IPNet
- func IsManagementSwitchTypeValid(mst ManagementSwitchType) bool
- func NetIPInSlice(a net.IP, list []net.IP) int
- func Split(network net.IPNet, n uint) ([]net.IPNet, error)
- func SubnetWithin(network net.IPNet, hostNumber int) (net.IPNet, error)
- type BootstrapSwitchMetadata
- type IPNets
- type IPRange
- type IPReservation
- type IPV4Network
- func (iNet *IPV4Network) AddBiggestSubnet(mask net.IPMask, name string, vlanID int16) (*IPV4Subnet, error)
- func (iNet *IPV4Network) AddSubnet(mask net.IPMask, name string, vlanID int16) (*IPV4Subnet, error)
- func (iNet *IPV4Network) AddSubnetbyCIDR(desiredNet net.IPNet, name string, vlanID int16) (*IPV4Subnet, error)
- func (iNet IPV4Network) AllocatedSubnets() []net.IPNet
- func (iNet IPV4Network) AllocatedVlans() []int16
- func (iNet *IPV4Network) ApplySupernetHack()
- func (iNet *IPV4Network) GenSubnets(cabinetDetails []sls.CabinetGroupDetail, mask net.IPMask, ...) error
- func (iNet *IPV4Network) LookUpSubnet(name string) (*IPV4Subnet, error)
- func (iNet IPV4Network) SubnetbyName(name string) IPV4Subnet
- type IPV4Subnet
- func (iSubnet *IPV4Subnet) AddReservation(name, comment string) *IPReservation
- func (iSubnet *IPV4Subnet) AddReservationWithIP(name, addr, comment string) (*IPReservation, error)
- func (iSubnet *IPV4Subnet) AddReservationWithPin(name, comment string, pin uint8) *IPReservation
- func (iSubnet *IPV4Subnet) LookupReservation(resName string) IPReservation
- func (iSubnet *IPV4Subnet) ReservationsByName() map[string]IPReservation
- func (iSubnet *IPV4Subnet) ReserveEdgeSwitchIPs(edges []string)
- func (iSubnet *IPV4Subnet) ReserveNetMgmtIPs(spines []string, leafs []string, leafbmcs []string, cdus []string)
- func (iSubnet *IPV4Subnet) ReservedIPs() []net.IP
- func (iSubnet *IPV4Subnet) TotalIPAddresses() int
- func (iSubnet *IPV4Subnet) UpdateDHCPRange(applySupernetHack bool)
- func (iSubnet *IPV4Subnet) UsableHostAddresses() int
- type ManagementSwitch
- type ManagementSwitchBrand
- type ManagementSwitchType
- type PinnedReservation
Constants ¶
const ( // ManagementSwitchBrandAruba for Aruba Management switches ManagementSwitchBrandAruba ManagementSwitchBrand = "Aruba" // ManagementSwitchBrandDell for Dell Management switches ManagementSwitchBrandDell ManagementSwitchBrand = "Dell" // ManagementSwitchBrandMellanox for Mellanox Management switches ManagementSwitchBrandMellanox ManagementSwitchBrand = "Mellanox" // ManagementSwitchBrandArista for Arista Edge switches ManagementSwitchBrandArista ManagementSwitchBrand = "Arista" // ManagementSwitchBrandCisco for Cisco Edge switches ManagementSwitchBrandCisco ManagementSwitchBrand = "Cisco" // ManagementSwitchBrandJuniper for Juniper Edge switches ManagementSwitchBrandJuniper ManagementSwitchBrand = "Juniper" // ManagementSwitchTypeCDU is the type for CDU Management switches ManagementSwitchTypeCDU ManagementSwitchType = "CDU" // ManagementSwitchTypeLeafBMC is the type for Leaf Management switches ManagementSwitchTypeLeafBMC ManagementSwitchType = "LeafBMC" // ManagementSwitchTypeSpine is the type for Spine Management switches ManagementSwitchTypeSpine ManagementSwitchType = "Spine" // ManagementSwitchTypeLeaf is the type for Leaf Management switches ManagementSwitchTypeLeaf ManagementSwitchType = "Leaf" // ManagementSwitchTypeEdge is the type for Edge Management switches ManagementSwitchTypeEdge ManagementSwitchType = "Edge" )
const SubrolePlaceHolder = "~fixme~"
SubrolePlaceHolder is the placeholder used to indicate that a prefix has no subrole mapping in ApplicationNodeConfig.
Variables ¶
var DefaultApplicationNodePrefixes = []string{
"uan",
"gn",
"ln",
}
DefaultApplicationNodePrefixes is the list of default Application node prefixes, for source column in the hmn_connections.json
var DefaultApplicationNodeSubroles = map[string]string{
"uan": "UAN",
"ln": "UAN",
"gn": "Gateway",
}
DefaultApplicationNodeSubroles is the default prefix<->subrole mapping for application node subroles, these can be overridden via ApplicationNodeConfig
var DefaultUAISubnetReservations = map[string][]string{
"uai_nmn_blackhole": {"uai-nmn-blackhole"},
"slurmctld_service": {
"slurmctld-service",
"slurmctld-service-nmn",
},
"slurmdbd_service": {
"slurmdbd-service",
"slurmdbd-service-nmn",
},
"pbs_service": {
"pbs-service",
"pbs-service-nmn",
},
"pbs_comm_service": {
"pbs-comm-service",
"pbs-comm-service-nmn",
},
}
DefaultUAISubnetReservations is the map of dns names and aliases
var Networks = [...]string{
"cmn",
"hmn",
"mtl",
"nmn",
}
Networks - The networks that need IPAM.
var PinnedMetalLBReservations = map[string]PinnedReservation{ "istio-ingressgateway": { 71, strings.Split( "api-gw-service api-gw-service-nmn.local packages registry spire.local api_gw_service registry.local packages packages.local spire", " ", ), }, "istio-ingressgateway-local": { 81, []string{"api-gw-service.local"}, }, "rsyslog-aggregator": { 72, []string{"rsyslog-agg-service"}, }, "cray-tftp": { 60, []string{"tftp-service"}, }, "unbound": { 225, []string{"unbound"}, }, "docker-registry": { 73, []string{"docker_registry_service"}, }, }
PinnedMetalLBReservations is the map of dns names and aliases with the required final octet of th ip address *** This structure is only necessary to pin ip addresses as we shift from 1.3 to 1.4 *** *** *** *** To anyone editing this code in the future, PLEASE DON'T MAKE IT BETTER *** *** *** *** *** *** This code is written to be thrown away with a fully dynamic ip addressing scheme *** *** ***
var ValidNetNames = []string{
"BICAN",
"CAN",
"CHN",
"CMN",
"HMN",
"HMN_MTN",
"HMN_RVR",
"MTL",
"NMN",
"NMN_MTN",
"NMN_RVR",
}
ValidNetNames is the list of strings that enumerate valid main network names
Functions ¶
func Add ¶
Add increments the given IP by the number. e.g: add(10.0.4.0, 1) -> 10.0.4.1. Negative values are allowed for decrementing.
func CalculateSubnetMask ¶
CalculateSubnetMask calculates new subnet mask to accommodate n subnets.
func CanonicalizeSubnets ¶
CanonicalizeSubnets iterates over subnets and returns deduplicated list of networks that belong to networkRange. Subnets that overlap each other but aren't exactly the same are not removed. Subnets are returned in the same order as they appear in input.
Example:
networkRange: 192.168.2.0/24 subnets: [172.168.2.0/25, 192.168.2.0/25, 192.168.3.128/25, 192.168.2.0/25, 192.168.2.128/25] returned: [192.168.2.0/25, 192.168.2.128/25]
Example 2:
networkRange: 10.0.0.0/8 subnets: [10.1.0.0/16, 10.1.0.0/24, 10.1.1.0/24] returned: [10.1.0.0/16, 10.1.0.0/24, 10.1.1.0/24]
func Free ¶
Free takes a network, a mask, and a list of subnets. An available network, within the first network, is returned.
func IPLessThan ¶
IPLessThan compare two ip addresses by section left-most is most significant
func IPNetfromCIDRString ¶
IPNetfromCIDRString converts from a string to an net.IPNet struct
func IsManagementSwitchTypeValid ¶
func IsManagementSwitchTypeValid(mst ManagementSwitchType) bool
IsManagementSwitchTypeValid validates the given ManagementSwitchType
func NetIPInSlice ¶
NetIPInSlice makes it easy to assess if an IP address is present in a list of ips
Types ¶
type BootstrapSwitchMetadata ¶
type BootstrapSwitchMetadata struct {
Xname string `json:"xname" csv:"Switch Xname"`
Type string `json:"type" csv:"Type"`
}
BootstrapSwitchMetadata is a type that matches the switch_metadata.csv file as Switch Xname, Type The type can be CDU, Spine, Leaf, or LeafBMC
type IPRange ¶
type IPRange struct {
// contains filtered or unexported fields
}
IPRange defines a pair of IPs, over a range.
func NewIPRange ¶
NewIPRange takes an IPNet, and returns the ipRange of the network.
type IPReservation ¶
type IPReservation struct {
IPAddress net.IP `yaml:"ip_address"`
Name string `yaml:"name"`
Comment string `yaml:"comment"`
Aliases []string `yaml:"aliases"`
}
IPReservation is a type for managing IP Reservations
func (*IPReservation) AddReservationAlias ¶
func (iReserv *IPReservation) AddReservationAlias(alias string)
AddReservationAlias adds an alias to a reservation if it doesn't already exist
type IPV4Network ¶
type IPV4Network struct {
FullName string `yaml:"full_name"`
CIDR string `yaml:"cidr"`
Subnets []*IPV4Subnet `yaml:"subnets"`
Name string `yaml:"name"`
VlanRange []int16 `yaml:"vlan_range"`
MTU int16 `yaml:"mtu"`
NetType slsCommon.NetworkType `yaml:"type"`
Comment string `yaml:"comment"`
PeerASN int `yaml:"peer-asn"`
MyASN int `yaml:"my-asn"`
SystemDefaultRoute string `yaml:"system_default_route"`
}
IPV4Network is a type for managing IPv4 Networks
func (*IPV4Network) AddBiggestSubnet ¶
func (iNet *IPV4Network) AddBiggestSubnet( mask net.IPMask, name string, vlanID int16, ) ( *IPV4Subnet, error, )
AddBiggestSubnet allocates the largest subnet possible within the requested network and mask
func (*IPV4Network) AddSubnet ¶
func (iNet *IPV4Network) AddSubnet( mask net.IPMask, name string, vlanID int16, ) ( *IPV4Subnet, error, )
AddSubnet allocates a new subnet
func (*IPV4Network) AddSubnetbyCIDR ¶
func (iNet *IPV4Network) AddSubnetbyCIDR( desiredNet net.IPNet, name string, vlanID int16, ) ( *IPV4Subnet, error, )
AddSubnetbyCIDR allocates a new subnet
func (IPV4Network) AllocatedSubnets ¶
func (iNet IPV4Network) AllocatedSubnets() []net.IPNet
AllocatedSubnets returns a list of the allocated subnets
func (IPV4Network) AllocatedVlans ¶
func (iNet IPV4Network) AllocatedVlans() []int16
AllocatedVlans returns a list of all allocated vlan ids
func (*IPV4Network) ApplySupernetHack ¶
func (iNet *IPV4Network) ApplySupernetHack()
ApplySupernetHack applys a dirty hack.
func (*IPV4Network) GenSubnets ¶
func (iNet *IPV4Network) GenSubnets( cabinetDetails []sls.CabinetGroupDetail, mask net.IPMask, cabinetFilter sls.CabinetFilterFunc, ) error
GenSubnets subdivides a network into a set of subnets
func (*IPV4Network) LookUpSubnet ¶
func (iNet *IPV4Network) LookUpSubnet(name string) ( *IPV4Subnet, error, )
LookUpSubnet returns a subnet by name
func (IPV4Network) SubnetbyName ¶
func (iNet IPV4Network) SubnetbyName(name string) IPV4Subnet
SubnetbyName Return a copy of the subnet by name or a blank subnet if it doesn't exists
type IPV4Subnet ¶
type IPV4Subnet struct {
FullName string `yaml:"full_name" form:"full_name" mapstructure:"full_name"`
CIDR net.IPNet `yaml:"cidr"`
IPReservations []IPReservation `yaml:"ip_reservations"`
Name string `yaml:"name" form:"name" mapstructure:"name"`
NetName string `yaml:"net-name"`
VlanID int16 `yaml:"vlan_id" form:"vlan_id" mapstructure:"vlan_id"`
Comment string `yaml:"comment"`
Gateway net.IP `yaml:"gateway"`
PITServer net.IP `yaml:"_"`
DNSServer net.IP `yaml:"dns_server"`
DHCPStart net.IP `yaml:"iprange-start"`
DHCPEnd net.IP `yaml:"iprange-end"`
ReservationStart net.IP `yaml:"reservation-start"`
ReservationEnd net.IP `yaml:"reservation-end"`
MetalLBPoolName string `yaml:"metallb-pool-name"`
}
IPV4Subnet is a type for managing IPv4 Subnets
func (*IPV4Subnet) AddReservation ¶
func (iSubnet *IPV4Subnet) AddReservation(name, comment string) *IPReservation
AddReservation adds a new IP reservation to the subnet
func (*IPV4Subnet) AddReservationWithIP ¶
func (iSubnet *IPV4Subnet) AddReservationWithIP(name, addr, comment string) ( *IPReservation, error, )
AddReservationWithIP adds a reservation with a specific ip address
func (*IPV4Subnet) AddReservationWithPin ¶
func (iSubnet *IPV4Subnet) AddReservationWithPin( name, comment string, pin uint8, ) *IPReservation
AddReservationWithPin adds a new IPv4 reservation to the subnet with the last octet pinned
func (*IPV4Subnet) LookupReservation ¶
func (iSubnet *IPV4Subnet) LookupReservation(resName string) IPReservation
LookupReservation searches the subnet for an IPReservation that matches the name provided
func (*IPV4Subnet) ReservationsByName ¶
func (iSubnet *IPV4Subnet) ReservationsByName() map[string]IPReservation
ReservationsByName presents the IPReservations in a map by name
func (*IPV4Subnet) ReserveEdgeSwitchIPs ¶
func (iSubnet *IPV4Subnet) ReserveEdgeSwitchIPs(edges []string)
ReserveEdgeSwitchIPs reserves (n) IP addresses for edge switches
func (*IPV4Subnet) ReserveNetMgmtIPs ¶
func (iSubnet *IPV4Subnet) ReserveNetMgmtIPs( spines []string, leafs []string, leafbmcs []string, cdus []string, )
ReserveNetMgmtIPs reserves (n) IP addresses for management networking equipment
func (*IPV4Subnet) ReservedIPs ¶
func (iSubnet *IPV4Subnet) ReservedIPs() []net.IP
ReservedIPs returns a list of IPs already reserved within the subnet
func (*IPV4Subnet) TotalIPAddresses ¶
func (iSubnet *IPV4Subnet) TotalIPAddresses() int
TotalIPAddresses returns the number of ip addresses in a subnet see UsableHostAddresses
func (*IPV4Subnet) UpdateDHCPRange ¶
func (iSubnet *IPV4Subnet) UpdateDHCPRange(applySupernetHack bool)
UpdateDHCPRange resets the DHCPStart to exclude all IPReservations
func (*IPV4Subnet) UsableHostAddresses ¶
func (iSubnet *IPV4Subnet) UsableHostAddresses() int
UsableHostAddresses returns the number of usable ip addresses in a subnet
type ManagementSwitch ¶
type ManagementSwitch struct {
Xname string `json:"xname" mapstructure:"xname" csv:"Switch Xname"` // Required for SLS
Name string `json:"name" mapstructure:"name" csv:"-"` // Required for SLS to update DNS
Brand ManagementSwitchBrand `json:"brand" mapstructure:"brand" csv:"Brand"`
Model string `json:"model" mapstructure:"model" csv:"Model"`
Os string `json:"operating-system" mapstructure:"operating-system" csv:"-"`
Firmware string `json:"firmware" mapstructure:"firmware" csv:"-"`
SwitchType ManagementSwitchType `json:"type" mapstructure:"type" csv:"Type"` // "CDU/LeafBMC/Spine/Leaf/Edge"
ManagementInterface net.IP `json:"ip" mapstructure:"ip" csv:"-"` // SNMP/REST interface IP (not a distinct BMC) // Required for SLS
}
ManagementSwitch is a type for managing Management switches
func ReadSwitchCSV ¶
func ReadSwitchCSV(filename string) ([]*ManagementSwitch, error)
ReadSwitchCSV parses a CSV file into a list of ManagementSwitch structs
func (*ManagementSwitch) Normalize ¶
func (mySwitch *ManagementSwitch) Normalize() error
Normalize the values of a Management switch
func (*ManagementSwitch) Validate ¶
func (mySwitch *ManagementSwitch) Validate() error
Validate ManagementSwitch contents
type ManagementSwitchBrand ¶
type ManagementSwitchBrand string
ManagementSwitchBrand known list of Management switch brands
func (ManagementSwitchBrand) String ¶
func (msb ManagementSwitchBrand) String() string
type ManagementSwitchType ¶
type ManagementSwitchType string
ManagementSwitchType the type of management switch CDU/LeafBMC/Spine/Leaf/Edge
func (ManagementSwitchType) String ¶
func (mst ManagementSwitchType) String() string
type PinnedReservation ¶
PinnedReservation is a simple struct to work with our abomination of a PinnedMetalLBReservations