Clean up work around for host name filtering
authorKlaus Aehlig <aehlig@google.com>
Mon, 1 Jul 2013 15:03:46 +0000 (17:03 +0200)
committerKlaus Aehlig <aehlig@google.com>
Wed, 3 Jul 2013 07:16:39 +0000 (09:16 +0200)
These functions simply served as a work around to express
host name matching by regular expressions, instead of using
correct equality filter on host names that provides
the correct matching already.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

src/Ganeti/Query/Filter.hs

index bfc219e..ced50a9 100644 (file)
@@ -48,15 +48,12 @@ module Ganeti.Query.Filter
   ( compileFilter
   , evaluateFilter
   , requestedNames
-  , FilterConstructor
   , makeSimpleFilter
-  , makeHostnameFilter
   ) where
 
 import Control.Applicative
 import Control.Monad (liftM)
 import qualified Data.Map as Map
-import Data.Maybe (fromJust)
 import Data.Traversable (traverse)
 import Text.JSON (JSValue(..), fromJSString)
 import Text.JSON.Pretty (pp_value)
@@ -242,30 +239,8 @@ requestedNames namefield (EQFilter fld val) =
     else Nothing
 requestedNames _ _ = Nothing
 
-
-type FilterConstructor = String -> [Either String Integer] -> Filter FilterField
-  
 -- | Builds a simple filter from a list of names.
 makeSimpleFilter :: String -> [Either String Integer] -> Filter FilterField
 makeSimpleFilter _ [] = EmptyFilter
 makeSimpleFilter namefield vals =
   OrFilter $ map (EQFilter namefield . either QuotedString NumericValue) vals
-
--- | List of symbols with a special meaning for regular expressions.
-reSpecialSymbols :: String
-reSpecialSymbols = "\\.|()[]"
-
--- | Quote symbols that have special meaning in regular expressions.
-quoteForRegex :: String -> String
-quoteForRegex s = s >>= \x ->
-  if x `elem` reSpecialSymbols then ['\\', x] else [x]
-
--- | Builds a filter for hostnames from a list of names.
-makeHostnameFilter :: String -> [Either String Integer] -> Filter FilterField
-makeHostnameFilter _ [] = EmptyFilter
-makeHostnameFilter namefield vals = 
-  OrFilter . flip map vals
-  $ either  (RegexpFilter namefield . fromJust . mkRegex
-             . (\ s -> "^(" ++ s ++ "|" ++ s ++ "\\..*)$")
-             . quoteForRegex)
-            (EQFilter namefield  . NumericValue)