diff --git a/app/Http/Controllers/Admin/AddressPools/AddressController.php b/app/Http/Controllers/Admin/AddressPools/AddressController.php index e24e8ed4732..7d26c11a253 100644 --- a/app/Http/Controllers/Admin/AddressPools/AddressController.php +++ b/app/Http/Controllers/Admin/AddressPools/AddressController.php @@ -63,7 +63,7 @@ public function store(StoreAddressRequest $request, AddressPool $addressPool) ]; } - + } else { diff --git a/app/Http/Controllers/Admin/Nodes/NodeController.php b/app/Http/Controllers/Admin/Nodes/NodeController.php index b1fc0bb2b2b..9620b4e5515 100644 --- a/app/Http/Controllers/Admin/Nodes/NodeController.php +++ b/app/Http/Controllers/Admin/Nodes/NodeController.php @@ -28,7 +28,10 @@ public function index(Request $request) $nodes = QueryBuilder::for(Node::query()) ->withCount(['servers']) ->allowedFilters( - [AllowedFilter::exact('id'), 'name', 'fqdn', AllowedFilter::exact('location_id'), AllowedFilter::custom('*', new FiltersNode)], + [AllowedFilter::exact('id'), 'name', 'fqdn', AllowedFilter::exact('location_id'), AllowedFilter::custom( + '*', + new FiltersNode, + )], ) ->paginate(min($request->query('per_page', 50), 100))->appends($request->query()); diff --git a/app/Repositories/Eloquent/AddressRepository.php b/app/Repositories/Eloquent/AddressRepository.php new file mode 100644 index 00000000000..cc882b17801 --- /dev/null +++ b/app/Repositories/Eloquent/AddressRepository.php @@ -0,0 +1,118 @@ + $addressPoolId, + 'address_pool_id_2' => $addressPoolId, + 'server_id' => $serverId, + 'type' => AddressType::IPV4->value, + 'starting_address' => $startingAddress, + 'ending_address' => $endingAddress, + 'cidr' => $cidr, + 'gateway' => $gateway, + 'mac_address' => $macAddress, + ], + ); + } + + public function createIPv6AddressesInBulk( + string $startingAddress, + string $endingAddress, + int $addressPoolId, + ?int $serverId, + int $cidr, + string $gateway, + ?string $macAddress, + ): void + { + $query = <<<'SQL' + INSERT INTO ip_addresses (address_pool_id, server_id, type, address, cidr, gateway, mac_address, created_at) + WITH RECURSIVE ips_to_insert AS ( + SELECT INET6_NTOA(INET6_ATON(:starting_address)) AS ip + UNION ALL + SELECT INET6_NTOA(INE6T_ATON(ip) + 1) + FROM ips_to_insert + WHERE INET6_ATON(ip) < INET6_ATON(:ending_address) + ) + SELECT + :address_pool_id AS address_pool_id, + :server_id AS server_id, + :type AS type, + r.ip AS address, + :cidr AS cidr, + :gateway AS gateway, + :mac_address AS mac_address, + NOW() as created_at + FROM ips_to_insert AS r + LEFT JOIN ip_addresses AS existing_ips_in_pool + ON r.ip = existing_ips_in_pool.address + AND existing_ips_in_pool.address_pool_id = :address_pool_id_2 + WHERE existing_ips_in_pool.address IS NULL; + SQL; + + DB::select( + $query, + [ + 'address_pool_id' => $addressPoolId, + 'address_pool_id_2' => $addressPoolId, + 'server_id' => $serverId, + 'type' => AddressType::IPV4->value, + 'starting_address' => $startingAddress, + 'ending_address' => $endingAddress, + 'cidr' => $cidr, + 'gateway' => $gateway, + 'mac_address' => $macAddress, + ], + ); + } +} \ No newline at end of file diff --git a/database/migrations/2023_09_03_174812_move_types_column_in_ip_addresses_table.php b/database/migrations/2023_09_03_174812_move_types_column_in_ip_addresses_table.php new file mode 100644 index 00000000000..db9139ba82d --- /dev/null +++ b/database/migrations/2023_09_03_174812_move_types_column_in_ip_addresses_table.php @@ -0,0 +1,24 @@ +