Revision 68586d9e src/Ganeti/Config.hs

b/src/Ganeti/Config.hs
81 81
-- | Type alias for the link and ip map.
82 82
type LinkIpMap = M.Map String (M.Map String String)
83 83

  
84
-- | Type class denoting objects which have node parameters.
85
class NdParamObject a where
86
  getNdParamsOf :: ConfigData -> a -> Maybe FilledNDParams
84
-- * Operations on the whole configuration
87 85

  
88 86
-- | Reads the config file.
89 87
readConfig :: FilePath -> IO (Result String)
......
289 287
      ginsts = map (getNodeInstances cfg) gnodes in
290 288
  (concatMap fst ginsts, concatMap snd ginsts)
291 289

  
292
-- | Looks up a network. If looking up by uuid fails, we look up
293
-- by name.
294
getNetwork :: ConfigData -> String -> ErrorResult Network
295
getNetwork cfg name =
296
  let networks = fromContainer (configNetworks cfg)
297
  in case getItem "Network" name networks of
298
       Ok net -> Ok net
299
       Bad _ -> let by_name = M.mapKeys
300
                              (fromNonEmpty . networkName . (M.!) networks)
301
                              networks
302
                in getItem "Network" name by_name
303

  
304 290
-- | Retrieves the instance hypervisor params, missing values filled with
305 291
-- cluster defaults.
306 292
getFilledInstHvParams :: [String] -> ConfigData -> Instance -> HvParams
......
475 461
  let gparams = getGroupNdParams cfg group
476 462
  return $ fillNDParams gparams (nodeNdparams node)
477 463

  
464
-- * Network
465

  
466
-- | Looks up a network. If looking up by uuid fails, we look up
467
-- by name.
468
getNetwork :: ConfigData -> String -> ErrorResult Network
469
getNetwork cfg name =
470
  let networks = fromContainer (configNetworks cfg)
471
  in case getItem "Network" name networks of
472
       Ok net -> Ok net
473
       Bad _ -> let by_name = M.mapKeys
474
                              (fromNonEmpty . networkName . (M.!) networks)
475
                              networks
476
                in getItem "Network" name by_name
477

  
478
-- * ND params
479

  
480
-- | Type class denoting objects which have node parameters.
481
class NdParamObject a where
482
  getNdParamsOf :: ConfigData -> a -> Maybe FilledNDParams
483

  
478 484
instance NdParamObject Node where
479 485
  getNdParamsOf = getNodeNdParams
480 486

  

Also available in: Unified diff