Persist Floating IP UUIDs for direct Neutron operations
This commit is contained in:
1 parent
89ac4d5bcd
commit
94124747ce
24 files changed
+918
-116
No files matched your search
@@ -0,0 +1,55 @@
|
||||
CREATE TABLE floating_ip_mappings (
|
||||
project_id TEXT NOT NULL,
|
||||
region TEXT NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
fip_id TEXT NOT NULL,
|
||||
confirmed_at INTEGER NOT NULL, -- Unix nanoseconds
|
||||
PRIMARY KEY (project_id, region, address)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
-- Older records had no project or region. Use them as hints until Neutron
|
||||
-- has confirmed the address and its ownership in the configured scope.
|
||||
CREATE TABLE floating_ip_legacy_candidates (
|
||||
address TEXT PRIMARY KEY,
|
||||
fip_id TEXT NOT NULL
|
||||
) WITHOUT ROWID;
|
||||
|
||||
WITH relevant_events AS (
|
||||
SELECT e.id, e.occurred_at, e.event_type, r.ip_address,
|
||||
CASE WHEN json_valid(e.payload) THEN e.payload ELSE '{}' END AS payload
|
||||
FROM events e
|
||||
LEFT JOIN ip_registry r ON r.id = e.registry_id
|
||||
WHERE e.event_type IN ('fip_associated', 'fip_occupied', 'diagnostic_attached', 'diagnostic_detached')
|
||||
), candidates AS (
|
||||
SELECT ip_address AS address, fip_id, COALESCE(fip_associated_at, updated_at) AS observed_at, 3 AS source, id
|
||||
FROM ip_queue
|
||||
WHERE fip_id <> ''
|
||||
UNION ALL
|
||||
SELECT address, fip_id, created_at, 4, id FROM diagnostic_holds WHERE fip_id <> ''
|
||||
UNION ALL
|
||||
SELECT i.address, i.fip_id, o.created_at, 2, i.id
|
||||
FROM diagnostic_operation_items i
|
||||
JOIN diagnostic_operations o ON o.id = i.operation_id
|
||||
WHERE i.fip_id <> ''
|
||||
UNION ALL
|
||||
SELECT CASE WHEN event_type IN ('diagnostic_attached', 'diagnostic_detached')
|
||||
THEN json_extract(payload, '$.address') ELSE ip_address END,
|
||||
json_extract(payload, '$.fip_id'), occurred_at, 1, id
|
||||
FROM relevant_events
|
||||
WHERE json_type(payload, '$.fip_id') = 'text'
|
||||
), ranked AS (
|
||||
SELECT address, fip_id, ROW_NUMBER() OVER (
|
||||
PARTITION BY address ORDER BY julianday(observed_at) DESC, source DESC, id DESC
|
||||
) AS rank
|
||||
FROM candidates
|
||||
WHERE typeof(address) = 'text' AND address <> '' AND fip_id <> ''
|
||||
)
|
||||
INSERT INTO floating_ip_legacy_candidates (address, fip_id)
|
||||
SELECT address, fip_id FROM ranked WHERE rank = 1;
|
||||
|
||||
ALTER TABLE diagnostic_holds ADD COLUMN port_id TEXT NOT NULL DEFAULT '';
|
||||
|
||||
-- Pending holds already have an exact link to their reserved port.
|
||||
UPDATE diagnostic_holds
|
||||
SET port_id = COALESCE((SELECT port_id FROM diagnostic_operation_items WHERE id = pending_item_id), '')
|
||||
WHERE pending_item_id IS NOT NULL;
|
||||
Reference in new issue
Block a user