Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / ConstantUtils.hs @ b9202225

History | View | Annotate | Download (5.3 kB)

1 f2b6e7d4 Jose A. Lopes
{-| ConstantUtils contains the helper functions for constants
2 f2b6e7d4 Jose A. Lopes
3 f2b6e7d4 Jose A. Lopes
This module cannot be merged with 'Ganeti.Utils' because it would
4 f2b6e7d4 Jose A. Lopes
create a circular dependency if imported, for example, from
5 f2b6e7d4 Jose A. Lopes
'Ganeti.Constants'.
6 f2b6e7d4 Jose A. Lopes
7 f2b6e7d4 Jose A. Lopes
-}
8 f2b6e7d4 Jose A. Lopes
9 f2b6e7d4 Jose A. Lopes
{-
10 f2b6e7d4 Jose A. Lopes
11 f2b6e7d4 Jose A. Lopes
Copyright (C) 2013 Google Inc.
12 f2b6e7d4 Jose A. Lopes
13 f2b6e7d4 Jose A. Lopes
This program is free software; you can redistribute it and/or modify
14 f2b6e7d4 Jose A. Lopes
it under the terms of the GNU General Public License as published by
15 f2b6e7d4 Jose A. Lopes
the Free Software Foundation; either version 2 of the License, or
16 f2b6e7d4 Jose A. Lopes
(at your option) any later version.
17 f2b6e7d4 Jose A. Lopes
18 f2b6e7d4 Jose A. Lopes
This program is distributed in the hope that it will be useful, but
19 f2b6e7d4 Jose A. Lopes
WITHOUT ANY WARRANTY; without even the implied warranty of
20 f2b6e7d4 Jose A. Lopes
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 f2b6e7d4 Jose A. Lopes
General Public License for more details.
22 f2b6e7d4 Jose A. Lopes
23 f2b6e7d4 Jose A. Lopes
You should have received a copy of the GNU General Public License
24 f2b6e7d4 Jose A. Lopes
along with this program; if not, write to the Free Software
25 f2b6e7d4 Jose A. Lopes
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 f2b6e7d4 Jose A. Lopes
02110-1301, USA.
27 f2b6e7d4 Jose A. Lopes
28 f2b6e7d4 Jose A. Lopes
-}
29 f2b6e7d4 Jose A. Lopes
module Ganeti.ConstantUtils where
30 f2b6e7d4 Jose A. Lopes
31 5d4e1402 Jose A. Lopes
import Data.Char (ord)
32 f2b6e7d4 Jose A. Lopes
import Data.Set (Set)
33 fa8d6aa7 Jose A. Lopes
import qualified Data.Set as Set (difference, fromList, toList, union)
34 f2b6e7d4 Jose A. Lopes
35 b711450c Petr Pudlak
import Ganeti.PyValue
36 f2b6e7d4 Jose A. Lopes
37 558d8ed8 Jose A. Lopes
-- | 'PythonChar' wraps a Python 'char'
38 5d4e1402 Jose A. Lopes
newtype PythonChar = PythonChar { unPythonChar :: Char }
39 5d4e1402 Jose A. Lopes
  deriving (Show)
40 5d4e1402 Jose A. Lopes
41 5d4e1402 Jose A. Lopes
instance PyValue PythonChar where
42 5d4e1402 Jose A. Lopes
  showValue c = "chr(" ++ show (ord (unPythonChar c)) ++ ")"
43 5d4e1402 Jose A. Lopes
44 a2b55ccd Jose A. Lopes
-- | 'PythonNone' wraps Python 'None'
45 a2b55ccd Jose A. Lopes
data PythonNone = PythonNone
46 a2b55ccd Jose A. Lopes
47 a2b55ccd Jose A. Lopes
instance PyValue PythonNone where
48 a2b55ccd Jose A. Lopes
  showValue _ = "None"
49 a2b55ccd Jose A. Lopes
50 f2b6e7d4 Jose A. Lopes
-- | FrozenSet wraps a Haskell 'Set'
51 f2b6e7d4 Jose A. Lopes
--
52 f2b6e7d4 Jose A. Lopes
-- See 'PyValue' instance for 'FrozenSet'.
53 f2b6e7d4 Jose A. Lopes
newtype FrozenSet a = FrozenSet { unFrozenSet :: Set a }
54 3a715da0 Jose A. Lopes
  deriving (Eq, Ord, Show)
55 f2b6e7d4 Jose A. Lopes
56 f2b6e7d4 Jose A. Lopes
-- | Converts a Haskell 'Set' into a Python 'frozenset'
57 f2b6e7d4 Jose A. Lopes
--
58 f2b6e7d4 Jose A. Lopes
-- This instance was supposed to be for 'Set' instead of 'FrozenSet'.
59 f2b6e7d4 Jose A. Lopes
-- However, 'ghc-6.12.1' seems to be crashing with 'segmentation
60 f2b6e7d4 Jose A. Lopes
-- fault' due to the presence of more than one instance of 'Set',
61 f2b6e7d4 Jose A. Lopes
-- namely, this one and the one in 'Ganeti.OpCodes'.  For this reason,
62 f2b6e7d4 Jose A. Lopes
-- we wrap 'Set' into 'FrozenSet'.
63 f2b6e7d4 Jose A. Lopes
instance PyValue a => PyValue (FrozenSet a) where
64 f2b6e7d4 Jose A. Lopes
  showValue s = "frozenset(" ++ showValue (Set.toList (unFrozenSet s)) ++ ")"
65 f2b6e7d4 Jose A. Lopes
66 f2b6e7d4 Jose A. Lopes
mkSet :: Ord a => [a] -> FrozenSet a
67 f2b6e7d4 Jose A. Lopes
mkSet = FrozenSet . Set.fromList
68 cd0359bc Jose A. Lopes
69 07e30af5 Jose A. Lopes
toList :: FrozenSet a -> [a]
70 07e30af5 Jose A. Lopes
toList = Set.toList . unFrozenSet
71 07e30af5 Jose A. Lopes
72 4c1275f9 Jose A. Lopes
union :: Ord a => FrozenSet a -> FrozenSet a -> FrozenSet a
73 4c1275f9 Jose A. Lopes
union x y = FrozenSet (unFrozenSet x `Set.union` unFrozenSet y)
74 4c1275f9 Jose A. Lopes
75 fa8d6aa7 Jose A. Lopes
difference :: Ord a => FrozenSet a -> FrozenSet a -> FrozenSet a
76 fa8d6aa7 Jose A. Lopes
difference x y = FrozenSet (unFrozenSet x `Set.difference` unFrozenSet y)
77 fa8d6aa7 Jose A. Lopes
78 cd0359bc Jose A. Lopes
-- | 'Protocol' represents the protocols used by the daemons
79 cd0359bc Jose A. Lopes
data Protocol = Tcp | Udp
80 cd0359bc Jose A. Lopes
  deriving (Show)
81 cd0359bc Jose A. Lopes
82 cd0359bc Jose A. Lopes
-- | 'PyValue' instance of 'Protocol'
83 cd0359bc Jose A. Lopes
--
84 cd0359bc Jose A. Lopes
-- This instance is used by the Haskell to Python constants
85 cd0359bc Jose A. Lopes
instance PyValue Protocol where
86 cd0359bc Jose A. Lopes
  showValue Tcp = "\"tcp\""
87 cd0359bc Jose A. Lopes
  showValue Udp = "\"udp\""
88 1c31b263 Jose A. Lopes
89 1c31b263 Jose A. Lopes
-- | Failure exit code
90 1c31b263 Jose A. Lopes
--
91 e1235448 Jose A. Lopes
-- These are defined here and not in 'Ganeti.Constants' together with
92 1c31b263 Jose A. Lopes
-- the other exit codes in order to avoid a circular dependency
93 e1235448 Jose A. Lopes
-- between 'Ganeti.Constants' and 'Ganeti.Runtime'
94 1c31b263 Jose A. Lopes
exitFailure :: Int
95 1c31b263 Jose A. Lopes
exitFailure = 1
96 df726590 Jose A. Lopes
97 df726590 Jose A. Lopes
-- | Console device
98 df726590 Jose A. Lopes
--
99 e1235448 Jose A. Lopes
-- This is defined here and not in 'Ganeti.Constants' order to avoid a
100 e1235448 Jose A. Lopes
-- circular dependency between 'Ganeti.Constants' and 'Ganeti.Logging'
101 df726590 Jose A. Lopes
devConsole :: String
102 df726590 Jose A. Lopes
devConsole = "/dev/console"
103 72e18df1 Jose A. Lopes
104 06fd57e5 Jose A. Lopes
-- | Random uuid generator
105 06fd57e5 Jose A. Lopes
--
106 e1235448 Jose A. Lopes
-- This is defined here and not in 'Ganeti.Constants' order to avoid a
107 e1235448 Jose A. Lopes
-- circular dependendy between 'Ganeti.Constants' and 'Ganeti.Types'
108 06fd57e5 Jose A. Lopes
randomUuidFile :: String
109 06fd57e5 Jose A. Lopes
randomUuidFile = "/proc/sys/kernel/random/uuid"
110 06fd57e5 Jose A. Lopes
111 8e4e0268 Jose A. Lopes
-- * Priority levels
112 72e18df1 Jose A. Lopes
--
113 8e4e0268 Jose A. Lopes
-- This is defined here and not in 'Ganeti.Types' in order to avoid a
114 8e4e0268 Jose A. Lopes
-- GHC stage restriction and because there is no suitable 'declareADT'
115 72e18df1 Jose A. Lopes
-- variant that handles integer values directly.
116 8e4e0268 Jose A. Lopes
117 72e18df1 Jose A. Lopes
priorityLow :: Int
118 72e18df1 Jose A. Lopes
priorityLow = 10
119 72e18df1 Jose A. Lopes
120 72e18df1 Jose A. Lopes
priorityNormal :: Int
121 72e18df1 Jose A. Lopes
priorityNormal = 0
122 72e18df1 Jose A. Lopes
123 72e18df1 Jose A. Lopes
priorityHigh :: Int
124 72e18df1 Jose A. Lopes
priorityHigh = -10
125 b78d0757 Jose A. Lopes
126 b78d0757 Jose A. Lopes
-- | Calculates int version number from major, minor and revision
127 b78d0757 Jose A. Lopes
-- numbers.
128 b78d0757 Jose A. Lopes
buildVersion :: Int -> Int -> Int -> Int
129 b78d0757 Jose A. Lopes
buildVersion major minor revision =
130 b78d0757 Jose A. Lopes
  1000000 * major + 10000 * minor + 1 * revision
131 8e4e0268 Jose A. Lopes
132 cdac0552 Jose A. Lopes
-- | Confd protocol version
133 cdac0552 Jose A. Lopes
--
134 cdac0552 Jose A. Lopes
-- This is defined here in order to avoid a circular dependency
135 e1235448 Jose A. Lopes
-- between 'Ganeti.Confd.Types' and 'Ganeti.Constants'.
136 cdac0552 Jose A. Lopes
confdProtocolVersion :: Int
137 cdac0552 Jose A. Lopes
confdProtocolVersion = 1
138 cdac0552 Jose A. Lopes
139 cc6a469e Jose A. Lopes
-- * Confd request query fields
140 8e4e0268 Jose A. Lopes
--
141 8e4e0268 Jose A. Lopes
-- These are defined here and not in 'Ganeti.Types' due to GHC stage
142 8e4e0268 Jose A. Lopes
-- restrictions concerning Template Haskell.  They are also not
143 e1235448 Jose A. Lopes
-- defined in 'Ganeti.Constants' in order to avoid a circular
144 8e4e0268 Jose A. Lopes
-- dependency between that module and 'Ganeti.Types'.
145 8e4e0268 Jose A. Lopes
146 8e4e0268 Jose A. Lopes
confdReqqLink :: String
147 8e4e0268 Jose A. Lopes
confdReqqLink = "0"
148 8e4e0268 Jose A. Lopes
149 8e4e0268 Jose A. Lopes
confdReqqIp :: String
150 8e4e0268 Jose A. Lopes
confdReqqIp = "1"
151 8e4e0268 Jose A. Lopes
152 8e4e0268 Jose A. Lopes
confdReqqIplist :: String
153 8e4e0268 Jose A. Lopes
confdReqqIplist = "2"
154 8e4e0268 Jose A. Lopes
155 8e4e0268 Jose A. Lopes
confdReqqFields :: String
156 8e4e0268 Jose A. Lopes
confdReqqFields = "3"
157 8397ffde Jose A. Lopes
158 8397ffde Jose A. Lopes
-- * ISpec
159 8397ffde Jose A. Lopes
160 8397ffde Jose A. Lopes
ispecMemSize :: String
161 8397ffde Jose A. Lopes
ispecMemSize = "memory-size"
162 8397ffde Jose A. Lopes
163 8397ffde Jose A. Lopes
ispecCpuCount :: String
164 8397ffde Jose A. Lopes
ispecCpuCount = "cpu-count"
165 8397ffde Jose A. Lopes
166 8397ffde Jose A. Lopes
ispecDiskCount :: String
167 8397ffde Jose A. Lopes
ispecDiskCount = "disk-count"
168 8397ffde Jose A. Lopes
169 8397ffde Jose A. Lopes
ispecDiskSize :: String
170 8397ffde Jose A. Lopes
ispecDiskSize = "disk-size"
171 8397ffde Jose A. Lopes
172 8397ffde Jose A. Lopes
ispecNicCount :: String
173 8397ffde Jose A. Lopes
ispecNicCount = "nic-count"
174 8397ffde Jose A. Lopes
175 8397ffde Jose A. Lopes
ispecSpindleUse :: String
176 8397ffde Jose A. Lopes
ispecSpindleUse = "spindle-use"
177 8397ffde Jose A. Lopes
178 8397ffde Jose A. Lopes
ispecsMinmax :: String
179 8397ffde Jose A. Lopes
ispecsMinmax = "minmax"
180 8397ffde Jose A. Lopes
181 8397ffde Jose A. Lopes
ispecsStd :: String
182 8397ffde Jose A. Lopes
ispecsStd = "std"
183 8397ffde Jose A. Lopes
184 8397ffde Jose A. Lopes
ipolicyDts :: String
185 8397ffde Jose A. Lopes
ipolicyDts = "disk-templates"
186 8397ffde Jose A. Lopes
187 8397ffde Jose A. Lopes
ipolicyVcpuRatio :: String
188 8397ffde Jose A. Lopes
ipolicyVcpuRatio = "vcpu-ratio"
189 8397ffde Jose A. Lopes
190 8397ffde Jose A. Lopes
ipolicySpindleRatio :: String
191 8397ffde Jose A. Lopes
ipolicySpindleRatio = "spindle-ratio"
192 8397ffde Jose A. Lopes
193 8397ffde Jose A. Lopes
ipolicyDefaultsVcpuRatio :: Double
194 8397ffde Jose A. Lopes
ipolicyDefaultsVcpuRatio = 4.0
195 8397ffde Jose A. Lopes
196 8397ffde Jose A. Lopes
ipolicyDefaultsSpindleRatio :: Double
197 8397ffde Jose A. Lopes
ipolicyDefaultsSpindleRatio = 32.0