Revision 5183e8be htools/Ganeti/Config.hs
b/htools/Ganeti/Config.hs | ||
---|---|---|
54 | 54 |
import qualified Data.Set as S |
55 | 55 |
import qualified Text.JSON as J |
56 | 56 |
|
57 |
import Ganeti.JSON |
|
58 | 57 |
import Ganeti.BasicTypes |
59 |
|
|
60 | 58 |
import qualified Ganeti.Constants as C |
59 |
import Ganeti.Errors |
|
60 |
import Ganeti.JSON |
|
61 | 61 |
import Ganeti.Objects |
62 | 62 |
|
63 | 63 |
-- | Type alias for the link and ip map. |
... | ... | |
145 | 145 |
|
146 | 146 |
-- | Generic lookup function that converts from a possible abbreviated |
147 | 147 |
-- name to a full name. |
148 |
getItem :: String -> String -> M.Map String a -> Result a |
|
148 |
getItem :: String -> String -> M.Map String a -> ErrorResult a
|
|
149 | 149 |
getItem kind name allitems = do |
150 | 150 |
let lresult = lookupName (M.keys allitems) name |
151 |
err msg = Bad $ kind ++ " name " ++ name ++ " " ++ msg |
|
151 |
err msg = Bad $ OpPrereqError (kind ++ " name " ++ name ++ " " ++ msg) |
|
152 |
ECodeNoEnt |
|
152 | 153 |
fullname <- case lrMatchPriority lresult of |
153 | 154 |
PartialMatch -> Ok $ lrContent lresult |
154 | 155 |
ExactMatch -> Ok $ lrContent lresult |
... | ... | |
158 | 159 |
M.lookup fullname allitems |
159 | 160 |
|
160 | 161 |
-- | Looks up a node. |
161 |
getNode :: ConfigData -> String -> Result Node |
|
162 |
getNode :: ConfigData -> String -> ErrorResult Node
|
|
162 | 163 |
getNode cfg name = getItem "Node" name (fromContainer $ configNodes cfg) |
163 | 164 |
|
164 | 165 |
-- | Looks up an instance. |
165 |
getInstance :: ConfigData -> String -> Result Instance |
|
166 |
getInstance :: ConfigData -> String -> ErrorResult Instance
|
|
166 | 167 |
getInstance cfg name = |
167 | 168 |
getItem "Instance" name (fromContainer $ configInstances cfg) |
168 | 169 |
|
169 | 170 |
-- | Looks up a node group. This is more tricky than for |
170 | 171 |
-- node/instances since the groups map is indexed by uuid, not name. |
171 |
getGroup :: ConfigData -> String -> Result NodeGroup |
|
172 |
getGroup :: ConfigData -> String -> ErrorResult NodeGroup
|
|
172 | 173 |
getGroup cfg name = |
173 | 174 |
let groups = fromContainer (configNodegroups cfg) |
174 | 175 |
in case getItem "NodeGroup" name groups of |
... | ... | |
209 | 210 |
(concatMap fst ginsts, concatMap snd ginsts) |
210 | 211 |
|
211 | 212 |
-- | Looks up an instance's primary node. |
212 |
getInstPrimaryNode :: ConfigData -> String -> Result Node |
|
213 |
getInstPrimaryNode :: ConfigData -> String -> ErrorResult Node
|
|
213 | 214 |
getInstPrimaryNode cfg name = |
214 | 215 |
liftM instPrimaryNode (getInstance cfg name) >>= getNode cfg |
215 | 216 |
|
Also available in: Unified diff