on master help sign in
Added DeviceRate and DeviceWeight
commit7b62e6acaeb998fea3f50af1026943788bd2c641 authorJames Parker <dev@jamesparker.me> dateFri 29 Jul 2016, 10:07 (10 years ago) parentb15ae8c
1 file changed+57−16
src/Docker/Types.hs+57−16
src/Docker/Types.hs+57−16
@@ -49,7 +49,7 @@ module Docker.Types (
4949 , LogDriverConfig(..)
5050 , NetworkMode(..)
5151 , PortType(..)
52− , NetworkInterface(..)
52+-- , NetworkInterface(..)
5353 , Networks(..)
5454 , NetworkSettings(..)
5555 , NetworkOptions(..)
@@ -73,6 +73,8 @@ module Docker.Types (
7373 , ContainerConfig(..)
7474 , defaultContainerConfig
7575 , ExposedPorts(..)
76+ , DeviceWeight(..)
77+ , DeviceRate(..)
7678 ) where
7779
7880import Data.Aeson (FromJSON, ToJSON, genericParseJSON,
@@ -801,14 +803,14 @@ instance FromJSON PortType where
801803 "udp" -> return UDP
802804 _ -> fail "PortType: Invalid port type."
803805
804−newtype NetworkInterface = NetworkInterface Text deriving (Eq, Show)
805−
806−instance FromJSON NetworkInterface where
807− parseJSON (JSON.String v) = return $ NetworkInterface v
808− parseJSON _ = fail "Network interface is not a string."
809−
810−instance ToJSON NetworkInterface where
811− toJSON (NetworkInterface i) = JSON.String i
806+-- newtype NetworkInterface = NetworkInterface Text deriving (Eq, Show)
807+--
808+-- instance FromJSON NetworkInterface where
809+-- parseJSON (JSON.String v) = return $ NetworkInterface v
810+-- parseJSON _ = fail "Network interface is not a string."
811+--
812+-- instance ToJSON NetworkInterface where
813+-- toJSON (NetworkInterface i) = JSON.String i
812814
813815-- | This datastructure models mapping a Port from the container onto the
814816-- host system s that the service running in the container can be accessed from
@@ -851,11 +853,14 @@ instance ToJSON PortBindings where
851853 toJSON (PortBindings []) = JSON.Object HM.empty
852854 toJSON (PortBindings (p:ps)) = toJSON (p:ps)
853855
854−data HostPort = HostPort NetworkInterface Port
856+data HostPort = HostPort {
857+ hostIp :: Text
858+ , hostPost :: Port
859+ }
855860 deriving (Eq, Show)
856861
857862instance ToJSON HostPort where
858− toJSON (HostPort i p) = object ["HostPort" .= p, "HostIP" .= i]
863+ toJSON (HostPort i p) = object ["HostPort" .= show p, "HostIp" .= i]
859864
860865instance FromJSON HostPort where
861866 parseJSON (JSON.Object o) = do
@@ -1040,15 +1045,51 @@ instance ToJSON Ulimit where
10401045 toJSON = genericToJSON defaultOptions {
10411046 fieldLabelModifier = drop 5}
10421047
1048+data DeviceWeight = DeviceWeight {
1049+ deviceWeightPath :: FilePath
1050+ , deviceWeightWeight :: Text
1051+ }
1052+ deriving (Show, Eq)
1053+
1054+instance FromJSON DeviceWeight where
1055+ parseJSON (JSON.Object o) = DeviceWeight
1056+ <$> o .: "Path"
1057+ <*> o .: "Weight"
1058+ parseJSON _ = fail "DeviceWeight is not an object."
1059+
1060+instance ToJSON DeviceWeight where
1061+ toJSON (DeviceWeight p w) = object [
1062+ "Path" .= p
1063+ , "Weight" .= w
1064+ ]
1065+
1066+data DeviceRate = DeviceRate {
1067+ deviceRatePath :: FilePath
1068+ , deviceRateRate :: Text
1069+ }
1070+ deriving (Show, Eq)
1071+
1072+instance FromJSON DeviceRate where
1073+ parseJSON (JSON.Object o) = DeviceRate
1074+ <$> o .: "Path"
1075+ <*> o .: "Rate"
1076+ parseJSON _ = fail "DeviceRate is not an object."
1077+
1078+instance ToJSON DeviceRate where
1079+ toJSON (DeviceRate p r) = object [
1080+ "Path" .= p
1081+ , "Rate" .= r
1082+ ]
1083+
10431084data ContainerResources = ContainerResources {
10441085 cpuShares :: Maybe Integer
10451086 -- , cgroupParent :: Text -- 1.24: Missing from inspecting container details... Going to omit for now.
10461087 , blkioWeight :: Maybe Integer
1047− , blkioWeightDevice :: Maybe Text -- TODO: Not Text
1048− , blkioDeviceReadBps :: Maybe Text -- TODO: Not Text
1049− , blkioDeviceWriteBps :: Maybe Text -- TODO: Not Text
1050− , blkioDeviceReadIOps :: Maybe Text -- TODO: Not Text
1051− , blkioDeviceWriteIOps :: Maybe Text -- TODO: Not Text
1088+ , blkioWeightDevice :: Maybe [DeviceWeight]
1089+ , blkioDeviceReadBps :: Maybe [DeviceRate] -- TODO: Not Text
1090+ , blkioDeviceWriteBps :: Maybe [DeviceRate] -- TODO: Not Text
1091+ , blkioDeviceReadIOps :: Maybe [DeviceRate] -- TODO: Not Text
1092+ , blkioDeviceWriteIOps :: Maybe [DeviceRate] -- TODO: Not Text
10521093 , cpuPeriod :: Maybe Integer
10531094 -- , cpuQuota :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.
10541095 , cpusetCpus :: Maybe Text