Do not rely on no-secondary for movable tests
[ganeti-local] / htools / Ganeti / HTools / Types.hs
index 946a25b..216b011 100644 (file)
@@ -6,7 +6,7 @@
 
 {-
 
-Copyright (C) 2009, 2010, 2011 Google Inc.
+Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -41,12 +41,13 @@ module Ganeti.HTools.Types
   , instanceStatusFromRaw
   , instanceStatusToRaw
   , RSpec(..)
+  , AllocInfo(..)
+  , AllocStats
   , DynUtil(..)
   , zeroUtil
   , baseUtil
   , addUtil
   , subUtil
-  , defVcpuRatio
   , defReservedDiskRatio
   , unitMem
   , unitCpu
@@ -119,6 +120,7 @@ $(THH.declareSADT "DiskTemplate"
        , ("DTPlain",      'C.dtPlain)
        , ("DTBlock",      'C.dtBlock)
        , ("DTDrbd8",      'C.dtDrbd8)
+       , ("DTRbd",        'C.dtRbd)
        ])
 $(THH.makeJSONInstance ''DiskTemplate)
 
@@ -155,14 +157,28 @@ data RSpec = RSpec
   , rspecDsk  :: Int  -- ^ Requested disk
   } deriving (Show, Read, Eq)
 
+-- | Allocation stats type. This is used instead of 'RSpec' (which was
+-- used at first), because we need to track more stats. The actual
+-- data can refer either to allocated, or available, etc. values
+-- depending on the context. See also
+-- 'Cluster.computeAllocationDelta'.
+data AllocInfo = AllocInfo
+  { allocInfoVCpus :: Int    -- ^ VCPUs
+  , allocInfoNCpus :: Double -- ^ Normalised CPUs
+  , allocInfoMem   :: Int    -- ^ Memory
+  , allocInfoDisk  :: Int    -- ^ Disk
+  } deriving (Show, Read, Eq)
+
+-- | Currently used, possibly to allocate, unallocable.
+type AllocStats = (AllocInfo, AllocInfo, AllocInfo)
 
 -- | Instance specification type.
 $(THH.buildObject "ISpec" "iSpec"
-  [ THH.renameField "MemorySize" $ THH.simpleField "memory-size" [t| Int |]
-  , THH.renameField "CpuCount"   $ THH.simpleField "cpu-count"   [t| Int |]
-  , THH.renameField "DiskSize"   $ THH.simpleField "disk-size"   [t| Int |]
-  , THH.renameField "DiskCount"  $ THH.simpleField "disk-count"  [t| Int |]
-  , THH.renameField "NicCount"   $ THH.simpleField "nic-count"   [t| Int |]
+  [ THH.renameField "MemorySize" $ THH.simpleField C.ispecMemSize   [t| Int |]
+  , THH.renameField "CpuCount"   $ THH.simpleField C.ispecCpuCount  [t| Int |]
+  , THH.renameField "DiskSize"   $ THH.simpleField C.ispecDiskSize  [t| Int |]
+  , THH.renameField "DiskCount"  $ THH.simpleField C.ispecDiskCount [t| Int |]
+  , THH.renameField "NicCount"   $ THH.simpleField C.ispecNicCount  [t| Int |]
   ])
 
 -- | The default minimum ispec.
@@ -194,11 +210,15 @@ defMaxISpec = ISpec { iSpecMemorySize = C.ipolicyDefaultsMaxMemorySize
 
 -- | Instance policy type.
 $(THH.buildObject "IPolicy" "iPolicy"
-  [ THH.renameField "StdSpec" $ THH.simpleField "std" [t| ISpec |]
-  , THH.renameField "MinSpec" $ THH.simpleField "min" [t| ISpec |]
-  , THH.renameField "MaxSpec" $ THH.simpleField "max" [t| ISpec |]
+  [ THH.renameField "StdSpec" $ THH.simpleField C.ispecsStd [t| ISpec |]
+  , THH.renameField "MinSpec" $ THH.simpleField C.ispecsMin [t| ISpec |]
+  , THH.renameField "MaxSpec" $ THH.simpleField C.ispecsMax [t| ISpec |]
   , THH.renameField "DiskTemplates" $
-      THH.simpleField "disk_templates" [t| [DiskTemplate] |]
+      THH.simpleField C.ipolicyDts [t| [DiskTemplate] |]
+  , THH.renameField "VcpuRatio" $
+      THH.simpleField C.ipolicyVcpuRatio [t| Double |]
+  , THH.renameField "SpindleRatio" $
+      THH.simpleField C.ipolicySpindleRatio [t| Double |]
   ])
 
 -- | Converts an ISpec type to a RSpec one.
@@ -217,6 +237,8 @@ defIPolicy = IPolicy { iPolicyStdSpec = defStdISpec
                      -- string values, not the actual type; and in
                      -- htools, we are mostly looking at DRBD
                      , iPolicyDiskTemplates = [DTDrbd8, DTPlain]
+                     , iPolicyVcpuRatio = C.ipolicyDefaultsVcpuRatio
+                     , iPolicySpindleRatio = C.ipolicyDefaultsSpindleRatio
                      }
 
 -- | The dynamic resource specs of a machine (i.e. load or load
@@ -281,10 +303,6 @@ connTimeout = 15
 queryTimeout :: Int
 queryTimeout = 60
 
--- | Default vcpu-to-pcpu ratio (randomly chosen value).
-defVcpuRatio :: Double
-defVcpuRatio = 64
-
 -- | Default max disk usage ratio.
 defReservedDiskRatio :: Double
 defReservedDiskRatio = 0