Revision e78a8c0b src/Ganeti/Query/Node.hs

b/src/Ganeti/Query/Node.hs
80 80
     "Total amount of memory of physical machine")
81 81
  ]
82 82

  
83
-- | Helper function to extract an attribute from a maybe StorageType
84
getAttrFromStorageInfo :: (J.JSON a) => (StorageInfo -> Maybe a)
85
                       -> Maybe StorageInfo -> J.JSValue
86
getAttrFromStorageInfo attr_fn (Just info) =
87
  case attr_fn info of
88
    Just val -> J.showJSON val
89
    Nothing -> J.JSNull
90
getAttrFromStorageInfo _ Nothing = J.JSNull
91

  
92
-- | Check whether the given storage info fits to the given storage type
93
isStorageInfoOfType :: StorageType -> StorageInfo -> Bool
94
isStorageInfoOfType stype sinfo = storageInfoType sinfo ==
95
    storageTypeToRaw stype
96

  
97
-- | Get storage info for the default storage unit
98
getStorageInfoForDefault :: [StorageInfo] -> Maybe StorageInfo
99
getStorageInfoForDefault sinfos = listToMaybe $ filter
100
    (not . isStorageInfoOfType StorageLvmPv) sinfos
101

  
102
-- | Gets the storage info for a storage type
103
-- FIXME: This needs to be extended when storage pools are implemented,
104
-- because storage types are not necessarily unique then
105
getStorageInfoForType :: [StorageInfo] -> StorageType -> Maybe StorageInfo
106
getStorageInfoForType sinfos stype = listToMaybe $ filter
107
    (isStorageInfoOfType stype) sinfos
108

  
83 109
-- | Map each name to a function that extracts that value from
84 110
-- the RPC result.
85 111
nodeLiveFieldExtract :: FieldName -> RpcResultNodeInfo -> J.JSValue
......
94 120
nodeLiveFieldExtract "ctotal" res =
95 121
  jsonHead (rpcResNodeInfoHvInfo res) hvInfoCpuTotal
96 122
nodeLiveFieldExtract "dfree" res =
97
  getMaybeJsonHead (rpcResNodeInfoStorageInfo res) storageInfoStorageFree
123
  getAttrFromStorageInfo storageInfoStorageFree (getStorageInfoForDefault
124
      (rpcResNodeInfoStorageInfo res))
98 125
nodeLiveFieldExtract "dtotal" res =
99
  getMaybeJsonHead (rpcResNodeInfoStorageInfo res) storageInfoStorageSize
126
  getAttrFromStorageInfo storageInfoStorageSize (getStorageInfoForDefault
127
      (rpcResNodeInfoStorageInfo res))
100 128
nodeLiveFieldExtract "spfree" res =
101
  getMaybeJsonElem (rpcResNodeInfoStorageInfo res) 1 storageInfoStorageFree
129
  getAttrFromStorageInfo storageInfoStorageFree (getStorageInfoForType
130
      (rpcResNodeInfoStorageInfo res) StorageLvmPv)
102 131
nodeLiveFieldExtract "sptotal" res =
103
  getMaybeJsonElem (rpcResNodeInfoStorageInfo res) 1 storageInfoStorageSize
132
  getAttrFromStorageInfo storageInfoStorageSize (getStorageInfoForType
133
      (rpcResNodeInfoStorageInfo res) StorageLvmPv)
104 134
nodeLiveFieldExtract "mfree" res =
105 135
  jsonHead (rpcResNodeInfoHvInfo res) hvInfoMemoryFree
106 136
nodeLiveFieldExtract "mnode" res =
......
244 274
collectLiveData True cfg nodes = do
245 275
  let hvs = [getDefaultHypervisorSpec cfg]
246 276
      good_nodes = nodesWithValidConfig cfg nodes
277
      -- FIXME: use storage units from calling code
247 278
      storage_units = getStorageUnitsOfNodes cfg good_nodes
248 279
  rpcres <- executeRpcCall good_nodes (RpcCallNodeInfo storage_units hvs)
249 280
  return $ fillUpList (fillPairFromMaybe rpcResultNodeBroken pickPairUnique)

Also available in: Unified diff