Commit 3c1a8730 authored by Christos Stavrakakis's avatar Christos Stavrakakis Committed by Helga Velroyen

Add nic/disk name and UUID fields in Haskell code

Add name and uuid fields to Disk and nic Haskell objects. Also,
since they now have an UUID, make them instances of UuidObject.
Signed-off-by: default avatarChristor Stavrakakis <cstavr@grnet.gr>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent b87a9c5f
......@@ -280,12 +280,16 @@ $(buildParam "Nic" "nicp"
, simpleField "link" [t| String |]
])
$(buildObject "PartialNic" "nic"
$(buildObject "PartialNic" "nic" $
[ simpleField "mac" [t| String |]
, optionalField $ simpleField "ip" [t| String |]
, simpleField "nicparams" [t| PartialNicParams |]
, optionalField $ simpleField "network" [t| String |]
])
, optionalField $ simpleField "name" [t| String |]
] ++ uuidFields)
instance UuidObject PartialNic where
uuidOf = nicUuid
-- * Disk definitions
......@@ -423,9 +427,11 @@ data Disk = Disk
, diskIvName :: String
, diskSize :: Int
, diskMode :: DiskMode
, diskName :: Maybe String
, diskUuid :: String
} deriving (Show, Eq)
$(buildObjectSerialisation "Disk"
$(buildObjectSerialisation "Disk" $
[ customField 'decodeDLId 'encodeFullDLId ["dev_type"] $
simpleField "logical_id" [t| DiskLogicalId |]
-- , simpleField "physical_id" [t| String |]
......@@ -433,7 +439,12 @@ $(buildObjectSerialisation "Disk"
, defaultField [| "" |] $ simpleField "iv_name" [t| String |]
, simpleField "size" [t| Int |]
, defaultField [| DiskRdWr |] $ simpleField "mode" [t| DiskMode |]
])
, optionalField $ simpleField "name" [t| String |]
]
++ uuidFields)
instance UuidObject Disk where
uuidOf = diskUuid
-- * Instance definitions
......
......@@ -89,7 +89,8 @@ instance Arbitrary DiskLogicalId where
-- generating recursive datastructures is a bit more work.
instance Arbitrary Disk where
arbitrary = Disk <$> arbitrary <*> pure [] <*> arbitrary
<*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary
-- FIXME: we should generate proper values, >=0, etc., but this is
-- hard for partial ones, where all must be wrapped in a 'Maybe'
......@@ -128,11 +129,14 @@ genInstWithNets nets = do
mac <- arbitrary
ip <- arbitrary
nicparams <- arbitrary
name <- arbitrary
uuid <- arbitrary
-- generate some more networks than the given ones
num_more_nets <- choose (0,3)
more_nets <- vectorOf num_more_nets genName
let partial_nics = map (PartialNic mac ip nicparams . Just)
(List.nub (nets ++ more_nets))
let genNic net = PartialNic mac ip nicparams net name uuid
partial_nics = map (genNic . Just)
(List.nub (nets ++ more_nets))
new_inst = plain_inst { instNics = partial_nics }
return new_inst
......
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