root / src / Ganeti / Config.hs @ 53822ec4
History | View | Annotate | Download (11.1 kB)
1 | eaa64cd8 | Iustin Pop | {-| Implementation of the Ganeti configuration database. |
---|---|---|---|
2 | eaa64cd8 | Iustin Pop | |
3 | eaa64cd8 | Iustin Pop | -} |
4 | eaa64cd8 | Iustin Pop | |
5 | eaa64cd8 | Iustin Pop | {- |
6 | eaa64cd8 | Iustin Pop | |
7 | eaa64cd8 | Iustin Pop | Copyright (C) 2011, 2012 Google Inc. |
8 | eaa64cd8 | Iustin Pop | |
9 | eaa64cd8 | Iustin Pop | This program is free software; you can redistribute it and/or modify |
10 | eaa64cd8 | Iustin Pop | it under the terms of the GNU General Public License as published by |
11 | eaa64cd8 | Iustin Pop | the Free Software Foundation; either version 2 of the License, or |
12 | eaa64cd8 | Iustin Pop | (at your option) any later version. |
13 | eaa64cd8 | Iustin Pop | |
14 | eaa64cd8 | Iustin Pop | This program is distributed in the hope that it will be useful, but |
15 | eaa64cd8 | Iustin Pop | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | eaa64cd8 | Iustin Pop | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | eaa64cd8 | Iustin Pop | General Public License for more details. |
18 | eaa64cd8 | Iustin Pop | |
19 | eaa64cd8 | Iustin Pop | You should have received a copy of the GNU General Public License |
20 | eaa64cd8 | Iustin Pop | along with this program; if not, write to the Free Software |
21 | eaa64cd8 | Iustin Pop | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
22 | eaa64cd8 | Iustin Pop | 02110-1301, USA. |
23 | eaa64cd8 | Iustin Pop | |
24 | eaa64cd8 | Iustin Pop | -} |
25 | eaa64cd8 | Iustin Pop | |
26 | eaa64cd8 | Iustin Pop | module Ganeti.Config |
27 | eaa64cd8 | Iustin Pop | ( LinkIpMap |
28 | da45c352 | Iustin Pop | , NdParamObject(..) |
29 | eaa64cd8 | Iustin Pop | , loadConfig |
30 | eaa64cd8 | Iustin Pop | , getNodeInstances |
31 | da45c352 | Iustin Pop | , getNodeRole |
32 | da45c352 | Iustin Pop | , getNodeNdParams |
33 | eaa64cd8 | Iustin Pop | , getDefaultNicLink |
34 | 0ec87781 | Iustin Pop | , getDefaultHypervisor |
35 | eaa64cd8 | Iustin Pop | , getInstancesIpByLink |
36 | eaa64cd8 | Iustin Pop | , getNode |
37 | eaa64cd8 | Iustin Pop | , getInstance |
38 | 4cd428db | Iustin Pop | , getGroup |
39 | da45c352 | Iustin Pop | , getGroupNdParams |
40 | e5cb098c | Agata Murawska | , getGroupIpolicy |
41 | 90d033ef | Iustin Pop | , getGroupDiskParams |
42 | e5cb098c | Agata Murawska | , getGroupNodes |
43 | e5cb098c | Agata Murawska | , getGroupInstances |
44 | da45c352 | Iustin Pop | , getGroupOfNode |
45 | eaa64cd8 | Iustin Pop | , getInstPrimaryNode |
46 | d81ec8b7 | Iustin Pop | , getInstMinorsForNode |
47 | 05092772 | Helga Velroyen | , getNetwork |
48 | eaa64cd8 | Iustin Pop | , buildLinkIpInstnameMap |
49 | 7b2ead5a | Iustin Pop | , instNodes |
50 | eaa64cd8 | Iustin Pop | ) where |
51 | eaa64cd8 | Iustin Pop | |
52 | 2cdaf225 | Iustin Pop | import Control.Monad (liftM) |
53 | eaa64cd8 | Iustin Pop | import Data.List (foldl') |
54 | eaa64cd8 | Iustin Pop | import qualified Data.Map as M |
55 | 7b2ead5a | Iustin Pop | import qualified Data.Set as S |
56 | eaa64cd8 | Iustin Pop | import qualified Text.JSON as J |
57 | eaa64cd8 | Iustin Pop | |
58 | eaa64cd8 | Iustin Pop | import Ganeti.BasicTypes |
59 | eaa64cd8 | Iustin Pop | import qualified Ganeti.Constants as C |
60 | 5183e8be | Iustin Pop | import Ganeti.Errors |
61 | 5183e8be | Iustin Pop | import Ganeti.JSON |
62 | eaa64cd8 | Iustin Pop | import Ganeti.Objects |
63 | 22381768 | Iustin Pop | import Ganeti.Types |
64 | eaa64cd8 | Iustin Pop | |
65 | eaa64cd8 | Iustin Pop | -- | Type alias for the link and ip map. |
66 | eaa64cd8 | Iustin Pop | type LinkIpMap = M.Map String (M.Map String String) |
67 | eaa64cd8 | Iustin Pop | |
68 | da45c352 | Iustin Pop | -- | Type class denoting objects which have node parameters. |
69 | da45c352 | Iustin Pop | class NdParamObject a where |
70 | da45c352 | Iustin Pop | getNdParamsOf :: ConfigData -> a -> Maybe FilledNDParams |
71 | da45c352 | Iustin Pop | |
72 | eaa64cd8 | Iustin Pop | -- | Reads the config file. |
73 | eaa64cd8 | Iustin Pop | readConfig :: FilePath -> IO String |
74 | eaa64cd8 | Iustin Pop | readConfig = readFile |
75 | eaa64cd8 | Iustin Pop | |
76 | eaa64cd8 | Iustin Pop | -- | Parses the configuration file. |
77 | eaa64cd8 | Iustin Pop | parseConfig :: String -> Result ConfigData |
78 | eaa64cd8 | Iustin Pop | parseConfig = fromJResult "parsing configuration" . J.decodeStrict |
79 | eaa64cd8 | Iustin Pop | |
80 | eaa64cd8 | Iustin Pop | -- | Wrapper over 'readConfig' and 'parseConfig'. |
81 | eaa64cd8 | Iustin Pop | loadConfig :: FilePath -> IO (Result ConfigData) |
82 | eaa64cd8 | Iustin Pop | loadConfig = fmap parseConfig . readConfig |
83 | eaa64cd8 | Iustin Pop | |
84 | eaa64cd8 | Iustin Pop | -- * Query functions |
85 | eaa64cd8 | Iustin Pop | |
86 | 7b2ead5a | Iustin Pop | -- | Computes the nodes covered by a disk. |
87 | 7b2ead5a | Iustin Pop | computeDiskNodes :: Disk -> S.Set String |
88 | 7b2ead5a | Iustin Pop | computeDiskNodes dsk = |
89 | 7b2ead5a | Iustin Pop | case diskLogicalId dsk of |
90 | 7b2ead5a | Iustin Pop | LIDDrbd8 nodeA nodeB _ _ _ _ -> S.fromList [nodeA, nodeB] |
91 | 7b2ead5a | Iustin Pop | _ -> S.empty |
92 | 7b2ead5a | Iustin Pop | |
93 | 7b2ead5a | Iustin Pop | -- | Computes all disk-related nodes of an instance. For non-DRBD, |
94 | 7b2ead5a | Iustin Pop | -- this will be empty, for DRBD it will contain both the primary and |
95 | 7b2ead5a | Iustin Pop | -- the secondaries. |
96 | 7b2ead5a | Iustin Pop | instDiskNodes :: Instance -> S.Set String |
97 | 7b2ead5a | Iustin Pop | instDiskNodes = S.unions . map computeDiskNodes . instDisks |
98 | 7b2ead5a | Iustin Pop | |
99 | 7b2ead5a | Iustin Pop | -- | Computes all nodes of an instance. |
100 | 7b2ead5a | Iustin Pop | instNodes :: Instance -> S.Set String |
101 | 7b2ead5a | Iustin Pop | instNodes inst = instPrimaryNode inst `S.insert` instDiskNodes inst |
102 | 7b2ead5a | Iustin Pop | |
103 | 7b2ead5a | Iustin Pop | -- | Computes the secondary nodes of an instance. Since this is valid |
104 | 7b2ead5a | Iustin Pop | -- only for DRBD, we call directly 'instDiskNodes', skipping over the |
105 | 7b2ead5a | Iustin Pop | -- extra primary insert. |
106 | 7b2ead5a | Iustin Pop | instSecondaryNodes :: Instance -> S.Set String |
107 | 7b2ead5a | Iustin Pop | instSecondaryNodes inst = |
108 | 7b2ead5a | Iustin Pop | instPrimaryNode inst `S.delete` instDiskNodes inst |
109 | 7b2ead5a | Iustin Pop | |
110 | eaa64cd8 | Iustin Pop | -- | Get instances of a given node. |
111 | eaa64cd8 | Iustin Pop | getNodeInstances :: ConfigData -> String -> ([Instance], [Instance]) |
112 | eaa64cd8 | Iustin Pop | getNodeInstances cfg nname = |
113 | 84835174 | Iustin Pop | let all_inst = M.elems . fromContainer . configInstances $ cfg |
114 | eaa64cd8 | Iustin Pop | pri_inst = filter ((== nname) . instPrimaryNode) all_inst |
115 | 7b2ead5a | Iustin Pop | sec_inst = filter ((nname `S.member`) . instSecondaryNodes) all_inst |
116 | eaa64cd8 | Iustin Pop | in (pri_inst, sec_inst) |
117 | eaa64cd8 | Iustin Pop | |
118 | da45c352 | Iustin Pop | -- | Computes the role of a node. |
119 | da45c352 | Iustin Pop | getNodeRole :: ConfigData -> Node -> NodeRole |
120 | da45c352 | Iustin Pop | getNodeRole cfg node |
121 | 5b11f8db | Iustin Pop | | nodeName node == clusterMasterNode (configCluster cfg) = NRMaster |
122 | da45c352 | Iustin Pop | | nodeMasterCandidate node = NRCandidate |
123 | da45c352 | Iustin Pop | | nodeDrained node = NRDrained |
124 | da45c352 | Iustin Pop | | nodeOffline node = NROffline |
125 | da45c352 | Iustin Pop | | otherwise = NRRegular |
126 | da45c352 | Iustin Pop | |
127 | eaa64cd8 | Iustin Pop | -- | Returns the default cluster link. |
128 | eaa64cd8 | Iustin Pop | getDefaultNicLink :: ConfigData -> String |
129 | eaa64cd8 | Iustin Pop | getDefaultNicLink = |
130 | 84835174 | Iustin Pop | nicpLink . (M.! C.ppDefault) . fromContainer . |
131 | 84835174 | Iustin Pop | clusterNicparams . configCluster |
132 | eaa64cd8 | Iustin Pop | |
133 | 0ec87781 | Iustin Pop | -- | Returns the default cluster hypervisor. |
134 | 0ec87781 | Iustin Pop | getDefaultHypervisor :: ConfigData -> Hypervisor |
135 | 0ec87781 | Iustin Pop | getDefaultHypervisor cfg = |
136 | 0ec87781 | Iustin Pop | case clusterEnabledHypervisors $ configCluster cfg of |
137 | 0ec87781 | Iustin Pop | -- FIXME: this case shouldn't happen (configuration broken), but |
138 | 0ec87781 | Iustin Pop | -- for now we handle it here because we're not authoritative for |
139 | 0ec87781 | Iustin Pop | -- the config |
140 | 0ec87781 | Iustin Pop | [] -> XenPvm |
141 | 0ec87781 | Iustin Pop | x:_ -> x |
142 | 0ec87781 | Iustin Pop | |
143 | eaa64cd8 | Iustin Pop | -- | Returns instances of a given link. |
144 | eaa64cd8 | Iustin Pop | getInstancesIpByLink :: LinkIpMap -> String -> [String] |
145 | eaa64cd8 | Iustin Pop | getInstancesIpByLink linkipmap link = |
146 | eaa64cd8 | Iustin Pop | M.keys $ M.findWithDefault M.empty link linkipmap |
147 | eaa64cd8 | Iustin Pop | |
148 | 0fc8e521 | Iustin Pop | -- | Generic lookup function that converts from a possible abbreviated |
149 | 0fc8e521 | Iustin Pop | -- name to a full name. |
150 | 5183e8be | Iustin Pop | getItem :: String -> String -> M.Map String a -> ErrorResult a |
151 | 0fc8e521 | Iustin Pop | getItem kind name allitems = do |
152 | 0fc8e521 | Iustin Pop | let lresult = lookupName (M.keys allitems) name |
153 | 5183e8be | Iustin Pop | err msg = Bad $ OpPrereqError (kind ++ " name " ++ name ++ " " ++ msg) |
154 | 5183e8be | Iustin Pop | ECodeNoEnt |
155 | 0fc8e521 | Iustin Pop | fullname <- case lrMatchPriority lresult of |
156 | 0fc8e521 | Iustin Pop | PartialMatch -> Ok $ lrContent lresult |
157 | 0fc8e521 | Iustin Pop | ExactMatch -> Ok $ lrContent lresult |
158 | 0fc8e521 | Iustin Pop | MultipleMatch -> err "has multiple matches" |
159 | 0fc8e521 | Iustin Pop | FailMatch -> err "not found" |
160 | 0fc8e521 | Iustin Pop | maybe (err "not found after successfull match?!") Ok $ |
161 | 0fc8e521 | Iustin Pop | M.lookup fullname allitems |
162 | 0fc8e521 | Iustin Pop | |
163 | eaa64cd8 | Iustin Pop | -- | Looks up a node. |
164 | 5183e8be | Iustin Pop | getNode :: ConfigData -> String -> ErrorResult Node |
165 | 84835174 | Iustin Pop | getNode cfg name = getItem "Node" name (fromContainer $ configNodes cfg) |
166 | eaa64cd8 | Iustin Pop | |
167 | eaa64cd8 | Iustin Pop | -- | Looks up an instance. |
168 | 5183e8be | Iustin Pop | getInstance :: ConfigData -> String -> ErrorResult Instance |
169 | 84835174 | Iustin Pop | getInstance cfg name = |
170 | 84835174 | Iustin Pop | getItem "Instance" name (fromContainer $ configInstances cfg) |
171 | eaa64cd8 | Iustin Pop | |
172 | 4cd428db | Iustin Pop | -- | Looks up a node group. This is more tricky than for |
173 | 4cd428db | Iustin Pop | -- node/instances since the groups map is indexed by uuid, not name. |
174 | 5183e8be | Iustin Pop | getGroup :: ConfigData -> String -> ErrorResult NodeGroup |
175 | 4cd428db | Iustin Pop | getGroup cfg name = |
176 | 4cd428db | Iustin Pop | let groups = fromContainer (configNodegroups cfg) |
177 | 4cd428db | Iustin Pop | in case getItem "NodeGroup" name groups of |
178 | 4cd428db | Iustin Pop | -- if not found by uuid, we need to look it up by name, slow |
179 | 4cd428db | Iustin Pop | Ok grp -> Ok grp |
180 | 4cd428db | Iustin Pop | Bad _ -> let by_name = M.mapKeys |
181 | 5b11f8db | Iustin Pop | (groupName . (M.!) groups) groups |
182 | 4cd428db | Iustin Pop | in getItem "NodeGroup" name by_name |
183 | 4cd428db | Iustin Pop | |
184 | da45c352 | Iustin Pop | -- | Computes a node group's node params. |
185 | da45c352 | Iustin Pop | getGroupNdParams :: ConfigData -> NodeGroup -> FilledNDParams |
186 | da45c352 | Iustin Pop | getGroupNdParams cfg ng = |
187 | da45c352 | Iustin Pop | fillNDParams (clusterNdparams $ configCluster cfg) (groupNdparams ng) |
188 | da45c352 | Iustin Pop | |
189 | e5cb098c | Agata Murawska | -- | Computes a node group's ipolicy. |
190 | e5cb098c | Agata Murawska | getGroupIpolicy :: ConfigData -> NodeGroup -> FilledIPolicy |
191 | e5cb098c | Agata Murawska | getGroupIpolicy cfg ng = |
192 | e5cb098c | Agata Murawska | fillIPolicy (clusterIpolicy $ configCluster cfg) (groupIpolicy ng) |
193 | e5cb098c | Agata Murawska | |
194 | 90d033ef | Iustin Pop | -- | Computes a group\'s (merged) disk params. |
195 | 90d033ef | Iustin Pop | getGroupDiskParams :: ConfigData -> NodeGroup -> DiskParams |
196 | 90d033ef | Iustin Pop | getGroupDiskParams cfg ng = |
197 | edc1acde | Iustin Pop | GenericContainer $ |
198 | 90d033ef | Iustin Pop | fillDict (fromContainer . clusterDiskparams $ configCluster cfg) |
199 | 90d033ef | Iustin Pop | (fromContainer $ groupDiskparams ng) [] |
200 | 90d033ef | Iustin Pop | |
201 | e5cb098c | Agata Murawska | -- | Get nodes of a given node group. |
202 | e5cb098c | Agata Murawska | getGroupNodes :: ConfigData -> String -> [Node] |
203 | e5cb098c | Agata Murawska | getGroupNodes cfg gname = |
204 | e5cb098c | Agata Murawska | let all_nodes = M.elems . fromContainer . configNodes $ cfg in |
205 | e5cb098c | Agata Murawska | filter ((==gname) . nodeGroup) all_nodes |
206 | e5cb098c | Agata Murawska | |
207 | e5cb098c | Agata Murawska | -- | Get (primary, secondary) instances of a given node group. |
208 | e5cb098c | Agata Murawska | getGroupInstances :: ConfigData -> String -> ([Instance], [Instance]) |
209 | e5cb098c | Agata Murawska | getGroupInstances cfg gname = |
210 | e5cb098c | Agata Murawska | let gnodes = map nodeName (getGroupNodes cfg gname) |
211 | e5cb098c | Agata Murawska | ginsts = map (getNodeInstances cfg) gnodes in |
212 | e5cb098c | Agata Murawska | (concatMap fst ginsts, concatMap snd ginsts) |
213 | e5cb098c | Agata Murawska | |
214 | 05092772 | Helga Velroyen | -- | Looks up a network. If looking up by uuid fails, we look up |
215 | 05092772 | Helga Velroyen | -- by name. |
216 | 05092772 | Helga Velroyen | getNetwork :: ConfigData -> String -> ErrorResult Network |
217 | 05092772 | Helga Velroyen | getNetwork cfg name = |
218 | 05092772 | Helga Velroyen | let networks = fromContainer (configNetworks cfg) |
219 | 05092772 | Helga Velroyen | in case getItem "Network" name networks of |
220 | 05092772 | Helga Velroyen | Ok net -> Ok net |
221 | 05092772 | Helga Velroyen | Bad _ -> let by_name = M.mapKeys |
222 | 05092772 | Helga Velroyen | (fromNonEmpty . networkName . (M.!) networks) |
223 | 05092772 | Helga Velroyen | networks |
224 | 05092772 | Helga Velroyen | in getItem "Network" name by_name |
225 | 05092772 | Helga Velroyen | |
226 | eaa64cd8 | Iustin Pop | -- | Looks up an instance's primary node. |
227 | 5183e8be | Iustin Pop | getInstPrimaryNode :: ConfigData -> String -> ErrorResult Node |
228 | eaa64cd8 | Iustin Pop | getInstPrimaryNode cfg name = |
229 | 2cdaf225 | Iustin Pop | liftM instPrimaryNode (getInstance cfg name) >>= getNode cfg |
230 | eaa64cd8 | Iustin Pop | |
231 | d81ec8b7 | Iustin Pop | -- | Filters DRBD minors for a given node. |
232 | d81ec8b7 | Iustin Pop | getDrbdMinorsForNode :: String -> Disk -> [(Int, String)] |
233 | d81ec8b7 | Iustin Pop | getDrbdMinorsForNode node disk = |
234 | d81ec8b7 | Iustin Pop | let child_minors = concatMap (getDrbdMinorsForNode node) (diskChildren disk) |
235 | d81ec8b7 | Iustin Pop | this_minors = |
236 | d81ec8b7 | Iustin Pop | case diskLogicalId disk of |
237 | d81ec8b7 | Iustin Pop | LIDDrbd8 nodeA nodeB _ minorA minorB _ |
238 | d81ec8b7 | Iustin Pop | | nodeA == node -> [(minorA, nodeB)] |
239 | d81ec8b7 | Iustin Pop | | nodeB == node -> [(minorB, nodeA)] |
240 | d81ec8b7 | Iustin Pop | _ -> [] |
241 | d81ec8b7 | Iustin Pop | in this_minors ++ child_minors |
242 | d81ec8b7 | Iustin Pop | |
243 | d81ec8b7 | Iustin Pop | -- | String for primary role. |
244 | d81ec8b7 | Iustin Pop | rolePrimary :: String |
245 | d81ec8b7 | Iustin Pop | rolePrimary = "primary" |
246 | d81ec8b7 | Iustin Pop | |
247 | d81ec8b7 | Iustin Pop | -- | String for secondary role. |
248 | d81ec8b7 | Iustin Pop | roleSecondary :: String |
249 | d81ec8b7 | Iustin Pop | roleSecondary = "secondary" |
250 | d81ec8b7 | Iustin Pop | |
251 | d81ec8b7 | Iustin Pop | -- | Gets the list of DRBD minors for an instance that are related to |
252 | d81ec8b7 | Iustin Pop | -- a given node. |
253 | d81ec8b7 | Iustin Pop | getInstMinorsForNode :: String -> Instance |
254 | d81ec8b7 | Iustin Pop | -> [(String, Int, String, String, String, String)] |
255 | d81ec8b7 | Iustin Pop | getInstMinorsForNode node inst = |
256 | d81ec8b7 | Iustin Pop | let role = if node == instPrimaryNode inst |
257 | d81ec8b7 | Iustin Pop | then rolePrimary |
258 | d81ec8b7 | Iustin Pop | else roleSecondary |
259 | d81ec8b7 | Iustin Pop | iname = instName inst |
260 | d81ec8b7 | Iustin Pop | -- FIXME: the disk/ build there is hack-ish; unify this in a |
261 | d81ec8b7 | Iustin Pop | -- separate place, or reuse the iv_name (but that is deprecated on |
262 | d81ec8b7 | Iustin Pop | -- the Python side) |
263 | d81ec8b7 | Iustin Pop | in concatMap (\(idx, dsk) -> |
264 | d81ec8b7 | Iustin Pop | [(node, minor, iname, "disk/" ++ show idx, role, peer) |
265 | d81ec8b7 | Iustin Pop | | (minor, peer) <- getDrbdMinorsForNode node dsk]) . |
266 | d81ec8b7 | Iustin Pop | zip [(0::Int)..] . instDisks $ inst |
267 | d81ec8b7 | Iustin Pop | |
268 | eaa64cd8 | Iustin Pop | -- | Builds link -> ip -> instname map. |
269 | eaa64cd8 | Iustin Pop | -- |
270 | eaa64cd8 | Iustin Pop | -- TODO: improve this by splitting it into multiple independent functions: |
271 | eaa64cd8 | Iustin Pop | -- |
272 | eaa64cd8 | Iustin Pop | -- * abstract the \"fetch instance with filled params\" functionality |
273 | eaa64cd8 | Iustin Pop | -- |
274 | eaa64cd8 | Iustin Pop | -- * abstsract the [instance] -> [(nic, instance_name)] part |
275 | eaa64cd8 | Iustin Pop | -- |
276 | eaa64cd8 | Iustin Pop | -- * etc. |
277 | eaa64cd8 | Iustin Pop | buildLinkIpInstnameMap :: ConfigData -> LinkIpMap |
278 | eaa64cd8 | Iustin Pop | buildLinkIpInstnameMap cfg = |
279 | eaa64cd8 | Iustin Pop | let cluster = configCluster cfg |
280 | 84835174 | Iustin Pop | instances = M.elems . fromContainer . configInstances $ cfg |
281 | 84835174 | Iustin Pop | defparams = (M.!) (fromContainer $ clusterNicparams cluster) C.ppDefault |
282 | eaa64cd8 | Iustin Pop | nics = concatMap (\i -> [(instName i, nic) | nic <- instNics i]) |
283 | eaa64cd8 | Iustin Pop | instances |
284 | eaa64cd8 | Iustin Pop | in foldl' (\accum (iname, nic) -> |
285 | eaa64cd8 | Iustin Pop | let pparams = nicNicparams nic |
286 | b09cce64 | Iustin Pop | fparams = fillNicParams defparams pparams |
287 | eaa64cd8 | Iustin Pop | link = nicpLink fparams |
288 | eaa64cd8 | Iustin Pop | in case nicIp nic of |
289 | eaa64cd8 | Iustin Pop | Nothing -> accum |
290 | 5b11f8db | Iustin Pop | Just ip -> let oldipmap = M.findWithDefault M.empty |
291 | eaa64cd8 | Iustin Pop | link accum |
292 | eaa64cd8 | Iustin Pop | newipmap = M.insert ip iname oldipmap |
293 | eaa64cd8 | Iustin Pop | in M.insert link newipmap accum |
294 | eaa64cd8 | Iustin Pop | ) M.empty nics |
295 | da45c352 | Iustin Pop | |
296 | da45c352 | Iustin Pop | |
297 | da45c352 | Iustin Pop | -- | Returns a node's group, with optional failure if we can't find it |
298 | da45c352 | Iustin Pop | -- (configuration corrupt). |
299 | da45c352 | Iustin Pop | getGroupOfNode :: ConfigData -> Node -> Maybe NodeGroup |
300 | da45c352 | Iustin Pop | getGroupOfNode cfg node = |
301 | da45c352 | Iustin Pop | M.lookup (nodeGroup node) (fromContainer . configNodegroups $ cfg) |
302 | da45c352 | Iustin Pop | |
303 | da45c352 | Iustin Pop | -- | Returns a node's ndparams, filled. |
304 | da45c352 | Iustin Pop | getNodeNdParams :: ConfigData -> Node -> Maybe FilledNDParams |
305 | da45c352 | Iustin Pop | getNodeNdParams cfg node = do |
306 | da45c352 | Iustin Pop | group <- getGroupOfNode cfg node |
307 | da45c352 | Iustin Pop | let gparams = getGroupNdParams cfg group |
308 | da45c352 | Iustin Pop | return $ fillNDParams gparams (nodeNdparams node) |
309 | da45c352 | Iustin Pop | |
310 | da45c352 | Iustin Pop | instance NdParamObject Node where |
311 | da45c352 | Iustin Pop | getNdParamsOf = getNodeNdParams |
312 | da45c352 | Iustin Pop | |
313 | da45c352 | Iustin Pop | instance NdParamObject NodeGroup where |
314 | da45c352 | Iustin Pop | getNdParamsOf cfg = Just . getGroupNdParams cfg |
315 | da45c352 | Iustin Pop | |
316 | da45c352 | Iustin Pop | instance NdParamObject Cluster where |
317 | da45c352 | Iustin Pop | getNdParamsOf _ = Just . clusterNdparams |