Revision 4e6f1cde src/Ganeti/Query/Common.hs

b/src/Ganeti/Query/Common.hs
40 40
  , tagsFields
41 41
  , dictFieldGetter
42 42
  , buildNdParamField
43
  , buildBeParamField
44
  , buildHvParamField
43 45
  , getDefaultHypervisorSpec
44 46
  , getHvParamsFromCluster
45 47
  ) where
......
183 185

  
184 186
-- | Builds the ndparam fields for an object.
185 187
buildNdParamField :: (NdParamObject a) => String -> FieldData a b
186
buildNdParamField field =
187
  let full_name = "ndp/" ++ field
188
      title = fromMaybe field $ field `Map.lookup` ndParamTitles
189
      qft = fromMaybe QFTOther $ field `Map.lookup` ndParamTypes
190
      desc = "The \"" ++ field ++ "\" node parameter"
191
  in (FieldDefinition full_name title qft desc,
192
      FieldConfig (ndParamGetter field), QffNormal)
188
buildNdParamField =
189
  buildParamField "ndp" "node" ndParamTitles ndParamTypes ndParamGetter
190

  
191
-- | Beparams optimised lookup map.
192
beParamTypes :: Map.Map String FieldType
193
beParamTypes = Map.map vTypeToQFT C.besParameterTypes
194

  
195
-- | Builds the beparam fields for an object.
196
buildBeParamField :: (String -> ConfigData -> a -> ResultEntry)
197
                  -> String
198
                  -> FieldData a b
199
buildBeParamField =
200
  buildParamField "be" "backend" C.besParameterTitles beParamTypes
201

  
202
-- | Hvparams optimised lookup map.
203
hvParamTypes :: Map.Map String FieldType
204
hvParamTypes = Map.map vTypeToQFT C.hvsParameterTypes
205

  
206
-- | Builds the beparam fields for an object.
207
buildHvParamField :: (String -> ConfigData -> a -> ResultEntry)
208
                  -> String
209
                  -> FieldData a b
210
buildHvParamField =
211
  buildParamField "hv" "hypervisor" C.hvsParameterTitles hvParamTypes
212

  
213
-- | Builds a param field for a certain getter class
214
buildParamField :: String -- ^ Prefix
215
                -> String -- ^ Parameter group name
216
                -> Map.Map String String -- ^ Parameter title map
217
                -> Map.Map String FieldType -- ^ Parameter type map
218
                -> (String -> ConfigData -> a -> ResultEntry)
219
                -> String -- ^ The parameter name
220
                -> FieldData a b
221
buildParamField prefix paramGroupName titleMap typeMap getter field =
222
  let full_name = prefix ++ "/" ++ field
223
      title = fromMaybe full_name $ field `Map.lookup` titleMap
224
      qft = fromMaybe QFTOther $ field `Map.lookup` typeMap
225
      desc = "The \"" ++ field ++ "\" " ++ paramGroupName ++ " parameter"
226
  in ( FieldDefinition full_name title qft desc
227
     , FieldConfig (getter field), QffNormal
228
     )
193 229

  
194 230
-- | Looks up the default hypervisor and its hvparams
195 231
getDefaultHypervisorSpec :: ConfigData -> (Hypervisor, HvParams)

Also available in: Unified diff