Files
cloud-ip-validator/internal/openstack/interface.go
T
ayurishchevandClaude Sonnet 5 582b44f314 Add Floating IP scanning and a durable address registry with configurable history depth
Adds POST /api/v1/admin/ips/scan (plus an optional periodic ticker) to
discover free Floating IPs in the OpenStack project and feed them straight
into the check queue. More importantly, decouples check/event history from
ip_queue's lifecycle: a new ip_registry table (migration 0007) gives every
address ever submitted a durable identity, so deleting it from the queue no
longer destroys its history — it's still reachable via the new
GET /api/v1/admin/registry[/{ip}] endpoints and the dashboard's /registry
pages, with retention depth configurable in check cycles per address
(history_retention_cycles, 0 = unlimited).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-23 09:52:01 +03:00

56 lines
2.3 KiB
Go

// Package openstack isolates all OpenStack/Neutron interaction behind a
// small interface, so the orchestrator's business logic can be unit tested
// without a real cloud, and so the real implementation is swappable for a
// mock via config alone.
package openstack
import "context"
type FloatingIP struct {
ID string
Address string
PortID string // empty when not associated to any port
ProjectID string
}
// FloatingIPClient is the only surface the orchestrator uses to manage
// Floating IPs. It intentionally does not expose allocation/deallocation —
// this tool only associates/disassociates pre-existing floating IPs with
// validator ports; returning an address to the customer-facing pool is an
// external business process out of scope here.
type FloatingIPClient interface {
// GetFloatingIPByAddress looks up the Neutron floating-ip resource for
// a given public address. Returns ErrNotFound if no such floating IP
// is registered in the service project.
GetFloatingIPByAddress(ctx context.Context, address string) (*FloatingIP, error)
// ListFloatingIPs returns every floating IP registered in the service
// project, both associated and free — filtering to the free pool (empty
// PortID) is the caller's job. Used to discover addresses to feed into
// the check queue without an admin having to enumerate them by hand.
ListFloatingIPs(ctx context.Context) ([]FloatingIP, error)
// AssociateFloatingIP attaches the floating IP to the given Neutron
// port (the validator's primary NIC port).
AssociateFloatingIP(ctx context.Context, fipID, portID string) error
// DisassociateFloatingIP detaches the floating IP from whatever port
// it's currently attached to, if any. Disassociating an already-free
// floating IP is a no-op, not an error.
DisassociateFloatingIP(ctx context.Context, fipID string) error
}
type notFoundError struct{ address string }
func (e *notFoundError) Error() string { return "floating ip not found: " + e.address }
// ErrNotFound wraps address into an error satisfying IsNotFound.
func ErrNotFound(address string) error { return &notFoundError{address} }
// IsNotFound reports whether err indicates the address has no matching
// Neutron floating-ip resource.
func IsNotFound(err error) bool {
_, ok := err.(*notFoundError)
return ok
}