50 lines
1.9 KiB
Go
50 lines
1.9 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)
|
|
|
|
// 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 ¬FoundError{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
|
|
}
|