on master help sign in
fixes for memory conversions
16dbf75James Parker
src/Docker/Client/Types.hs+5−5
@@ -1230,19 +1230,19 @@ instance ToJSON DeviceRate where
1230 , "Rate" .= r
1230 , "Rate" .= r
1231 ]
1231 ]
1232
1232
1233−data MemoryConstraintSize = B | M | GB deriving (Eq, Show)
1233+data MemoryConstraintSize = B | MB | GB deriving (Eq, Show)
1234
1234
1235data MemoryConstraint = MemoryConstraint Integer MemoryConstraintSize deriving (Eq, Show)
1235data MemoryConstraint = MemoryConstraint Integer MemoryConstraintSize deriving (Eq, Show)
1236
1236
1237instance ToJSON MemoryConstraint where
1237instance ToJSON MemoryConstraint where
1238 toJSON (MemoryConstraint x B) = toJSON x
1238 toJSON (MemoryConstraint x B) = toJSON x
1239− toJSON (MemoryConstraint x M) = toJSON $ x * 1024
1239+ toJSON (MemoryConstraint x MB) = toJSON $ x * 1024 * 1024
1240− toJSON (MemoryConstraint x GB) = toJSON $ x * 1024 * 1024
1240+ toJSON (MemoryConstraint x GB) = toJSON $ x * 1024 * 1024 * 1024
1241
1241
1242instance FromJSON MemoryConstraint where
1242instance FromJSON MemoryConstraint where
1243 parseJSON (JSON.Number x) = case (floatingOrInteger x) of
1243 parseJSON (JSON.Number x) = case (floatingOrInteger x) of
1244− Left _ -> fail "Failed to parse MemoryConstraint"
1244+ Left (_ :: Double) -> 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)
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 MB or GB)
1246 parseJSON _ = fail "Failed to parse MemoryConstraint"
1246 parseJSON _ = fail "Failed to parse MemoryConstraint"
1247
1247
1248data ContainerResources = ContainerResources {
1248data ContainerResources = ContainerResources {