sl

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package sl wraps the SoftLayer API for managing IP notes and PTR records.

Index

Constants

This section is empty.

Variables

View Source
var DefaultListExcludeNotes = []string{
	"ONLY FOR METAL",
	"FULL",
	"NETWORK FOR INFOSEC",
}

DefaultListExcludeNotes are subnet notes skipped by list and lease unless overridden on the command line.

View Source
var DefaultStaleExcludeNotes = []string{
	"ONLY FOR METAL",
	"NETWORK FOR INFOSEC",
}

DefaultStaleExcludeNotes are subnet notes skipped by stale. FULL subnets are kept: dead IPs there are exactly what we want to find.

View Source
var ErrPTRNotFound = errors.New("PTR record not found")

ErrPTRNotFound is returned when an IP has no matching PTR record.

Functions

func FirstFree

func FirstFree(subnets []SubnetInfo) (SubnetInfo, IPInfo, bool)

FirstFree returns the first free IP across the given subnets along with its subnet, or ok=false when everything is taken.

func IsPrivateIP

func IsPrivateIP(ip string) bool

IsPrivateIP reports whether the address belongs to a private range (RFC 1918: 10/8, 172.16/12, 192.168/16).

func ResolveExcludeNotes

func ResolveExcludeNotes(opts ListOpts, defaults []string) []string

ResolveExcludeNotes returns the subnet-note exclusions to send to the API.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a thin wrapper around the SoftLayer API session.

func NewClientFromEnv

func NewClientFromEnv() (*Client, error)

NewClientFromEnv builds a Client using SL_USER / SL_APIKEY credentials.

func (*Client) DeletePTR

DeletePTR removes the PTR record of an IP. Deleting a missing record is reported via ErrPTRNotFound so callers can treat it as a no-op.

func (*Client) GetNote

func (c *Client) GetNote(ip string) (string, error)

GetNote returns the current note of an IP address.

func (*Client) GetPTR

GetPTR returns the PTR record for the given IP, or ErrPTRNotFound.

func (*Client) ListSubnets

func (c *Client) ListSubnets(opts ListOpts) ([]SubnetInfo, error)

ListSubnets returns account subnets with their IPs, PTRs and notes.

func (*Client) SetNote

func (c *Client) SetNote(ip, note string) error

SetNote updates the note attached to an IP address.

func (*Client) SetPTR

func (c *Client) SetPTR(ip, ptr string, ttl int) (datatypes.Dns_Domain_ResourceRecord, error)

SetPTR creates (or replaces) the PTR record for an IP.

func (*Client) StaleIPs

func (c *Client) StaleIPs(opts ListOpts) ([]IPInfo, error)

StaleIPs returns public IP addresses that do not answer pings.

type IPInfo

type IPInfo struct {
	IP   string `json:"ip"`
	PTR  string `json:"ptr,omitempty"`
	Note string `json:"note,omitempty"`
	Free bool   `json:"free"`
}

IPInfo describes a single usable IP address inside a subnet.

type ListOpts

type ListOpts struct {
	IncludePublic     bool
	IncludePrivate    bool
	ExcludeNotes      []string // merged with defaults unless NoDefaultExcludes
	ExcludeCIDRs      []string // applied after the API call
	NoDefaultExcludes bool
	WithPTRs          bool
}

ListOpts controls subnet listing and search commands.

type SubnetInfo

type SubnetInfo struct {
	ID       int      `json:"id"`
	CIDR     string   `json:"cidr"`
	MaskBits int      `json:"mask_bits"`
	Gateway  string   `json:"gateway,omitempty"`
	Private  bool     `json:"private"`
	IPs      []IPInfo `json:"ips"`
}

SubnetInfo describes a subnet together with its usable IP addresses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL