getInstanceLVsByNode :: ConfigData -> Instance -> ErrorResult NodeLVsMap
getInstanceLVsByNode cd inst =
    withMissingParam "Instance without Primary Node"
      (\i -> return $ MM.fromList . lvsByNode i)
      (instPrimaryNode inst)
    <*> getInstDisksFromObj cd inst
  where
    lvsByNode :: String -> [Disk] -> [(String, LogicalVolume)]
    lvsByNode node = concatMap (lvsByNode1 node)
    lvsByNode1 :: String -> Disk -> [(String, LogicalVolume)]
    lvsByNode1 _ (diskLogicalId &&& diskChildren
                   -> (Just (LIDDrbd8 nA nB _ _ _ _), ch)) =
                         lvsByNode nA ch ++ lvsByNode nB ch
    lvsByNode1 node (diskLogicalId -> (Just (LIDPlain lv))) =
                         [(node, lv)]
    lvsByNode1 node (diskChildren -> ch) = lvsByNode node ch
getInstanceLVsByNode :: ConfigData -> Instance -> ErrorResult NodeLVsMap
getInstanceLVsByNode cd inst =
    withMissingParam "Instance without Primary Node"
      (\i -> return $ MM.fromList . lvsByNode i)
      (instPrimaryNode inst)
    <*> getInstDisksFromObj cd inst
  where
    lvsByNode :: String -> [Disk] -> [(String, LogicalVolume)]
    lvsByNode node = concatMap (lvsByNode1 node)
    lvsByNode1 :: String -> Disk -> [(String, LogicalVolume)]
    lvsByNode1 _ (diskLogicalId &&& diskChildren
                   -> (Just (LIDDrbd8 nA nB _ _ _ _), ch)) =
                         lvsByNode nA ch ++ lvsByNode nB ch
    lvsByNode1 node (diskLogicalId -> (Just (LIDPlain lv))) =
                         [(node, lv)]
    lvsByNode1 node (diskChildren -> ch) = lvsByNode node ch
getInstanceLVsByNode cd inst =
    withMissingParam "Instance without Primary Node"
      (\i -> return $ MM.fromList . lvsByNode i)
      (instPrimaryNode inst)
    <*> getInstDisksFromObj cd inst
  where
    lvsByNode :: String -> [Disk] -> [(String, LogicalVolume)]
    lvsByNode node = concatMap (lvsByNode1 node)
    lvsByNode1 :: String -> Disk -> [(String, LogicalVolume)]
    lvsByNode1 _ (diskLogicalId &&& diskChildren
                   -> (Just (LIDDrbd8 nA nB _ _ _ _), ch)) =
                         lvsByNode nA ch ++ lvsByNode nB ch
    lvsByNode1 node (diskLogicalId -> (Just (LIDPlain lv))) =
                         [(node, lv)]
    lvsByNode1 node (diskChildren -> ch) = lvsByNode node ch