Revision 8472a321 Ganeti/HTools/Loader.hs

b/Ganeti/HTools/Loader.hs
68 68

  
69 69
-- | Compute the longest common suffix of a NameList list that
70 70
-- | starts with a dot
71
longestDomain :: NameList -> String
71
longestDomain :: [String] -> String
72 72
longestDomain [] = ""
73
longestDomain ((_,x):xs) =
74
    let
75
        onlyStrings = snd $ unzip xs
76
    in
77
      foldr (\ suffix accu -> if all (isSuffixOf suffix) onlyStrings
73
longestDomain (x:xs) =
74
      foldr (\ suffix accu -> if all (isSuffixOf suffix) xs
78 75
                              then suffix
79 76
                              else accu)
80 77
      "" $ filter (isPrefixOf ".") (tails x)
......
89 86
              [(String, Int)], Instance.AssocList) -- ^ Data from either
90 87
                                                   -- Text.loadData
91 88
                                                   -- or Rapi.loadData
92
          -> Result (NodeList, InstanceList, String, NameList, NameList)
89
          -> Result (NodeList, InstanceList, String)
93 90
mergeData (ktn, nl, kti, il) = do
94 91
  let
95 92
      nl2 = fixNodes nl il
96 93
      il3 = Container.fromAssocList il
97 94
      nl3 = Container.fromAssocList
98 95
            (map (\ (k, v) -> (k, Node.buildPeers v il3 (length nl2))) nl2)
99
      xtn = swapPairs ktn
100
      xti = swapPairs kti
101
      common_suffix = longestDomain (xti ++ xtn)
96
      node_names = map Node.name $ Container.elems nl3
97
      inst_names = map Instance.name $ Container.elems il3
98
      common_suffix = longestDomain (node_names ++ inst_names)
102 99
      csl = length common_suffix
103
      stn = map (\(x, y) -> (x, stripSuffix csl y)) xtn
104
      sti = map (\(x, y) -> (x, stripSuffix csl y)) xti
105 100
      snl = Container.map (\n -> setName n (stripSuffix csl $ name n)) nl3
106 101
      sil = Container.map (\i -> setName i (stripSuffix csl $ name i)) il3
107
  return (snl, sil, common_suffix, stn, sti)
102
  return (snl, sil, common_suffix)
108 103

  
109 104
-- | Check cluster data for consistency
110 105
checkData :: NodeList -> InstanceList

Also available in: Unified diff