Revision 1a0dacf6
b/src/Ganeti/Confd/Server.hs | ||
---|---|---|
186 | 186 |
PlainQuery str -> return str |
187 | 187 |
_ -> fail $ "Invalid query type " ++ show (confdRqQuery req) |
188 | 188 |
node <- gntErrorToResult $ getNode cfg node_name |
189 |
let minors = concatMap (getInstMinorsForNode (nodeName node)) . |
|
189 |
let minors = concatMap (getInstMinorsForNode cfg (nodeName node)) .
|
|
190 | 190 |
M.elems . fromContainer . configInstances $ cfg |
191 | 191 |
encoded = [J.JSArray [J.showJSON a, J.showJSON b, J.showJSON c, |
192 | 192 |
J.showJSON d, J.showJSON e, J.showJSON f] | |
b/src/Ganeti/Config.hs | ||
---|---|---|
47 | 47 |
, getInstPrimaryNode |
48 | 48 |
, getInstMinorsForNode |
49 | 49 |
, getInstAllNodes |
50 |
, getInstDisks |
|
50 | 51 |
, getFilledInstHvParams |
51 | 52 |
, getFilledInstBeParams |
52 | 53 |
, getFilledInstOsParams |
... | ... | |
99 | 100 |
-- | Computes all disk-related nodes of an instance. For non-DRBD, |
100 | 101 |
-- this will be empty, for DRBD it will contain both the primary and |
101 | 102 |
-- the secondaries. |
102 |
instDiskNodes :: Instance -> S.Set String |
|
103 |
instDiskNodes = S.unions . map computeDiskNodes . instDisks |
|
103 |
instDiskNodes :: ConfigData -> Instance -> S.Set String |
|
104 |
instDiskNodes cfg inst = |
|
105 |
case getInstDisks cfg (instName inst) of |
|
106 |
Ok disks -> S.unions $ map computeDiskNodes disks |
|
107 |
Bad _ -> S.empty |
|
104 | 108 |
|
105 | 109 |
-- | Computes all nodes of an instance. |
106 |
instNodes :: Instance -> S.Set String |
|
107 |
instNodes inst = instPrimaryNode inst `S.insert` instDiskNodes inst
|
|
110 |
instNodes :: ConfigData -> Instance -> S.Set String
|
|
111 |
instNodes cfg inst = instPrimaryNode inst `S.insert` instDiskNodes cfg inst
|
|
108 | 112 |
|
109 | 113 |
-- | Computes the secondary nodes of an instance. Since this is valid |
110 | 114 |
-- only for DRBD, we call directly 'instDiskNodes', skipping over the |
111 | 115 |
-- extra primary insert. |
112 |
instSecondaryNodes :: Instance -> S.Set String |
|
113 |
instSecondaryNodes inst = |
|
114 |
instPrimaryNode inst `S.delete` instDiskNodes inst |
|
116 |
instSecondaryNodes :: ConfigData -> Instance -> S.Set String
|
|
117 |
instSecondaryNodes cfg inst =
|
|
118 |
instPrimaryNode inst `S.delete` instDiskNodes cfg inst
|
|
115 | 119 |
|
116 | 120 |
-- | Get instances of a given node. |
117 | 121 |
-- The node is specified through its UUID. |
... | ... | |
119 | 123 |
getNodeInstances cfg nname = |
120 | 124 |
let all_inst = M.elems . fromContainer . configInstances $ cfg |
121 | 125 |
pri_inst = filter ((== nname) . instPrimaryNode) all_inst |
122 |
sec_inst = filter ((nname `S.member`) . instSecondaryNodes) all_inst |
|
126 |
sec_inst = filter ((nname `S.member`) . instSecondaryNodes cfg) all_inst
|
|
123 | 127 |
in (pri_inst, sec_inst) |
124 | 128 |
|
125 | 129 |
-- | Computes the role of a node. |
... | ... | |
314 | 318 |
-- the primary node has to be appended to the results. |
315 | 319 |
getInstAllNodes :: ConfigData -> String -> ErrorResult [Node] |
316 | 320 |
getInstAllNodes cfg name = do |
317 |
inst <- getInstance cfg name
|
|
318 |
let diskNodes = concatMap (getDrbdDiskNodes cfg) $ instDisks inst
|
|
321 |
inst_disks <- getInstDisks cfg name
|
|
322 |
let diskNodes = concatMap (getDrbdDiskNodes cfg) inst_disks
|
|
319 | 323 |
pNode <- getInstPrimaryNode cfg name |
320 | 324 |
return . nub $ pNode:diskNodes |
321 | 325 |
|
322 | 326 |
-- | Get disks for a given instance. |
323 | 327 |
-- The instance is specified by name or uuid. |
324 |
--getInstDisks :: ConfigData -> String -> ErrorResult [Disk]
|
|
325 |
--getInstDisks cfg iname = do
|
|
326 |
-- let inst = getInstance cfg iname
|
|
327 |
-- mapM (getDisk cfg) $ instDisks inst
|
|
328 |
getInstDisks :: ConfigData -> String -> ErrorResult [Disk] |
|
329 |
getInstDisks cfg iname = do |
|
330 |
inst <- getInstance cfg iname
|
|
331 |
mapM (getDisk cfg) $ instDisks inst |
|
328 | 332 |
|
329 | 333 |
-- | Filters DRBD minors for a given node. |
330 | 334 |
getDrbdMinorsForNode :: String -> Disk -> [(Int, String)] |
... | ... | |
348 | 352 |
|
349 | 353 |
-- | Gets the list of DRBD minors for an instance that are related to |
350 | 354 |
-- a given node. |
351 |
getInstMinorsForNode :: String -> Instance |
|
355 |
getInstMinorsForNode :: ConfigData -> String -> Instance
|
|
352 | 356 |
-> [(String, Int, String, String, String, String)] |
353 |
getInstMinorsForNode node inst = |
|
357 |
getInstMinorsForNode cfg node inst =
|
|
354 | 358 |
let role = if node == instPrimaryNode inst |
355 | 359 |
then rolePrimary |
356 | 360 |
else roleSecondary |
357 | 361 |
iname = instName inst |
362 |
inst_disks = case getInstDisks cfg (instName inst) of |
|
363 |
Ok disks -> disks |
|
364 |
Bad _ -> [] |
|
358 | 365 |
-- FIXME: the disk/ build there is hack-ish; unify this in a |
359 | 366 |
-- separate place, or reuse the iv_name (but that is deprecated on |
360 | 367 |
-- the Python side) |
361 | 368 |
in concatMap (\(idx, dsk) -> |
362 | 369 |
[(node, minor, iname, "disk/" ++ show idx, role, peer) |
363 | 370 |
| (minor, peer) <- getDrbdMinorsForNode node dsk]) . |
364 |
zip [(0::Int)..] . instDisks $ inst
|
|
371 |
zip [(0::Int)..] $ inst_disks
|
|
365 | 372 |
|
366 | 373 |
-- | Builds link -> ip -> instname map. |
367 | 374 |
-- |
b/src/Ganeti/DataCollectors/Lv.hs | ||
---|---|---|
39 | 39 |
import qualified Control.Exception as E |
40 | 40 |
import Control.Monad |
41 | 41 |
import Data.Attoparsec.Text.Lazy as A |
42 |
import Data.List |
|
42 |
--import Data.List
|
|
43 | 43 |
import Data.Text.Lazy (pack, unpack) |
44 | 44 |
import Network.BSD (getHostName) |
45 | 45 |
import System.Process |
... | ... | |
145 | 145 |
exitIfBad "Unable to obtain the list of instances" instances |
146 | 146 |
|
147 | 147 |
-- | Adds the name of the instance to the information about one logical volume. |
148 |
addInstNameToOneLv :: [Instance] -> LVInfo -> LVInfo |
|
149 |
addInstNameToOneLv instances lvInfo = |
|
150 |
let vg_name = lviVgName lvInfo |
|
151 |
lv_name = lviName lvInfo |
|
152 |
instanceHasDisk = any (includesLogicalId vg_name lv_name) . instDisks |
|
153 |
rightInstance = find instanceHasDisk instances |
|
154 |
in
|
|
155 |
case rightInstance of |
|
156 |
Nothing -> lvInfo |
|
157 |
Just i -> lvInfo { lviInstance = Just $ instName i } |
|
148 |
--addInstNameToOneLv :: [Instance] -> LVInfo -> LVInfo
|
|
149 |
--addInstNameToOneLv instances lvInfo =
|
|
150 |
-- let vg_name = lviVgName lvInfo
|
|
151 |
-- lv_name = lviName lvInfo
|
|
152 |
-- instanceHasDisk = any (includesLogicalId vg_name lv_name) . instDisks
|
|
153 |
-- rightInstance = find instanceHasDisk instances
|
|
154 |
-- in
|
|
155 |
-- case rightInstance of
|
|
156 |
-- Nothing -> lvInfo
|
|
157 |
-- Just i -> lvInfo { lviInstance = Just $ instName i }
|
|
158 | 158 |
|
159 | 159 |
-- | Adds the name of the instance to the information about logical volumes. |
160 | 160 |
addInstNameToLv :: [Instance] -> [LVInfo] -> [LVInfo] |
161 |
addInstNameToLv instances = map (addInstNameToOneLv instances)
|
|
161 |
addInstNameToLv _instances = id -- map (addInstNameToOneLv instances)
|
|
162 | 162 |
|
163 | 163 |
-- | This function computes the JSON representation of the LV status. |
164 | 164 |
buildJsonReport :: Options -> IO J.JSValue |
b/src/Ganeti/Objects.hs | ||
---|---|---|
48 | 48 |
, allBeParamFields |
49 | 49 |
, Instance(..) |
50 | 50 |
, toDictInstance |
51 |
, getDiskSizeRequirements |
|
52 | 51 |
, PartialNDParams(..) |
53 | 52 |
, FilledNDParams(..) |
54 | 53 |
, fillNDParams |
... | ... | |
455 | 454 |
, simpleField "osparams_private" [t| OsParamsPrivate |] |
456 | 455 |
, simpleField "admin_state" [t| AdminState |] |
457 | 456 |
, simpleField "nics" [t| [PartialNic] |] |
458 |
, simpleField "disks" [t| [Disk] |]
|
|
457 |
, simpleField "disks" [t| [String] |]
|
|
459 | 458 |
, simpleField "disk_template" [t| DiskTemplate |] |
460 | 459 |
, simpleField "disks_active" [t| Bool |] |
461 | 460 |
, optionalField $ simpleField "network_port" [t| Int |] |
... | ... | |
478 | 477 |
instance TagsObject Instance where |
479 | 478 |
tagsOf = instTags |
480 | 479 |
|
481 |
-- | Retrieves the real disk size requirements for all the disks of the |
|
482 |
-- instance. This includes the metadata etc. and is different from the values |
|
483 |
-- visible to the instance. |
|
484 |
getDiskSizeRequirements :: Instance -> Int |
|
485 |
getDiskSizeRequirements inst = |
|
486 |
sum . map |
|
487 |
(\disk -> case instDiskTemplate inst of |
|
488 |
DTDrbd8 -> diskSize disk + C.drbdMetaSize |
|
489 |
DTDiskless -> 0 |
|
490 |
DTBlock -> 0 |
|
491 |
_ -> diskSize disk ) |
|
492 |
$ instDisks inst |
|
493 |
|
|
494 | 480 |
-- * IPolicy definitions |
495 | 481 |
|
496 | 482 |
$(buildParam "ISpec" "ispec" |
b/src/Ganeti/Query/Instance.hs | ||
---|---|---|
177 | 177 |
[ (FieldDefinition "disk_usage" "DiskUsage" QFTUnit |
178 | 178 |
"Total disk space used by instance on each of its nodes; this is not the\ |
179 | 179 |
\ disk size visible to the instance, but the usage on the node", |
180 |
FieldSimple (rsNormal . getDiskSizeRequirements), QffNormal)
|
|
180 |
FieldConfig getDiskSizeRequirements, QffNormal)
|
|
181 | 181 |
, (FieldDefinition "disk.count" "Disks" QFTNumber |
182 | 182 |
"Number of disks", |
183 | 183 |
FieldSimple (rsNormal . length . instDisks), QffNormal) |
184 | 184 |
, (FieldDefinition "disk.sizes" "Disk_sizes" QFTOther |
185 | 185 |
"List of disk sizes", |
186 |
FieldSimple (rsNormal . map diskSize . instDisks), QffNormal)
|
|
186 |
FieldConfig getDiskSizes, QffNormal)
|
|
187 | 187 |
, (FieldDefinition "disk.spindles" "Disk_spindles" QFTOther |
188 | 188 |
"List of disk spindles", |
189 |
FieldSimple (rsNormal . map (MaybeForJSON . diskSpindles) . |
|
190 |
instDisks), |
|
191 |
QffNormal) |
|
189 |
FieldConfig getDiskSpindles, QffNormal) |
|
192 | 190 |
, (FieldDefinition "disk.names" "Disk_names" QFTOther |
193 | 191 |
"List of disk names", |
194 |
FieldSimple (rsNormal . map (MaybeForJSON . diskName) . |
|
195 |
instDisks), |
|
196 |
QffNormal) |
|
192 |
FieldConfig getDiskNames, QffNormal) |
|
197 | 193 |
, (FieldDefinition "disk.uuids" "Disk_UUIDs" QFTOther |
198 | 194 |
"List of disk UUIDs", |
199 |
FieldSimple (rsNormal . map diskUuid . instDisks), QffNormal)
|
|
195 |
FieldConfig getDiskUuids, QffNormal)
|
|
200 | 196 |
] ++ |
201 | 197 |
|
202 | 198 |
-- Per-disk parameter fields |
203 |
instantiateIndexedFields C.maxDisks |
|
204 |
[ (fieldDefinitionCompleter "disk.size/%d" "Disk/%d" QFTUnit |
|
205 |
"Disk size of %s disk", |
|
206 |
getIndexedField instDisks diskSize, QffNormal) |
|
207 |
, (fieldDefinitionCompleter "disk.spindles/%d" "DiskSpindles/%d" QFTNumber |
|
208 |
"Spindles of %s disk", |
|
209 |
getIndexedOptionalField instDisks diskSpindles, QffNormal) |
|
210 |
, (fieldDefinitionCompleter "disk.name/%d" "DiskName/%d" QFTText |
|
211 |
"Name of %s disk", |
|
212 |
getIndexedOptionalField instDisks diskName, QffNormal) |
|
213 |
, (fieldDefinitionCompleter "disk.uuid/%d" "DiskUUID/%d" QFTText |
|
214 |
"UUID of %s disk", |
|
215 |
getIndexedField instDisks diskUuid, QffNormal) |
|
216 |
] ++ |
|
199 |
--instantiateIndexedFields C.maxDisks
|
|
200 |
--[ (fieldDefinitionCompleter "disk.size/%d" "Disk/%d" QFTUnit
|
|
201 |
-- "Disk size of %s disk",
|
|
202 |
-- getIndexedField instDisks diskSize, QffNormal)
|
|
203 |
--, (fieldDefinitionCompleter "disk.spindles/%d" "DiskSpindles/%d" QFTNumber
|
|
204 |
-- "Spindles of %s disk",
|
|
205 |
-- getIndexedOptionalField instDisks diskSpindles, QffNormal)
|
|
206 |
--, (fieldDefinitionCompleter "disk.name/%d" "DiskName/%d" QFTText
|
|
207 |
-- "Name of %s disk",
|
|
208 |
-- getIndexedOptionalField instDisks diskName, QffNormal)
|
|
209 |
--, (fieldDefinitionCompleter "disk.uuid/%d" "DiskUUID/%d" QFTText
|
|
210 |
-- "UUID of %s disk",
|
|
211 |
-- getIndexedField instDisks diskUuid, QffNormal)
|
|
212 |
--] ++
|
|
217 | 213 |
|
218 | 214 |
-- Aggregate nic parameter fields |
219 | 215 |
[ (FieldDefinition "nic.count" "NICs" QFTNumber |
... | ... | |
358 | 354 |
getDefaultNicParams cfg = |
359 | 355 |
(Map.!) (fromContainer . clusterNicparams . configCluster $ cfg) C.ppDefault |
360 | 356 |
|
357 |
-- | Retrieves the real disk size requirements for all the disks of the |
|
358 |
-- instance. This includes the metadata etc. and is different from the values |
|
359 |
-- visible to the instance. |
|
360 |
getDiskSizeRequirements :: ConfigData -> Instance -> ResultEntry |
|
361 |
getDiskSizeRequirements cfg inst = |
|
362 |
rsErrorNoData . liftA (sum . map getSizes) . getInstDisks cfg $ instName inst |
|
363 |
where |
|
364 |
getSizes :: Disk -> Int |
|
365 |
getSizes disk = |
|
366 |
case instDiskTemplate inst of |
|
367 |
DTDrbd8 -> diskSize disk + C.drbdMetaSize |
|
368 |
DTDiskless -> 0 |
|
369 |
DTBlock -> 0 |
|
370 |
_ -> diskSize disk |
|
371 |
|
|
372 |
-- | Get a list of disk sizes for an instance |
|
373 |
getDiskSizes :: ConfigData -> Instance -> ResultEntry |
|
374 |
getDiskSizes cfg = |
|
375 |
rsErrorNoData . liftA (map diskSize) . getInstDisks cfg . instName |
|
376 |
|
|
377 |
-- | Get a list of disk spindles |
|
378 |
getDiskSpindles :: ConfigData -> Instance -> ResultEntry |
|
379 |
getDiskSpindles cfg = |
|
380 |
rsErrorNoData . liftA (map (MaybeForJSON . diskSpindles)) . |
|
381 |
getInstDisks cfg . instName |
|
382 |
|
|
383 |
-- | Get a list of disk names for an instance |
|
384 |
getDiskNames :: ConfigData -> Instance -> ResultEntry |
|
385 |
getDiskNames cfg = |
|
386 |
rsErrorNoData . liftA (map (MaybeForJSON . diskName)) . |
|
387 |
getInstDisks cfg . instName |
|
388 |
|
|
389 |
-- | Get a list of disk UUIDs for an instance |
|
390 |
getDiskUuids :: ConfigData -> Instance -> ResultEntry |
|
391 |
getDiskUuids cfg = |
|
392 |
rsErrorNoData . liftA (map diskUuid) . getInstDisks cfg . instName |
|
393 |
|
|
361 | 394 |
-- | Returns a field that retrieves a given NIC's network name. |
362 | 395 |
getIndexedNicNetworkNameField :: Int -> FieldGetter Instance Runtime |
363 | 396 |
getIndexedNicNetworkNameField index = |
Also available in: Unified diff