Commit 2a050e19 authored by Petr Pudlak's avatar Petr Pudlak

Fix the computation of the list of reserved IP addresses

After refactoring the code for network addresses to Haskell, a
regression appeared that added 30 to all IP addresses in the generated
list. Since the code for generating the list used just 'show' and look
for 0s and 1s in the string (and treating anything else as 0), it turned
out that after adding a separate type for address pools, the strings

    "AddressPool {apReservations = ...}"

and the initial part of the string was exactly the mysterious 30

This fix replaces this by switching to correct types and iterating over
the bits in BitArray.

Fixes #1068.
Signed-off-by: default avatarPetr Pudlak <>
Reviewed-by: default avatarKlaus Aehlig <>
parent 124cc7e9
......@@ -44,11 +44,12 @@ module Ganeti.Query.Network
import qualified Data.Map as Map
import Data.Maybe (fromMaybe, mapMaybe)
import Data.List (find, foldl', intercalate)
import Data.List (find, intercalate)
import Ganeti.JSON
import Ganeti.Network
import Ganeti.Objects
import qualified Ganeti.Objects.BitArray as BA
import Ganeti.Query.Language
import Ganeti.Query.Common
import Ganeti.Query.Types
......@@ -165,24 +166,17 @@ getNetworkUuid cfg name =
-- | Computes the reservations list for a network.
-- This doesn't use the netmask for validation of the length, instead
-- simply iterating over the reservations string.
getReservations :: Ip4Network -> String -> [Ip4Address]
getReservations net =
reverse .
fst .
foldl' (\(accu, addr) c ->
let addr' = nextIp4Address addr
accu' = case c of
'1' -> addr:accu
'0' -> accu
_ -> -- FIXME: the reservations string
-- should be a proper type
in (accu', addr')) ([], ip4netAddr net)
-- simply iterating over the reservations.
getReservations :: Ip4Network -> Maybe AddressPool -> [Ip4Address]
getReservations _ Nothing = []
getReservations net (Just pool) =
map snd . filter fst
$ zip (BA.toList . apReservations $ pool)
(iterate nextIp4Address $ ip4netAddr net)
-- | Computes the external reservations as string for a network.
getExtReservationsString :: Network -> ResultEntry
getExtReservationsString net =
let addrs = getReservations (networkNetwork net)
(maybe "" show $ networkExtReservations net)
(networkExtReservations net)
in rsNormal . intercalate ", " $ map show addrs
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment