on master help sign in
Makes Memory constriants more explicit
commit389eada1ad21b04e771307cff8785f86e9764299 authorDeni Bertovic <deni@denibertovic.com> dateMon 5 Sep 2016, 17:48 (10 years ago) parent2207d98
2 files changed+21−4
docker.cabal+1 src/Docker/Client/Types.hs+20−4
docker.cabal+1
@@ -31,6 +31,7 @@ library
3131 , network >= 2.6.0
3232 , text >= 1.0.0 && < 2.0.0
3333 , time >= 1.5.0 && < 1.7.0
34+ , scientific >= 0.3.0 && < 0.4.0
3435 , tls >= 1.3.7 && < 1.4.0
3536 , unordered-containers >= 0.2.0 && < 0.3.0
3637 , x509 >= 1.6.0 && < 1.7.0
src/Docker/Client/Types.hs+20−4
@@ -93,6 +93,7 @@ import Data.Aeson.Types (defaultOptions, fieldLabelModifier)
9393import Data.Char (isAlphaNum, toUpper)
9494import qualified Data.HashMap.Strict as HM
9595import Data.Monoid ((<>))
96+import Data.Scientific (floatingOrInteger)
9697import Data.Text (Text)
9798import qualified Data.Text as T
9899import Data.Time.Clock (UTCTime)
@@ -1229,6 +1230,21 @@ instance ToJSON DeviceRate where
12291230 , "Rate" .= r
12301231 ]
12311232
1233+data MemoryConstraintSize = B | M | GB deriving (Eq, Show)
1234+
1235+data MemoryConstraint = MemoryConstraint Integer MemoryConstraintSize deriving (Eq, Show)
1236+
1237+instance ToJSON MemoryConstraint where
1238+ toJSON (MemoryConstraint x B) = toJSON x
1239+ toJSON (MemoryConstraint x M) = toJSON $ x * 1024
1240+ toJSON (MemoryConstraint x GB) = toJSON $ x * 1024 * 1024
1241+
1242+instance FromJSON MemoryConstraint where
1243+ parseJSON (JSON.Number x) = case (floatingOrInteger x) of
1244+ Left _ -> fail "Failed to parse MemoryConstraint"
1245+ Right i -> return $ MemoryConstraint i B -- | The docker daemon will always return the number as bytes (integer), regardless of how we set them (using M or GB)
1246+ parseJSON _ = fail "Failed to parse MemoryConstraint"
1247+
12321248data ContainerResources = ContainerResources {
12331249 cpuShares :: Maybe Integer
12341250 -- , cgroupParent :: Text -- 1.24: Missing from inspecting container details... Going to omit for now.
@@ -1244,10 +1260,10 @@ data ContainerResources = ContainerResources {
12441260 , cpusetMems :: Maybe Text
12451261 , devices :: [Device]
12461262 -- , diskQuota :: Integer -- Don't see this ins 1.24.
1247− , kernelMemory :: Maybe Integer
1248− , memory :: Maybe Integer
1249− , memoryReservation :: Maybe Integer
1250− , memorySwap :: Maybe Integer
1263+ , kernelMemory :: Maybe MemoryConstraint
1264+ , memory :: Maybe MemoryConstraint
1265+ , memoryReservation :: Maybe MemoryConstraint
1266+ , memorySwap :: Maybe MemoryConstraint
12511267 -- , memorySwappiness :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.
12521268 , oomKillDisable :: Bool
12531269 -- , pidsLimit :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.