Persist Floating IP UUIDs for direct Neutron operations

This commit is contained in:
ayurishchev committed 2026-11-22 21:26:19 +03:00
1 parent 89ac4d5bcd
commit 94124747ce
24 files changed
+918 -116

No files matched your search

+32 -4
View File
@@ -49,8 +49,7 @@ type ScanOptions struct {
// ClearFirst clears the whole queue before scanning (auto-cycle step 1).
// Ignored together with DryRun: a dry run never touches the queue.
ClearFirst bool
// DryRun only discovers and counts the free floating IPs; the queue is
// left untouched.
// DryRun only discovers and counts the free floating IPs.
DryRun bool
}
@@ -232,7 +231,7 @@ func (o *Orchestrator) runScan(ctx context.Context, run *scanRun, opts ScanOptio
}
// doScan is the scan algorithm: optional clear -> read every page into memory
// -> sort -> (unless dry run) enqueue in chunks -> one fip_scan event.
// -> sort -> (unless dry run) save mappings and enqueue in chunks -> one fip_scan event.
func (o *Orchestrator) doScan(ctx context.Context, opts ScanOptions) (scanResult, error) {
j := &o.scan
var res scanResult
@@ -247,11 +246,27 @@ func (o *Orchestrator) doScan(ctx context.Context, opts ScanOptions) (scanResult
// Read everything first: a read error after retries must leave the queue
// untouched, so nothing is enqueued until discovery is complete.
var free []string
var observed map[string]string
if !opts.DryRun {
observed = make(map[string]string)
}
seen := map[string]struct{}{}
start := time.Now()
pages, err := o.OS.ListFreeFloatingIPs(ctx, o.ScanPageSize, func(page []openstack.FloatingIP) error {
nFree := 0
for _, f := range page {
if f.PortID != "" || f.Address == "" {
if f.Address == "" || !o.matchesFloatingIP(&f, f.Address) {
continue
}
if !opts.DryRun {
if id, exists := observed[f.Address]; !exists {
observed[f.Address] = f.ID
} else if id != f.ID {
// A later listing by address could not choose one either.
observed[f.Address] = ""
}
}
if f.PortID != "" {
continue
}
if _, dup := seen[f.Address]; dup {
@@ -275,6 +290,19 @@ func (o *Orchestrator) doScan(ctx context.Context, opts ScanOptions) (scanResult
res.free = len(free)
sortAddressesAscending(free)
var mappings []db.FloatingIPMapping
for address, id := range observed {
if id != "" {
mappings = append(mappings, db.FloatingIPMapping{Address: address, FIPID: id})
}
}
for off := 0; off < len(mappings); off += scanChunkSize {
chunk := mappings[off:min(off+scanChunkSize, len(mappings))]
if err := o.DB.ConfirmFloatingIPs(ctx, o.FIPScope, chunk, start); err != nil {
return res, fmt.Errorf("save scanned floating ips: %w", err)
}
}
if !opts.DryRun && len(free) > 0 {
j.update(func(s *ScanStatus) { s.State = ScanEnqueuing })
for off := 0; off < len(free); off += scanChunkSize {