Commit de36f091 authored by Jose A. Lopes's avatar Jose A. Lopes
Browse files

Remove TagObject



The 'TagObject' datatype became useless because it was replaced by
'TagKind'. This patch removes 'TagObject', its 'Arbitrary' instance,
and related functions.
Signed-off-by: default avatarJose A. Lopes <jabolopes@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 6e94b75c
......@@ -29,10 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Ganeti.OpCodes
( pyClasses
, OpCode(..)
, TagObject(..)
, tagObjectFrom
, encodeTagObject
, decodeTagObject
, ReplaceDisksMode(..)
, DiskIndex
, mkDiskIndex
......
......@@ -33,11 +33,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Ganeti.OpParams
( TagType(..)
, TagObject(..)
, tagObjectFrom
, tagNameOf
, decodeTagObject
, encodeTagObject
, ReplaceDisksMode(..)
, DiskIndex
, mkDiskIndex
......@@ -317,54 +312,6 @@ $(declareSADT "TagType"
])
$(makeJSONInstance ''TagType)
-- | Data type holding a tag object (type and object name).
data TagObject = TagInstance String
| TagNode String
| TagGroup String
| TagCluster
deriving (Show, Eq)
-- | Tag type for a given tag object.
tagTypeOf :: TagObject -> TagType
tagTypeOf (TagInstance {}) = TagTypeInstance
tagTypeOf (TagNode {}) = TagTypeNode
tagTypeOf (TagGroup {}) = TagTypeGroup
tagTypeOf (TagCluster {}) = TagTypeCluster
-- | Gets the potential tag object name.
tagNameOf :: TagObject -> Maybe String
tagNameOf (TagInstance s) = Just s
tagNameOf (TagNode s) = Just s
tagNameOf (TagGroup s) = Just s
tagNameOf TagCluster = Nothing
-- | Builds a 'TagObject' from a tag type and name.
tagObjectFrom :: (Monad m) => TagType -> JSValue -> m TagObject
tagObjectFrom TagTypeInstance (JSString s) =
return . TagInstance $ fromJSString s
tagObjectFrom TagTypeNode (JSString s) = return . TagNode $ fromJSString s
tagObjectFrom TagTypeGroup (JSString s) = return . TagGroup $ fromJSString s
tagObjectFrom TagTypeCluster JSNull = return TagCluster
tagObjectFrom t v =
fail $ "Invalid tag type/name combination: " ++ show t ++ "/" ++
show (pp_value v)
-- | Name of the tag \"name\" field.
tagNameField :: String
tagNameField = "name"
-- | Custom encoder for 'TagObject' as represented in an opcode.
encodeTagObject :: TagObject -> (JSValue, [(String, JSValue)])
encodeTagObject t = ( showJSON (tagTypeOf t)
, [(tagNameField, maybe JSNull showJSON (tagNameOf t))] )
-- | Custom decoder for 'TagObject' as represented in an opcode.
decodeTagObject :: (Monad m) => [(String, JSValue)] -> JSValue -> m TagObject
decodeTagObject obj kind = do
ttype <- fromJVal kind
tname <- fromObj obj tagNameField
tagObjectFrom ttype tname
-- ** Disks
-- | Replace disks type.
......
......@@ -58,12 +58,8 @@ import Ganeti.JSON
-- * Arbitrary instances
instance Arbitrary OpCodes.TagObject where
arbitrary = oneof [ OpCodes.TagInstance <$> genFQDN
, OpCodes.TagNode <$> genFQDN
, OpCodes.TagGroup <$> genFQDN
, pure OpCodes.TagCluster
]
instance (Ord k, Arbitrary k, Arbitrary a) => Arbitrary (Map.Map k a) where
arbitrary = Map.fromList <$> arbitrary
arbitraryOpTagsGet :: Gen OpCodes.OpCode
arbitraryOpTagsGet = do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment