root / src / Ganeti / Types.hs @ 54c7dff7
History | View | Annotate | Download (16.1 kB)
1 | 5e9deac0 | Iustin Pop | {-# LANGUAGE TemplateHaskell #-} |
---|---|---|---|
2 | 5e9deac0 | Iustin Pop | |
3 | 5e9deac0 | Iustin Pop | {-| Some common Ganeti types. |
4 | 5e9deac0 | Iustin Pop | |
5 | 5e9deac0 | Iustin Pop | This holds types common to both core work, and to htools. Types that |
6 | 5e9deac0 | Iustin Pop | are very core specific (e.g. configuration objects) should go in |
7 | 5e9deac0 | Iustin Pop | 'Ganeti.Objects', while types that are specific to htools in-memory |
8 | 5e9deac0 | Iustin Pop | representation should go into 'Ganeti.HTools.Types'. |
9 | 5e9deac0 | Iustin Pop | |
10 | 5e9deac0 | Iustin Pop | -} |
11 | 5e9deac0 | Iustin Pop | |
12 | 5e9deac0 | Iustin Pop | {- |
13 | 5e9deac0 | Iustin Pop | |
14 | 37fe56e0 | Iustin Pop | Copyright (C) 2012, 2013 Google Inc. |
15 | 5e9deac0 | Iustin Pop | |
16 | 5e9deac0 | Iustin Pop | This program is free software; you can redistribute it and/or modify |
17 | 5e9deac0 | Iustin Pop | it under the terms of the GNU General Public License as published by |
18 | 5e9deac0 | Iustin Pop | the Free Software Foundation; either version 2 of the License, or |
19 | 5e9deac0 | Iustin Pop | (at your option) any later version. |
20 | 5e9deac0 | Iustin Pop | |
21 | 5e9deac0 | Iustin Pop | This program is distributed in the hope that it will be useful, but |
22 | 5e9deac0 | Iustin Pop | WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | 5e9deac0 | Iustin Pop | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
24 | 5e9deac0 | Iustin Pop | General Public License for more details. |
25 | 5e9deac0 | Iustin Pop | |
26 | 5e9deac0 | Iustin Pop | You should have received a copy of the GNU General Public License |
27 | 5e9deac0 | Iustin Pop | along with this program; if not, write to the Free Software |
28 | 5e9deac0 | Iustin Pop | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
29 | 5e9deac0 | Iustin Pop | 02110-1301, USA. |
30 | 5e9deac0 | Iustin Pop | |
31 | 5e9deac0 | Iustin Pop | -} |
32 | 5e9deac0 | Iustin Pop | |
33 | 5e9deac0 | Iustin Pop | module Ganeti.Types |
34 | 5e9deac0 | Iustin Pop | ( AllocPolicy(..) |
35 | 5e9deac0 | Iustin Pop | , allocPolicyFromRaw |
36 | 5e9deac0 | Iustin Pop | , allocPolicyToRaw |
37 | 5e9deac0 | Iustin Pop | , InstanceStatus(..) |
38 | 5e9deac0 | Iustin Pop | , instanceStatusFromRaw |
39 | 5e9deac0 | Iustin Pop | , instanceStatusToRaw |
40 | 5e9deac0 | Iustin Pop | , DiskTemplate(..) |
41 | 5e9deac0 | Iustin Pop | , diskTemplateToRaw |
42 | 5e9deac0 | Iustin Pop | , diskTemplateFromRaw |
43 | edb5a1c8 | Iustin Pop | , NonNegative |
44 | edb5a1c8 | Iustin Pop | , fromNonNegative |
45 | edb5a1c8 | Iustin Pop | , mkNonNegative |
46 | edb5a1c8 | Iustin Pop | , Positive |
47 | edb5a1c8 | Iustin Pop | , fromPositive |
48 | edb5a1c8 | Iustin Pop | , mkPositive |
49 | c67b908a | Iustin Pop | , Negative |
50 | c67b908a | Iustin Pop | , fromNegative |
51 | c67b908a | Iustin Pop | , mkNegative |
52 | edb5a1c8 | Iustin Pop | , NonEmpty |
53 | edb5a1c8 | Iustin Pop | , fromNonEmpty |
54 | edb5a1c8 | Iustin Pop | , mkNonEmpty |
55 | 6a28e02c | Iustin Pop | , NonEmptyString |
56 | d696bbef | Iustin Pop | , MigrationMode(..) |
57 | d696bbef | Iustin Pop | , VerifyOptionalChecks(..) |
58 | d696bbef | Iustin Pop | , DdmSimple(..) |
59 | c2d3219b | Iustin Pop | , DdmFull(..) |
60 | d696bbef | Iustin Pop | , CVErrorCode(..) |
61 | d696bbef | Iustin Pop | , cVErrorCodeToRaw |
62 | 22381768 | Iustin Pop | , Hypervisor(..) |
63 | 6a28e02c | Iustin Pop | , OobCommand(..) |
64 | 48755fac | Iustin Pop | , StorageType(..) |
65 | 6a28e02c | Iustin Pop | , NodeEvacMode(..) |
66 | c65621d7 | Iustin Pop | , FileDriver(..) |
67 | 6d558717 | Iustin Pop | , InstCreateMode(..) |
68 | c2d3219b | Iustin Pop | , RebootType(..) |
69 | 398e9066 | Iustin Pop | , ExportMode(..) |
70 | a3f02317 | Iustin Pop | , IAllocatorTestDir(..) |
71 | a3f02317 | Iustin Pop | , IAllocatorMode(..) |
72 | a3f02317 | Iustin Pop | , iAllocatorModeToRaw |
73 | 497beee2 | Iustin Pop | , NICMode(..) |
74 | 497beee2 | Iustin Pop | , nICModeToRaw |
75 | 3bdbe4b3 | Dato Simó | , JobStatus(..) |
76 | 3bdbe4b3 | Dato Simó | , jobStatusToRaw |
77 | 3bdbe4b3 | Dato Simó | , jobStatusFromRaw |
78 | 6903fea0 | Iustin Pop | , FinalizedJobStatus(..) |
79 | 6903fea0 | Iustin Pop | , finalizedJobStatusToRaw |
80 | c48711d5 | Iustin Pop | , JobId |
81 | c48711d5 | Iustin Pop | , fromJobId |
82 | c48711d5 | Iustin Pop | , makeJobId |
83 | fd958a3d | Iustin Pop | , makeJobIdS |
84 | b46ba79c | Iustin Pop | , RelativeJobId |
85 | b46ba79c | Iustin Pop | , JobIdDep(..) |
86 | b46ba79c | Iustin Pop | , JobDependency(..) |
87 | b46ba79c | Iustin Pop | , OpSubmitPriority(..) |
88 | fd958a3d | Iustin Pop | , opSubmitPriorityToRaw |
89 | 37fe56e0 | Iustin Pop | , parseSubmitPriority |
90 | 37fe56e0 | Iustin Pop | , fmtSubmitPriority |
91 | 3bdbe4b3 | Dato Simó | , OpStatus(..) |
92 | 3bdbe4b3 | Dato Simó | , opStatusToRaw |
93 | 3bdbe4b3 | Dato Simó | , opStatusFromRaw |
94 | 5cd95d46 | Iustin Pop | , ELogType(..) |
95 | a59d5fa1 | Michele Tartara | , InstReasonSrc(..) |
96 | 5e9deac0 | Iustin Pop | ) where |
97 | 5e9deac0 | Iustin Pop | |
98 | b46ba79c | Iustin Pop | import Control.Monad (liftM) |
99 | edb5a1c8 | Iustin Pop | import qualified Text.JSON as JSON |
100 | b46ba79c | Iustin Pop | import Text.JSON (JSON, readJSON, showJSON) |
101 | c48711d5 | Iustin Pop | import Data.Ratio (numerator, denominator) |
102 | edb5a1c8 | Iustin Pop | |
103 | 5e9deac0 | Iustin Pop | import qualified Ganeti.Constants as C |
104 | 5e9deac0 | Iustin Pop | import qualified Ganeti.THH as THH |
105 | edc1acde | Iustin Pop | import Ganeti.JSON |
106 | c48711d5 | Iustin Pop | import Ganeti.Utils |
107 | 5e9deac0 | Iustin Pop | |
108 | edb5a1c8 | Iustin Pop | -- * Generic types |
109 | edb5a1c8 | Iustin Pop | |
110 | edb5a1c8 | Iustin Pop | -- | Type that holds a non-negative value. |
111 | edb5a1c8 | Iustin Pop | newtype NonNegative a = NonNegative { fromNonNegative :: a } |
112 | 139c0683 | Iustin Pop | deriving (Show, Eq) |
113 | edb5a1c8 | Iustin Pop | |
114 | edb5a1c8 | Iustin Pop | -- | Smart constructor for 'NonNegative'. |
115 | edb5a1c8 | Iustin Pop | mkNonNegative :: (Monad m, Num a, Ord a, Show a) => a -> m (NonNegative a) |
116 | edb5a1c8 | Iustin Pop | mkNonNegative i | i >= 0 = return (NonNegative i) |
117 | edb5a1c8 | Iustin Pop | | otherwise = fail $ "Invalid value for non-negative type '" ++ |
118 | edb5a1c8 | Iustin Pop | show i ++ "'" |
119 | edb5a1c8 | Iustin Pop | |
120 | edb5a1c8 | Iustin Pop | instance (JSON.JSON a, Num a, Ord a, Show a) => JSON.JSON (NonNegative a) where |
121 | edb5a1c8 | Iustin Pop | showJSON = JSON.showJSON . fromNonNegative |
122 | edb5a1c8 | Iustin Pop | readJSON v = JSON.readJSON v >>= mkNonNegative |
123 | edb5a1c8 | Iustin Pop | |
124 | edb5a1c8 | Iustin Pop | -- | Type that holds a positive value. |
125 | edb5a1c8 | Iustin Pop | newtype Positive a = Positive { fromPositive :: a } |
126 | 139c0683 | Iustin Pop | deriving (Show, Eq) |
127 | edb5a1c8 | Iustin Pop | |
128 | edb5a1c8 | Iustin Pop | -- | Smart constructor for 'Positive'. |
129 | edb5a1c8 | Iustin Pop | mkPositive :: (Monad m, Num a, Ord a, Show a) => a -> m (Positive a) |
130 | edb5a1c8 | Iustin Pop | mkPositive i | i > 0 = return (Positive i) |
131 | edb5a1c8 | Iustin Pop | | otherwise = fail $ "Invalid value for positive type '" ++ |
132 | edb5a1c8 | Iustin Pop | show i ++ "'" |
133 | edb5a1c8 | Iustin Pop | |
134 | edb5a1c8 | Iustin Pop | instance (JSON.JSON a, Num a, Ord a, Show a) => JSON.JSON (Positive a) where |
135 | edb5a1c8 | Iustin Pop | showJSON = JSON.showJSON . fromPositive |
136 | edb5a1c8 | Iustin Pop | readJSON v = JSON.readJSON v >>= mkPositive |
137 | edb5a1c8 | Iustin Pop | |
138 | c67b908a | Iustin Pop | -- | Type that holds a negative value. |
139 | c67b908a | Iustin Pop | newtype Negative a = Negative { fromNegative :: a } |
140 | c67b908a | Iustin Pop | deriving (Show, Eq) |
141 | c67b908a | Iustin Pop | |
142 | c67b908a | Iustin Pop | -- | Smart constructor for 'Negative'. |
143 | c67b908a | Iustin Pop | mkNegative :: (Monad m, Num a, Ord a, Show a) => a -> m (Negative a) |
144 | c67b908a | Iustin Pop | mkNegative i | i < 0 = return (Negative i) |
145 | c67b908a | Iustin Pop | | otherwise = fail $ "Invalid value for negative type '" ++ |
146 | c67b908a | Iustin Pop | show i ++ "'" |
147 | c67b908a | Iustin Pop | |
148 | c67b908a | Iustin Pop | instance (JSON.JSON a, Num a, Ord a, Show a) => JSON.JSON (Negative a) where |
149 | c67b908a | Iustin Pop | showJSON = JSON.showJSON . fromNegative |
150 | c67b908a | Iustin Pop | readJSON v = JSON.readJSON v >>= mkNegative |
151 | c67b908a | Iustin Pop | |
152 | edb5a1c8 | Iustin Pop | -- | Type that holds a non-null list. |
153 | edb5a1c8 | Iustin Pop | newtype NonEmpty a = NonEmpty { fromNonEmpty :: [a] } |
154 | 139c0683 | Iustin Pop | deriving (Show, Eq) |
155 | edb5a1c8 | Iustin Pop | |
156 | edb5a1c8 | Iustin Pop | -- | Smart constructor for 'NonEmpty'. |
157 | edb5a1c8 | Iustin Pop | mkNonEmpty :: (Monad m) => [a] -> m (NonEmpty a) |
158 | edb5a1c8 | Iustin Pop | mkNonEmpty [] = fail "Received empty value for non-empty list" |
159 | edb5a1c8 | Iustin Pop | mkNonEmpty xs = return (NonEmpty xs) |
160 | edb5a1c8 | Iustin Pop | |
161 | edb5a1c8 | Iustin Pop | instance (JSON.JSON a) => JSON.JSON (NonEmpty a) where |
162 | edb5a1c8 | Iustin Pop | showJSON = JSON.showJSON . fromNonEmpty |
163 | edb5a1c8 | Iustin Pop | readJSON v = JSON.readJSON v >>= mkNonEmpty |
164 | edb5a1c8 | Iustin Pop | |
165 | 6a28e02c | Iustin Pop | -- | A simple type alias for non-empty strings. |
166 | 6a28e02c | Iustin Pop | type NonEmptyString = NonEmpty Char |
167 | 6a28e02c | Iustin Pop | |
168 | edb5a1c8 | Iustin Pop | -- * Ganeti types |
169 | edb5a1c8 | Iustin Pop | |
170 | 5e9deac0 | Iustin Pop | -- | Instance disk template type. |
171 | 5e9deac0 | Iustin Pop | $(THH.declareSADT "DiskTemplate" |
172 | 5e9deac0 | Iustin Pop | [ ("DTDiskless", 'C.dtDiskless) |
173 | 5e9deac0 | Iustin Pop | , ("DTFile", 'C.dtFile) |
174 | 5e9deac0 | Iustin Pop | , ("DTSharedFile", 'C.dtSharedFile) |
175 | 5e9deac0 | Iustin Pop | , ("DTPlain", 'C.dtPlain) |
176 | 5e9deac0 | Iustin Pop | , ("DTBlock", 'C.dtBlock) |
177 | 5e9deac0 | Iustin Pop | , ("DTDrbd8", 'C.dtDrbd8) |
178 | 5e9deac0 | Iustin Pop | , ("DTRbd", 'C.dtRbd) |
179 | 277a2ec9 | Constantinos Venetsanopoulos | , ("DTExt", 'C.dtExt) |
180 | 5e9deac0 | Iustin Pop | ]) |
181 | 5e9deac0 | Iustin Pop | $(THH.makeJSONInstance ''DiskTemplate) |
182 | 5e9deac0 | Iustin Pop | |
183 | edc1acde | Iustin Pop | instance HasStringRepr DiskTemplate where |
184 | edc1acde | Iustin Pop | fromStringRepr = diskTemplateFromRaw |
185 | edc1acde | Iustin Pop | toStringRepr = diskTemplateToRaw |
186 | edc1acde | Iustin Pop | |
187 | 5e9deac0 | Iustin Pop | -- | The Group allocation policy type. |
188 | 5e9deac0 | Iustin Pop | -- |
189 | 5e9deac0 | Iustin Pop | -- Note that the order of constructors is important as the automatic |
190 | 5e9deac0 | Iustin Pop | -- Ord instance will order them in the order they are defined, so when |
191 | 5e9deac0 | Iustin Pop | -- changing this data type be careful about the interaction with the |
192 | 5e9deac0 | Iustin Pop | -- desired sorting order. |
193 | 5e9deac0 | Iustin Pop | $(THH.declareSADT "AllocPolicy" |
194 | 5e9deac0 | Iustin Pop | [ ("AllocPreferred", 'C.allocPolicyPreferred) |
195 | 5e9deac0 | Iustin Pop | , ("AllocLastResort", 'C.allocPolicyLastResort) |
196 | 5e9deac0 | Iustin Pop | , ("AllocUnallocable", 'C.allocPolicyUnallocable) |
197 | 5e9deac0 | Iustin Pop | ]) |
198 | 5e9deac0 | Iustin Pop | $(THH.makeJSONInstance ''AllocPolicy) |
199 | 5e9deac0 | Iustin Pop | |
200 | 5e9deac0 | Iustin Pop | -- | The Instance real state type. FIXME: this could be improved to |
201 | 5e9deac0 | Iustin Pop | -- just wrap a /NormalState AdminStatus | ErrorState ErrorCondition/. |
202 | 5e9deac0 | Iustin Pop | $(THH.declareSADT "InstanceStatus" |
203 | 5e9deac0 | Iustin Pop | [ ("StatusDown", 'C.inststAdmindown) |
204 | 5e9deac0 | Iustin Pop | , ("StatusOffline", 'C.inststAdminoffline) |
205 | 5e9deac0 | Iustin Pop | , ("ErrorDown", 'C.inststErrordown) |
206 | 5e9deac0 | Iustin Pop | , ("ErrorUp", 'C.inststErrorup) |
207 | 5e9deac0 | Iustin Pop | , ("NodeDown", 'C.inststNodedown) |
208 | 5e9deac0 | Iustin Pop | , ("NodeOffline", 'C.inststNodeoffline) |
209 | 5e9deac0 | Iustin Pop | , ("Running", 'C.inststRunning) |
210 | 5e9deac0 | Iustin Pop | , ("WrongNode", 'C.inststWrongnode) |
211 | 5e9deac0 | Iustin Pop | ]) |
212 | 5e9deac0 | Iustin Pop | $(THH.makeJSONInstance ''InstanceStatus) |
213 | d696bbef | Iustin Pop | |
214 | d696bbef | Iustin Pop | -- | Migration mode. |
215 | d696bbef | Iustin Pop | $(THH.declareSADT "MigrationMode" |
216 | d696bbef | Iustin Pop | [ ("MigrationLive", 'C.htMigrationLive) |
217 | d696bbef | Iustin Pop | , ("MigrationNonLive", 'C.htMigrationNonlive) |
218 | d696bbef | Iustin Pop | ]) |
219 | d696bbef | Iustin Pop | $(THH.makeJSONInstance ''MigrationMode) |
220 | d696bbef | Iustin Pop | |
221 | d696bbef | Iustin Pop | -- | Verify optional checks. |
222 | d696bbef | Iustin Pop | $(THH.declareSADT "VerifyOptionalChecks" |
223 | d696bbef | Iustin Pop | [ ("VerifyNPlusOneMem", 'C.verifyNplusoneMem) |
224 | d696bbef | Iustin Pop | ]) |
225 | d696bbef | Iustin Pop | $(THH.makeJSONInstance ''VerifyOptionalChecks) |
226 | d696bbef | Iustin Pop | |
227 | d696bbef | Iustin Pop | -- | Cluster verify error codes. |
228 | d696bbef | Iustin Pop | $(THH.declareSADT "CVErrorCode" |
229 | d696bbef | Iustin Pop | [ ("CvECLUSTERCFG", 'C.cvEclustercfgCode) |
230 | d696bbef | Iustin Pop | , ("CvECLUSTERCERT", 'C.cvEclustercertCode) |
231 | d696bbef | Iustin Pop | , ("CvECLUSTERFILECHECK", 'C.cvEclusterfilecheckCode) |
232 | d696bbef | Iustin Pop | , ("CvECLUSTERDANGLINGNODES", 'C.cvEclusterdanglingnodesCode) |
233 | d696bbef | Iustin Pop | , ("CvECLUSTERDANGLINGINST", 'C.cvEclusterdanglinginstCode) |
234 | d696bbef | Iustin Pop | , ("CvEINSTANCEBADNODE", 'C.cvEinstancebadnodeCode) |
235 | d696bbef | Iustin Pop | , ("CvEINSTANCEDOWN", 'C.cvEinstancedownCode) |
236 | d696bbef | Iustin Pop | , ("CvEINSTANCELAYOUT", 'C.cvEinstancelayoutCode) |
237 | d696bbef | Iustin Pop | , ("CvEINSTANCEMISSINGDISK", 'C.cvEinstancemissingdiskCode) |
238 | d696bbef | Iustin Pop | , ("CvEINSTANCEFAULTYDISK", 'C.cvEinstancefaultydiskCode) |
239 | d696bbef | Iustin Pop | , ("CvEINSTANCEWRONGNODE", 'C.cvEinstancewrongnodeCode) |
240 | d696bbef | Iustin Pop | , ("CvEINSTANCESPLITGROUPS", 'C.cvEinstancesplitgroupsCode) |
241 | d696bbef | Iustin Pop | , ("CvEINSTANCEPOLICY", 'C.cvEinstancepolicyCode) |
242 | d696bbef | Iustin Pop | , ("CvENODEDRBD", 'C.cvEnodedrbdCode) |
243 | d696bbef | Iustin Pop | , ("CvENODEDRBDHELPER", 'C.cvEnodedrbdhelperCode) |
244 | d696bbef | Iustin Pop | , ("CvENODEFILECHECK", 'C.cvEnodefilecheckCode) |
245 | d696bbef | Iustin Pop | , ("CvENODEHOOKS", 'C.cvEnodehooksCode) |
246 | d696bbef | Iustin Pop | , ("CvENODEHV", 'C.cvEnodehvCode) |
247 | d696bbef | Iustin Pop | , ("CvENODELVM", 'C.cvEnodelvmCode) |
248 | d696bbef | Iustin Pop | , ("CvENODEN1", 'C.cvEnoden1Code) |
249 | d696bbef | Iustin Pop | , ("CvENODENET", 'C.cvEnodenetCode) |
250 | d696bbef | Iustin Pop | , ("CvENODEOS", 'C.cvEnodeosCode) |
251 | d696bbef | Iustin Pop | , ("CvENODEORPHANINSTANCE", 'C.cvEnodeorphaninstanceCode) |
252 | d696bbef | Iustin Pop | , ("CvENODEORPHANLV", 'C.cvEnodeorphanlvCode) |
253 | d696bbef | Iustin Pop | , ("CvENODERPC", 'C.cvEnoderpcCode) |
254 | d696bbef | Iustin Pop | , ("CvENODESSH", 'C.cvEnodesshCode) |
255 | d696bbef | Iustin Pop | , ("CvENODEVERSION", 'C.cvEnodeversionCode) |
256 | d696bbef | Iustin Pop | , ("CvENODESETUP", 'C.cvEnodesetupCode) |
257 | d696bbef | Iustin Pop | , ("CvENODETIME", 'C.cvEnodetimeCode) |
258 | d696bbef | Iustin Pop | , ("CvENODEOOBPATH", 'C.cvEnodeoobpathCode) |
259 | d696bbef | Iustin Pop | , ("CvENODEUSERSCRIPTS", 'C.cvEnodeuserscriptsCode) |
260 | d696bbef | Iustin Pop | , ("CvENODEFILESTORAGEPATHS", 'C.cvEnodefilestoragepathsCode) |
261 | d696bbef | Iustin Pop | ]) |
262 | d696bbef | Iustin Pop | $(THH.makeJSONInstance ''CVErrorCode) |
263 | d696bbef | Iustin Pop | |
264 | d696bbef | Iustin Pop | -- | Dynamic device modification, just add\/remove version. |
265 | d696bbef | Iustin Pop | $(THH.declareSADT "DdmSimple" |
266 | d696bbef | Iustin Pop | [ ("DdmSimpleAdd", 'C.ddmAdd) |
267 | d696bbef | Iustin Pop | , ("DdmSimpleRemove", 'C.ddmRemove) |
268 | d696bbef | Iustin Pop | ]) |
269 | d696bbef | Iustin Pop | $(THH.makeJSONInstance ''DdmSimple) |
270 | 22381768 | Iustin Pop | |
271 | c2d3219b | Iustin Pop | -- | Dynamic device modification, all operations version. |
272 | c2d3219b | Iustin Pop | $(THH.declareSADT "DdmFull" |
273 | c2d3219b | Iustin Pop | [ ("DdmFullAdd", 'C.ddmAdd) |
274 | c2d3219b | Iustin Pop | , ("DdmFullRemove", 'C.ddmRemove) |
275 | c2d3219b | Iustin Pop | , ("DdmFullModify", 'C.ddmModify) |
276 | c2d3219b | Iustin Pop | ]) |
277 | c2d3219b | Iustin Pop | $(THH.makeJSONInstance ''DdmFull) |
278 | c2d3219b | Iustin Pop | |
279 | 22381768 | Iustin Pop | -- | Hypervisor type definitions. |
280 | 22381768 | Iustin Pop | $(THH.declareSADT "Hypervisor" |
281 | 22381768 | Iustin Pop | [ ( "Kvm", 'C.htKvm ) |
282 | 22381768 | Iustin Pop | , ( "XenPvm", 'C.htXenPvm ) |
283 | 22381768 | Iustin Pop | , ( "Chroot", 'C.htChroot ) |
284 | 22381768 | Iustin Pop | , ( "XenHvm", 'C.htXenHvm ) |
285 | 22381768 | Iustin Pop | , ( "Lxc", 'C.htLxc ) |
286 | 22381768 | Iustin Pop | , ( "Fake", 'C.htFake ) |
287 | 22381768 | Iustin Pop | ]) |
288 | 22381768 | Iustin Pop | $(THH.makeJSONInstance ''Hypervisor) |
289 | 48755fac | Iustin Pop | |
290 | 6a28e02c | Iustin Pop | -- | Oob command type. |
291 | 6a28e02c | Iustin Pop | $(THH.declareSADT "OobCommand" |
292 | 6a28e02c | Iustin Pop | [ ("OobHealth", 'C.oobHealth) |
293 | 6a28e02c | Iustin Pop | , ("OobPowerCycle", 'C.oobPowerCycle) |
294 | 6a28e02c | Iustin Pop | , ("OobPowerOff", 'C.oobPowerOff) |
295 | 6a28e02c | Iustin Pop | , ("OobPowerOn", 'C.oobPowerOn) |
296 | 6a28e02c | Iustin Pop | , ("OobPowerStatus", 'C.oobPowerStatus) |
297 | 6a28e02c | Iustin Pop | ]) |
298 | 6a28e02c | Iustin Pop | $(THH.makeJSONInstance ''OobCommand) |
299 | 6a28e02c | Iustin Pop | |
300 | 48755fac | Iustin Pop | -- | Storage type. |
301 | 48755fac | Iustin Pop | $(THH.declareSADT "StorageType" |
302 | 48755fac | Iustin Pop | [ ("StorageFile", 'C.stFile) |
303 | 48755fac | Iustin Pop | , ("StorageLvmPv", 'C.stLvmPv) |
304 | 48755fac | Iustin Pop | , ("StorageLvmVg", 'C.stLvmVg) |
305 | d0de443e | Helga Velroyen | , ("StorageDiskless", 'C.stDiskless) |
306 | d0de443e | Helga Velroyen | , ("StorageSharedFile", 'C.stSharedFile) |
307 | d0de443e | Helga Velroyen | , ("StorageBlock", 'C.stBlock) |
308 | d0de443e | Helga Velroyen | , ("StorageRados", 'C.stRados) |
309 | d0de443e | Helga Velroyen | , ("StorageExt", 'C.stExt) |
310 | 48755fac | Iustin Pop | ]) |
311 | 48755fac | Iustin Pop | $(THH.makeJSONInstance ''StorageType) |
312 | 6a28e02c | Iustin Pop | |
313 | 6a28e02c | Iustin Pop | -- | Node evac modes. |
314 | 6a28e02c | Iustin Pop | $(THH.declareSADT "NodeEvacMode" |
315 | 6a28e02c | Iustin Pop | [ ("NEvacPrimary", 'C.iallocatorNevacPri) |
316 | 6a28e02c | Iustin Pop | , ("NEvacSecondary", 'C.iallocatorNevacSec) |
317 | 6a28e02c | Iustin Pop | , ("NEvacAll", 'C.iallocatorNevacAll) |
318 | 6a28e02c | Iustin Pop | ]) |
319 | 6a28e02c | Iustin Pop | $(THH.makeJSONInstance ''NodeEvacMode) |
320 | c65621d7 | Iustin Pop | |
321 | c65621d7 | Iustin Pop | -- | The file driver type. |
322 | c65621d7 | Iustin Pop | $(THH.declareSADT "FileDriver" |
323 | c65621d7 | Iustin Pop | [ ("FileLoop", 'C.fdLoop) |
324 | c65621d7 | Iustin Pop | , ("FileBlktap", 'C.fdBlktap) |
325 | c65621d7 | Iustin Pop | ]) |
326 | c65621d7 | Iustin Pop | $(THH.makeJSONInstance ''FileDriver) |
327 | 6d558717 | Iustin Pop | |
328 | 6d558717 | Iustin Pop | -- | The instance create mode. |
329 | 6d558717 | Iustin Pop | $(THH.declareSADT "InstCreateMode" |
330 | 6d558717 | Iustin Pop | [ ("InstCreate", 'C.instanceCreate) |
331 | 6d558717 | Iustin Pop | , ("InstImport", 'C.instanceImport) |
332 | 6d558717 | Iustin Pop | , ("InstRemoteImport", 'C.instanceRemoteImport) |
333 | 6d558717 | Iustin Pop | ]) |
334 | 6d558717 | Iustin Pop | $(THH.makeJSONInstance ''InstCreateMode) |
335 | c2d3219b | Iustin Pop | |
336 | c2d3219b | Iustin Pop | -- | Reboot type. |
337 | c2d3219b | Iustin Pop | $(THH.declareSADT "RebootType" |
338 | c2d3219b | Iustin Pop | [ ("RebootSoft", 'C.instanceRebootSoft) |
339 | c2d3219b | Iustin Pop | , ("RebootHard", 'C.instanceRebootHard) |
340 | c2d3219b | Iustin Pop | , ("RebootFull", 'C.instanceRebootFull) |
341 | c2d3219b | Iustin Pop | ]) |
342 | c2d3219b | Iustin Pop | $(THH.makeJSONInstance ''RebootType) |
343 | 398e9066 | Iustin Pop | |
344 | 398e9066 | Iustin Pop | -- | Export modes. |
345 | 398e9066 | Iustin Pop | $(THH.declareSADT "ExportMode" |
346 | 398e9066 | Iustin Pop | [ ("ExportModeLocal", 'C.exportModeLocal) |
347 | 398e9066 | Iustin Pop | , ("ExportModeRemove", 'C.exportModeRemote) |
348 | 398e9066 | Iustin Pop | ]) |
349 | 398e9066 | Iustin Pop | $(THH.makeJSONInstance ''ExportMode) |
350 | a3f02317 | Iustin Pop | |
351 | a3f02317 | Iustin Pop | -- | IAllocator run types (OpTestIAllocator). |
352 | a3f02317 | Iustin Pop | $(THH.declareSADT "IAllocatorTestDir" |
353 | a3f02317 | Iustin Pop | [ ("IAllocatorDirIn", 'C.iallocatorDirIn) |
354 | a3f02317 | Iustin Pop | , ("IAllocatorDirOut", 'C.iallocatorDirOut) |
355 | a3f02317 | Iustin Pop | ]) |
356 | a3f02317 | Iustin Pop | $(THH.makeJSONInstance ''IAllocatorTestDir) |
357 | a3f02317 | Iustin Pop | |
358 | a3f02317 | Iustin Pop | -- | IAllocator mode. FIXME: use this in "HTools.Backend.IAlloc". |
359 | a3f02317 | Iustin Pop | $(THH.declareSADT "IAllocatorMode" |
360 | a3f02317 | Iustin Pop | [ ("IAllocatorAlloc", 'C.iallocatorModeAlloc) |
361 | a3f02317 | Iustin Pop | , ("IAllocatorMultiAlloc", 'C.iallocatorModeMultiAlloc) |
362 | a3f02317 | Iustin Pop | , ("IAllocatorReloc", 'C.iallocatorModeReloc) |
363 | a3f02317 | Iustin Pop | , ("IAllocatorNodeEvac", 'C.iallocatorModeNodeEvac) |
364 | a3f02317 | Iustin Pop | , ("IAllocatorChangeGroup", 'C.iallocatorModeChgGroup) |
365 | a3f02317 | Iustin Pop | ]) |
366 | a3f02317 | Iustin Pop | $(THH.makeJSONInstance ''IAllocatorMode) |
367 | 497beee2 | Iustin Pop | |
368 | 3673a326 | Helga Velroyen | -- | Network mode. |
369 | 497beee2 | Iustin Pop | $(THH.declareSADT "NICMode" |
370 | 497beee2 | Iustin Pop | [ ("NMBridged", 'C.nicModeBridged) |
371 | 497beee2 | Iustin Pop | , ("NMRouted", 'C.nicModeRouted) |
372 | 57fb6fcb | Guido Trotter | , ("NMOvs", 'C.nicModeOvs) |
373 | 497beee2 | Iustin Pop | ]) |
374 | 497beee2 | Iustin Pop | $(THH.makeJSONInstance ''NICMode) |
375 | 6903fea0 | Iustin Pop | |
376 | 3bdbe4b3 | Dato Simó | -- | The JobStatus data type. Note that this is ordered especially |
377 | 3bdbe4b3 | Dato Simó | -- such that greater\/lesser comparison on values of this type makes |
378 | 3bdbe4b3 | Dato Simó | -- sense. |
379 | 3bdbe4b3 | Dato Simó | $(THH.declareSADT "JobStatus" |
380 | 3bdbe4b3 | Dato Simó | [ ("JOB_STATUS_QUEUED", 'C.jobStatusQueued) |
381 | 3bdbe4b3 | Dato Simó | , ("JOB_STATUS_WAITING", 'C.jobStatusWaiting) |
382 | 3bdbe4b3 | Dato Simó | , ("JOB_STATUS_CANCELING", 'C.jobStatusCanceling) |
383 | 3bdbe4b3 | Dato Simó | , ("JOB_STATUS_RUNNING", 'C.jobStatusRunning) |
384 | 3bdbe4b3 | Dato Simó | , ("JOB_STATUS_CANCELED", 'C.jobStatusCanceled) |
385 | 3bdbe4b3 | Dato Simó | , ("JOB_STATUS_SUCCESS", 'C.jobStatusSuccess) |
386 | 3bdbe4b3 | Dato Simó | , ("JOB_STATUS_ERROR", 'C.jobStatusError) |
387 | 3bdbe4b3 | Dato Simó | ]) |
388 | 3bdbe4b3 | Dato Simó | $(THH.makeJSONInstance ''JobStatus) |
389 | 3bdbe4b3 | Dato Simó | |
390 | 6903fea0 | Iustin Pop | -- | Finalized job status. |
391 | 6903fea0 | Iustin Pop | $(THH.declareSADT "FinalizedJobStatus" |
392 | 6903fea0 | Iustin Pop | [ ("JobStatusCanceled", 'C.jobStatusCanceled) |
393 | 6903fea0 | Iustin Pop | , ("JobStatusSuccessful", 'C.jobStatusSuccess) |
394 | 6903fea0 | Iustin Pop | , ("JobStatusFailed", 'C.jobStatusError) |
395 | 6903fea0 | Iustin Pop | ]) |
396 | 6903fea0 | Iustin Pop | $(THH.makeJSONInstance ''FinalizedJobStatus) |
397 | c48711d5 | Iustin Pop | |
398 | c48711d5 | Iustin Pop | -- | The Ganeti job type. |
399 | c48711d5 | Iustin Pop | newtype JobId = JobId { fromJobId :: Int } |
400 | c48711d5 | Iustin Pop | deriving (Show, Eq) |
401 | c48711d5 | Iustin Pop | |
402 | c48711d5 | Iustin Pop | -- | Builds a job ID. |
403 | c48711d5 | Iustin Pop | makeJobId :: (Monad m) => Int -> m JobId |
404 | c48711d5 | Iustin Pop | makeJobId i | i >= 0 = return $ JobId i |
405 | c48711d5 | Iustin Pop | | otherwise = fail $ "Invalid value for job ID ' " ++ show i ++ "'" |
406 | c48711d5 | Iustin Pop | |
407 | fd958a3d | Iustin Pop | -- | Builds a job ID from a string. |
408 | fd958a3d | Iustin Pop | makeJobIdS :: (Monad m) => String -> m JobId |
409 | fd958a3d | Iustin Pop | makeJobIdS s = tryRead "parsing job id" s >>= makeJobId |
410 | fd958a3d | Iustin Pop | |
411 | c48711d5 | Iustin Pop | -- | Parses a job ID. |
412 | c48711d5 | Iustin Pop | parseJobId :: (Monad m) => JSON.JSValue -> m JobId |
413 | fd958a3d | Iustin Pop | parseJobId (JSON.JSString x) = makeJobIdS $ JSON.fromJSString x |
414 | c48711d5 | Iustin Pop | parseJobId (JSON.JSRational _ x) = |
415 | c48711d5 | Iustin Pop | if denominator x /= 1 |
416 | c48711d5 | Iustin Pop | then fail $ "Got fractional job ID from master daemon?! Value:" ++ show x |
417 | c48711d5 | Iustin Pop | -- FIXME: potential integer overflow here on 32-bit platforms |
418 | c48711d5 | Iustin Pop | else makeJobId . fromIntegral . numerator $ x |
419 | c48711d5 | Iustin Pop | parseJobId x = fail $ "Wrong type/value for job id: " ++ show x |
420 | c48711d5 | Iustin Pop | |
421 | c48711d5 | Iustin Pop | instance JSON.JSON JobId where |
422 | c48711d5 | Iustin Pop | showJSON = JSON.showJSON . fromJobId |
423 | c48711d5 | Iustin Pop | readJSON = parseJobId |
424 | b46ba79c | Iustin Pop | |
425 | b46ba79c | Iustin Pop | -- | Relative job ID type alias. |
426 | b46ba79c | Iustin Pop | type RelativeJobId = Negative Int |
427 | b46ba79c | Iustin Pop | |
428 | b46ba79c | Iustin Pop | -- | Job ID dependency. |
429 | b46ba79c | Iustin Pop | data JobIdDep = JobDepRelative RelativeJobId |
430 | b46ba79c | Iustin Pop | | JobDepAbsolute JobId |
431 | b46ba79c | Iustin Pop | deriving (Show, Eq) |
432 | b46ba79c | Iustin Pop | |
433 | b46ba79c | Iustin Pop | instance JSON.JSON JobIdDep where |
434 | b46ba79c | Iustin Pop | showJSON (JobDepRelative i) = showJSON i |
435 | b46ba79c | Iustin Pop | showJSON (JobDepAbsolute i) = showJSON i |
436 | b46ba79c | Iustin Pop | readJSON v = |
437 | b46ba79c | Iustin Pop | case JSON.readJSON v::JSON.Result (Negative Int) of |
438 | b46ba79c | Iustin Pop | -- first try relative dependency, usually most common |
439 | b46ba79c | Iustin Pop | JSON.Ok r -> return $ JobDepRelative r |
440 | 77d43564 | Iustin Pop | JSON.Error _ -> liftM JobDepAbsolute (parseJobId v) |
441 | b46ba79c | Iustin Pop | |
442 | b46ba79c | Iustin Pop | -- | Job Dependency type. |
443 | b46ba79c | Iustin Pop | data JobDependency = JobDependency JobIdDep [FinalizedJobStatus] |
444 | b46ba79c | Iustin Pop | deriving (Show, Eq) |
445 | b46ba79c | Iustin Pop | |
446 | b46ba79c | Iustin Pop | instance JSON JobDependency where |
447 | b46ba79c | Iustin Pop | showJSON (JobDependency dep status) = showJSON (dep, status) |
448 | b46ba79c | Iustin Pop | readJSON = liftM (uncurry JobDependency) . readJSON |
449 | b46ba79c | Iustin Pop | |
450 | b46ba79c | Iustin Pop | -- | Valid opcode priorities for submit. |
451 | b46ba79c | Iustin Pop | $(THH.declareIADT "OpSubmitPriority" |
452 | b46ba79c | Iustin Pop | [ ("OpPrioLow", 'C.opPrioLow) |
453 | b46ba79c | Iustin Pop | , ("OpPrioNormal", 'C.opPrioNormal) |
454 | b46ba79c | Iustin Pop | , ("OpPrioHigh", 'C.opPrioHigh) |
455 | b46ba79c | Iustin Pop | ]) |
456 | b46ba79c | Iustin Pop | $(THH.makeJSONInstance ''OpSubmitPriority) |
457 | 3bdbe4b3 | Dato Simó | |
458 | 37fe56e0 | Iustin Pop | -- | Parse submit priorities from a string. |
459 | 37fe56e0 | Iustin Pop | parseSubmitPriority :: (Monad m) => String -> m OpSubmitPriority |
460 | 37fe56e0 | Iustin Pop | parseSubmitPriority "low" = return OpPrioLow |
461 | 37fe56e0 | Iustin Pop | parseSubmitPriority "normal" = return OpPrioNormal |
462 | 37fe56e0 | Iustin Pop | parseSubmitPriority "high" = return OpPrioHigh |
463 | 37fe56e0 | Iustin Pop | parseSubmitPriority str = fail $ "Unknown priority '" ++ str ++ "'" |
464 | 37fe56e0 | Iustin Pop | |
465 | 37fe56e0 | Iustin Pop | -- | Format a submit priority as string. |
466 | 37fe56e0 | Iustin Pop | fmtSubmitPriority :: OpSubmitPriority -> String |
467 | 37fe56e0 | Iustin Pop | fmtSubmitPriority OpPrioLow = "low" |
468 | 37fe56e0 | Iustin Pop | fmtSubmitPriority OpPrioNormal = "normal" |
469 | 37fe56e0 | Iustin Pop | fmtSubmitPriority OpPrioHigh = "high" |
470 | 37fe56e0 | Iustin Pop | |
471 | 3bdbe4b3 | Dato Simó | -- | Our ADT for the OpCode status at runtime (while in a job). |
472 | 3bdbe4b3 | Dato Simó | $(THH.declareSADT "OpStatus" |
473 | 5cd95d46 | Iustin Pop | [ ("OP_STATUS_QUEUED", 'C.opStatusQueued) |
474 | 5cd95d46 | Iustin Pop | , ("OP_STATUS_WAITING", 'C.opStatusWaiting) |
475 | 5cd95d46 | Iustin Pop | , ("OP_STATUS_CANCELING", 'C.opStatusCanceling) |
476 | 5cd95d46 | Iustin Pop | , ("OP_STATUS_RUNNING", 'C.opStatusRunning) |
477 | 5cd95d46 | Iustin Pop | , ("OP_STATUS_CANCELED", 'C.opStatusCanceled) |
478 | 5cd95d46 | Iustin Pop | , ("OP_STATUS_SUCCESS", 'C.opStatusSuccess) |
479 | 5cd95d46 | Iustin Pop | , ("OP_STATUS_ERROR", 'C.opStatusError) |
480 | 5cd95d46 | Iustin Pop | ]) |
481 | 3bdbe4b3 | Dato Simó | $(THH.makeJSONInstance ''OpStatus) |
482 | 5cd95d46 | Iustin Pop | |
483 | 5cd95d46 | Iustin Pop | -- | Type for the job message type. |
484 | 5cd95d46 | Iustin Pop | $(THH.declareSADT "ELogType" |
485 | 5cd95d46 | Iustin Pop | [ ("ELogMessage", 'C.elogMessage) |
486 | 5cd95d46 | Iustin Pop | , ("ELogRemoteImport", 'C.elogRemoteImport) |
487 | 5cd95d46 | Iustin Pop | , ("ELogJqueueTest", 'C.elogJqueueTest) |
488 | 5cd95d46 | Iustin Pop | ]) |
489 | 5cd95d46 | Iustin Pop | $(THH.makeJSONInstance ''ELogType) |
490 | a59d5fa1 | Michele Tartara | |
491 | a59d5fa1 | Michele Tartara | -- | Type for the source of the state change of instances. |
492 | a59d5fa1 | Michele Tartara | $(THH.declareSADT "InstReasonSrc" |
493 | a59d5fa1 | Michele Tartara | [ ("IRSCli", 'C.instanceReasonSourceCli) |
494 | a59d5fa1 | Michele Tartara | , ("IRSRapi", 'C.instanceReasonSourceRapi) |
495 | a59d5fa1 | Michele Tartara | ]) |
496 | a59d5fa1 | Michele Tartara | $(THH.makeJSONInstance ''InstReasonSrc) |
497 | a59d5fa1 | Michele Tartara |