diff --git a/web/app/Models/CloudPublicIp.php b/web/app/Models/CloudPublicIp.php index d2aff695..d30545e5 100644 --- a/web/app/Models/CloudPublicIp.php +++ b/web/app/Models/CloudPublicIp.php @@ -11,6 +11,7 @@ final class CloudPublicIp extends Model 'id' => 'int', 'host_id' => 'int', 'public_ip_pool_id' => 'int', + 'address_family' => 'int', 'prefix_length' => 'int', 'reservation_id' => 'int', 'instance_id' => 'int', diff --git a/web/app/Models/CloudPublicIpPool.php b/web/app/Models/CloudPublicIpPool.php index a63fa03b..05f6a1bc 100644 --- a/web/app/Models/CloudPublicIpPool.php +++ b/web/app/Models/CloudPublicIpPool.php @@ -11,7 +11,10 @@ final class CloudPublicIpPool extends Model 'id' => 'int', 'host_id' => 'int', 'network_attachment_id' => 'int', + 'address_family' => 'int', + 'gateway_on_link' => 'bool', 'guest_prefix_length' => 'int', + 'max_allocations' => 'int', 'priority' => 'int', 'desired_revision' => 'int', 'observed_revision' => 'int', diff --git a/web/app/Models/CloudResourceReservationIp.php b/web/app/Models/CloudResourceReservationIp.php new file mode 100644 index 00000000..ceb34722 --- /dev/null +++ b/web/app/Models/CloudResourceReservationIp.php @@ -0,0 +1,21 @@ + 'int', + 'reservation_id' => 'int', + 'address_family' => 'int', + 'network_attachment_id' => 'int', + 'public_ip_pool_id' => 'int', + 'public_ip_id' => 'int', + 'released_at' => 'int', + 'created_at' => 'int', + 'updated_at' => 'int', + ]; +} diff --git a/web/sql/cloud.sql b/web/sql/cloud.sql index d16d3fe6..262c7f2e 100644 --- a/web/sql/cloud.sql +++ b/web/sql/cloud.sql @@ -259,12 +259,18 @@ CREATE TABLE cloud_public_ip_pools ( pool_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, host_id BIGINT UNSIGNED NOT NULL, network_attachment_id BIGINT UNSIGNED NOT NULL, + address_family TINYINT UNSIGNED NOT NULL, name VARCHAR(80) NOT NULL, - cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, - gateway VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + cidr VARCHAR(49) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + gateway VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + gateway_on_link TINYINT UNSIGNED NOT NULL DEFAULT 0, guest_prefix_length TINYINT UNSIGNED NOT NULL, dns_servers_json TEXT NOT NULL, reserved_ips_json TEXT NOT NULL, + allocation_start VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL, + allocation_end VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL, + allocation_cursor VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL, + max_allocations INT UNSIGNED NOT NULL DEFAULT 0, state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'active', priority INT NOT NULL DEFAULT 0, desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1, @@ -274,9 +280,30 @@ CREATE TABLE cloud_public_ip_pools ( created_at BIGINT UNSIGNED NOT NULL, updated_at BIGINT UNSIGNED NOT NULL, UNIQUE KEY cloud_public_ip_pool_key (host_id, pool_key), - UNIQUE KEY cloud_public_ip_pool_cidr (host_id, cidr), - KEY cloud_public_ip_pool_attachment (network_attachment_id, state, priority, id), - KEY cloud_public_ip_pool_sync (host_id, sync_state, updated_at, id) + UNIQUE KEY cloud_public_ip_pool_cidr (host_id, address_family, cidr), + KEY cloud_public_ip_pool_attachment (network_attachment_id, address_family, state, priority, id), + KEY cloud_public_ip_pool_sync (host_id, sync_state, updated_at, id), + CONSTRAINT chk_cloud_public_ip_pool_family CHECK ( + address_family IN (4,6) + ), + CONSTRAINT chk_cloud_public_ip_pool_prefix CHECK ( + (address_family = 4 AND guest_prefix_length BETWEEN 1 AND 30) + OR (address_family = 6 AND guest_prefix_length BETWEEN 1 AND 120) + ), + CONSTRAINT chk_cloud_public_ip_pool_gateway CHECK ( + gateway_on_link IN (0,1) + ), + CONSTRAINT chk_cloud_public_ip_pool_allocation CHECK ( + (address_family = 4 + AND allocation_start IS NULL + AND allocation_end IS NULL + AND allocation_cursor IS NULL + AND max_allocations = 0) + OR (address_family = 6 + AND allocation_start IS NOT NULL + AND allocation_end IS NOT NULL + AND max_allocations >= 1) + ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Operator limits and safety reserves are authoritative scheduling policy. @@ -302,7 +329,9 @@ CREATE TABLE cloud_public_ips ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, host_id BIGINT UNSIGNED NOT NULL, public_ip_pool_id BIGINT UNSIGNED DEFAULT NULL, + address_family TINYINT UNSIGNED NOT NULL, address VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + address_binary VARBINARY(16) NOT NULL, prefix_length TINYINT UNSIGNED NOT NULL, state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'available', reservation_id BIGINT UNSIGNED DEFAULT NULL, @@ -310,12 +339,19 @@ CREATE TABLE cloud_public_ips ( operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL, created_at BIGINT UNSIGNED NOT NULL, updated_at BIGINT UNSIGNED NOT NULL, - UNIQUE KEY cloud_public_ip_address (address), - KEY cloud_public_ip_available (host_id, state, id), + UNIQUE KEY cloud_public_ip_address (address_family, address_binary), + KEY cloud_public_ip_available (host_id, address_family, state, id), KEY cloud_public_ip_pool_available (public_ip_pool_id, state, id), - UNIQUE KEY cloud_public_ip_reservation (reservation_id), + UNIQUE KEY cloud_public_ip_reservation (reservation_id, address_family), KEY cloud_public_ip_instance (instance_id), - UNIQUE KEY cloud_public_ip_operation (operation_id) + UNIQUE KEY cloud_public_ip_operation (operation_id, address_family), + CONSTRAINT chk_cloud_public_ip_family CHECK ( + address_family IN (4,6) + ), + CONSTRAINT chk_cloud_public_ip_prefix CHECK ( + (address_family = 4 AND prefix_length BETWEEN 1 AND 30) + OR (address_family = 6 AND prefix_length BETWEEN 1 AND 120) + ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- An administrator public-pool replacement is one durable orchestration @@ -1380,6 +1416,39 @@ CREATE TABLE cloud_resource_reservations ( OR (order_id IS NULL AND backup_restore_id IS NOT NULL AND offer_id IS NULL) ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +-- One resource reservation owns one address in each required family. Claims +-- are retained after release so reconciliation can prove which exact bundle +-- an operation held without overloading nullable columns on the reservation. +CREATE TABLE cloud_resource_reservation_ips ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + reservation_id BIGINT UNSIGNED NOT NULL, + address_family TINYINT UNSIGNED NOT NULL, + network_attachment_id BIGINT UNSIGNED NOT NULL, + public_ip_pool_id BIGINT UNSIGNED NOT NULL, + public_ip_id BIGINT UNSIGNED NOT NULL, + operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'reserved', + released_at BIGINT UNSIGNED DEFAULT NULL, + release_reason VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '', + created_at BIGINT UNSIGNED NOT NULL, + updated_at BIGINT UNSIGNED NOT NULL, + UNIQUE KEY cloud_reservation_ip_family (reservation_id, address_family), + UNIQUE KEY cloud_reservation_ip_operation (operation_id, address_family), + KEY cloud_reservation_ip_address (public_ip_id, state, id), + KEY cloud_reservation_ip_pool (public_ip_pool_id, state, id), + KEY cloud_reservation_ip_attachment (network_attachment_id, state, id), + CONSTRAINT chk_cloud_reservation_ip_family CHECK ( + address_family IN (4,6) + ), + CONSTRAINT chk_cloud_reservation_ip_state CHECK ( + state IN ('reserved','committed','uncertain','released') + ), + CONSTRAINT chk_cloud_reservation_ip_release CHECK ( + (state = 'released' AND released_at IS NOT NULL AND release_reason <> '') + OR (state <> 'released' AND released_at IS NULL AND release_reason = '') + ) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE cloud_service_periods ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, instance_id BIGINT UNSIGNED NOT NULL, diff --git a/web/tests/CloudDualStackPublicNetworkSchemaTest.php b/web/tests/CloudDualStackPublicNetworkSchemaTest.php new file mode 100644 index 00000000..f00b79d7 --- /dev/null +++ b/web/tests/CloudDualStackPublicNetworkSchemaTest.php @@ -0,0 +1,102 @@ + 'int'") + && str_contains($poolModel, "'gateway_on_link' => 'bool'") + && str_contains($poolModel, "'max_allocations' => 'int'"), + 'Public pool model does not expose canonical dual-stack casts.'); +$assert(is_string($ipModel) + && str_contains($ipModel, "'address_family' => 'int'"), + 'Public IP model does not expose its address family.'); +$assert(is_string($claimModel) + && str_contains($claimModel, + "protected \$table = 'cloud_resource_reservation_ips';") + && str_contains($claimModel, "'address_family' => 'int'"), + 'Reservation address-claim model is missing.'); + +echo "Dual-stack public-network schema tests passed.\n"; diff --git a/web/tests/CloudMultiHostSchemaDefinitionTest.php b/web/tests/CloudMultiHostSchemaDefinitionTest.php index 293c7732..d8df725f 100644 --- a/web/tests/CloudMultiHostSchemaDefinitionTest.php +++ b/web/tests/CloudMultiHostSchemaDefinitionTest.php @@ -65,13 +65,17 @@ $assert(str_contains($schema, 'configured_cpu_cores') && str_contains($schema, "state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'held'"), 'Panel scheduling policy and reservation-ledger capacity fields are incomplete.'); -$assert(str_contains($schema, 'UNIQUE KEY cloud_public_ip_address (address)') - && str_contains($schema, 'cloud_public_ip_available (host_id, state, id)') +$assert(str_contains($schema, + 'UNIQUE KEY cloud_public_ip_address (address_family, address_binary)') + && str_contains($schema, + 'cloud_public_ip_available (host_id, address_family, state, id)') && str_contains($schema, 'operation_id CHAR(32)') && str_contains($schema, - 'UNIQUE KEY cloud_public_ip_reservation (reservation_id)') + 'UNIQUE KEY cloud_public_ip_reservation (reservation_id, address_family)') + && str_contains($schema, + 'UNIQUE KEY cloud_public_ip_operation (operation_id, address_family)') && str_contains($schema, - 'UNIQUE KEY cloud_public_ip_operation (operation_id)') + 'UNIQUE KEY cloud_reservation_ip_family (reservation_id, address_family)') && str_contains($schema, 'UNIQUE KEY cloud_resource_reservation_operation (operation_id)') && str_contains($schema, 'public_ip_id BIGINT UNSIGNED DEFAULT NULL'),