root / src / Ganeti / WConfd / Ssconf.hs @ 731152ce
History | View | Annotate | Download (3.9 kB)
1 |
{-| Converts a configuration state into a Ssconf map. |
---|---|
2 |
|
3 |
As TemplateHaskell require that splices be defined in a separate |
4 |
module, we combine all the TemplateHaskell functionality that HTools |
5 |
needs in this module (except the one for unittests). |
6 |
|
7 |
-} |
8 |
|
9 |
{- |
10 |
|
11 |
Copyright (C) 2014 Google Inc. |
12 |
|
13 |
This program is free software; you can redistribute it and/or modify |
14 |
it under the terms of the GNU General Public License as published by |
15 |
the Free Software Foundation; either version 2 of the License, or |
16 |
(at your option) any later version. |
17 |
|
18 |
This program is distributed in the hope that it will be useful, but |
19 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
21 |
General Public License for more details. |
22 |
|
23 |
You should have received a copy of the GNU General Public License |
24 |
along with this program; if not, write to the Free Software |
25 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
26 |
02110-1301, USA. |
27 |
|
28 |
-} |
29 |
|
30 |
module Ganeti.WConfd.Ssconf |
31 |
( SSConf(..) |
32 |
, emptySSConf |
33 |
, mkSSConf |
34 |
) where |
35 |
|
36 |
import Control.Arrow ((&&&)) |
37 |
import Data.Foldable (Foldable(..), toList) |
38 |
import Data.List (partition) |
39 |
import qualified Data.Map as M |
40 |
|
41 |
import Ganeti.BasicTypes |
42 |
import Ganeti.Config |
43 |
import Ganeti.Constants |
44 |
import Ganeti.JSON |
45 |
import Ganeti.Objects |
46 |
import Ganeti.Ssconf |
47 |
import Ganeti.Utils |
48 |
import Ganeti.Types |
49 |
|
50 |
mkSSConf :: ConfigData -> SSConf |
51 |
mkSSConf cdata = SSConf $ M.fromList |
52 |
[ (SSClusterName, return $ clusterClusterName cluster) |
53 |
, (SSClusterTags, toList $ tagsOf cluster) |
54 |
, (SSFileStorageDir, return $ clusterFileStorageDir cluster) |
55 |
, (SSSharedFileStorageDir, return $ clusterSharedFileStorageDir cluster) |
56 |
, (SSGlusterStorageDir, return $ clusterGlusterStorageDir cluster) |
57 |
, (SSMasterCandidates, mapLines nodeName mcs) |
58 |
, (SSMasterCandidatesIps, mapLines nodePrimaryIp mcs) |
59 |
, (SSMasterCandidatesCerts, mapLines eqPair . toPairs |
60 |
. clusterCandidateCerts $ cluster) |
61 |
, (SSMasterIp, return $ clusterMasterIp cluster) |
62 |
, (SSMasterNetdev, return $ clusterMasterNetdev cluster) |
63 |
, (SSMasterNetmask, return . show $ clusterMasterNetmask cluster) |
64 |
, (SSMasterNode, return |
65 |
. genericResult (error "Master node not found") nodeName |
66 |
. getNode cdata $ clusterMasterNode cluster) |
67 |
, (SSNodeList, mapLines nodeName nodes) |
68 |
, (SSNodePrimaryIps, mapLines (spcPair . (nodeName &&& nodePrimaryIp)) |
69 |
nodes ) |
70 |
, (SSNodeSecondaryIps, mapLines (spcPair . (nodeName &&& nodeSecondaryIp)) |
71 |
nodes ) |
72 |
, (SSOfflineNodes, mapLines nodeName offline ) |
73 |
, (SSOnlineNodes, mapLines nodeName online ) |
74 |
, (SSPrimaryIpFamily, return . show . ipFamilyToRaw |
75 |
. clusterPrimaryIpFamily $ cluster) |
76 |
, (SSInstanceList, niceSort . map instName |
77 |
. toList . configInstances $ cdata) |
78 |
, (SSReleaseVersion, return releaseVersion) |
79 |
, (SSHypervisorList, mapLines hypervisorToRaw |
80 |
. clusterEnabledHypervisors $ cluster) |
81 |
, (SSMaintainNodeHealth, return . show . clusterMaintainNodeHealth |
82 |
$ cluster) |
83 |
, (SSUidPool, mapLines formatUidRange . clusterUidPool $ cluster) |
84 |
, (SSNodegroups, mapLines (spcPair . (groupUuid &&& groupName)) |
85 |
nodeGroups) |
86 |
, (SSNetworks, mapLines (spcPair . (networkUuid |
87 |
&&& (fromNonEmpty . networkName))) |
88 |
. configNetworks $ cdata) |
89 |
] |
90 |
where |
91 |
mapLines :: (Foldable f) => (a -> String) -> f a -> [String] |
92 |
mapLines f = map f . toList |
93 |
eqPair (x, y) = x ++ "=" ++ y |
94 |
spcPair (x, y) = x ++ " " ++ y |
95 |
toPairs = M.assocs . fromContainer |
96 |
|
97 |
cluster = configCluster cdata |
98 |
mcs = getMasterCandidates cdata |
99 |
nodes = niceSortKey nodeName . toList $ configNodes cdata |
100 |
(offline, online) = partition nodeOffline nodes |
101 |
nodeGroups = niceSortKey groupName . toList $ configNodegroups cdata |