LGTM, thanks On Wed, Nov 11, 2015 at 5:27 PM, 'Klaus Aehlig' via ganeti-devel < [email protected]> wrote:
> The UuidObject type class provides a clean interface to > obtain the UUID of an object. Prefer this interface over > hard-coding the specific functions all over the place. > > Signed-off-by: Klaus Aehlig <[email protected]> > --- > src/Ganeti/Confd/ClientFunctions.hs | 2 +- > src/Ganeti/Confd/Server.hs | 6 +++--- > src/Ganeti/Config.hs | 8 ++++---- > src/Ganeti/JQScheduler.hs | 2 +- > src/Ganeti/Query/Group.hs | 8 ++++---- > src/Ganeti/Query/Instance.hs | 14 +++++++------- > src/Ganeti/Query/Network.hs | 10 +++++----- > src/Ganeti/Query/Node.hs | 10 +++++----- > src/Ganeti/Query/Query.hs | 2 +- > src/Ganeti/Rpc.hs | 2 +- > src/Ganeti/Storage/Utils.hs | 2 +- > src/Ganeti/WConfd/Ssconf.hs | 4 ++-- > test/hs/Test/Ganeti/Objects.hs | 4 ++-- > 13 files changed, 37 insertions(+), 37 deletions(-) > > diff --git a/src/Ganeti/Confd/ClientFunctions.hs > b/src/Ganeti/Confd/ClientFunctions.hs > index f416afe..3213669 100644 > --- a/src/Ganeti/Confd/ClientFunctions.hs > +++ b/src/Ganeti/Confd/ClientFunctions.hs > @@ -72,7 +72,7 @@ getDisks > -> BT.ResultT String IO [Ganeti.Objects.Disk] > getDisks inst srvAddr srvPort = do > client <- liftIO $ getConfdClient srvAddr srvPort > - reply <- liftIO . query client ReqInstanceDisks . PlainQuery . instUuid > $ inst > + reply <- liftIO . query client ReqInstanceDisks . PlainQuery . uuidOf $ > inst > case fmap (J.readJSON . confdReplyAnswer) reply of > Just (J.Ok disks) -> return disks > Just (J.Error msg) -> fail msg > diff --git a/src/Ganeti/Confd/Server.hs b/src/Ganeti/Confd/Server.hs > index 7556527..774054b 100644 > --- a/src/Ganeti/Confd/Server.hs > +++ b/src/Ganeti/Confd/Server.hs > @@ -222,7 +222,7 @@ buildResponse cdata req@(ConfdRequest { confdRqType = > ReqNodeDrbd }) = do > PlainQuery str -> return str > _ -> fail $ "Invalid query type " ++ show (confdRqQuery > req) > node <- gntErrorToResult $ getNode cfg node_name > - let minors = concatMap (getInstMinorsForNode cfg (nodeUuid node)) . > + let minors = concatMap (getInstMinorsForNode cfg (uuidOf node)) . > M.elems . fromContainer . configInstances $ cfg > encoded <- mapM (encodeMinors cfg) minors > return (ReplyStatusOk, J.showJSON encoded, nodeSerial node) > @@ -238,7 +238,7 @@ buildResponse cdata req@(ConfdRequest { confdRqType = > ReqNodeInstances }) = do > case getNode cfg node_name of > Ok n -> return n > Bad e -> fail $ "Node not found in the configuration: " ++ show e > - let node_uuid = nodeUuid node > + let node_uuid = uuidOf node > instances = getNodeInstances cfg node_uuid > return (ReplyStatusOk, J.showJSON instances, nodeSerial node) > > @@ -253,7 +253,7 @@ buildResponse cdata req@(ConfdRequest { confdRqType = > ReqInstanceDisks }) = do > case getInstance cfg inst_name of > Ok i -> return i > Bad e -> fail $ "Instance not found in the configuration: " ++ show > e > - case getInstDisks cfg . instUuid $ inst of > + case getInstDisks cfg . uuidOf $ inst of > Ok disks -> return (ReplyStatusOk, J.showJSON disks, instSerial inst) > Bad e -> fail $ "Could not retrieve disks: " ++ show e > > diff --git a/src/Ganeti/Config.hs b/src/Ganeti/Config.hs > index ddbb7b1..264aae0 100644 > --- a/src/Ganeti/Config.hs > +++ b/src/Ganeti/Config.hs > @@ -175,7 +175,7 @@ getNodeInstances cfg nname = > -- | Computes the role of a node. > getNodeRole :: ConfigData -> Node -> NodeRole > getNodeRole cfg node > - | nodeUuid node == clusterMasterNode (configCluster cfg) = NRMaster > + | uuidOf node == clusterMasterNode (configCluster cfg) = NRMaster > | nodeMasterCandidate node = NRCandidate > | nodeDrained node = NRDrained > | nodeOffline node = NROffline > @@ -322,7 +322,7 @@ getGroupNodes cfg gname = > -- | Get (primary, secondary) instances of a given node group. > getGroupInstances :: ConfigData -> String -> ([Instance], [Instance]) > getGroupInstances cfg gname = > - let gnodes = map nodeUuid (getGroupNodes cfg gname) > + let gnodes = map uuidOf (getGroupNodes cfg gname) > ginsts = map (getNodeInstances cfg) gnodes in > (concatMap fst ginsts, concatMap snd ginsts) > > @@ -409,7 +409,7 @@ getInstDisks cfg iname = > -- | Get disks for a given instance object. > getInstDisksFromObj :: ConfigData -> Instance -> ErrorResult [Disk] > getInstDisksFromObj cfg = > - getInstDisks cfg . instUuid > + getInstDisks cfg . uuidOf > > -- | Collects a value for all DRBD disks > collectFromDrbdDisks > @@ -496,7 +496,7 @@ buildLinkIpInstnameMap cfg = > let cluster = configCluster cfg > instances = M.elems . fromContainer . configInstances $ cfg > defparams = (M.!) (fromContainer $ clusterNicparams cluster) > C.ppDefault > - nics = concatMap (\i -> [(fromMaybe (instUuid i) $ instName i, nic) > + nics = concatMap (\i -> [(fromMaybe (uuidOf i) $ instName i, nic) > | nic <- instNics i]) > instances > in foldl' (\accum (iname, nic) -> > diff --git a/src/Ganeti/JQScheduler.hs b/src/Ganeti/JQScheduler.hs > index c1847d2..66c3fd1 100644 > --- a/src/Ganeti/JQScheduler.hs > +++ b/src/Ganeti/JQScheduler.hs > @@ -372,7 +372,7 @@ cancelRejectedJobs qstate cfg filters = do > forM_ jobsToCancel $ \(job, fr) -> do > let jid = qjId job > logDebug $ "Cancelling job " ++ show (fromJobId jid) > - ++ " because it was REJECTed by filter rule " ++ frUuid fr > + ++ " because it was REJECTed by filter rule " ++ uuidOf fr > -- First dequeue, then cancel. > dequeueResult <- dequeueJob qstate jid > case dequeueResult of > diff --git a/src/Ganeti/Query/Group.hs b/src/Ganeti/Query/Group.hs > index c15906c..45bd81a 100644 > --- a/src/Ganeti/Query/Group.hs > +++ b/src/Ganeti/Query/Group.hs > @@ -69,20 +69,20 @@ groupFields = > , (FieldDefinition "ndparams" "NDParams" QFTOther "Node parameters", > FieldConfig (\cfg ng -> rsNormal (getGroupNdParams cfg ng)), > QffNormal) > , (FieldDefinition "node_cnt" "Nodes" QFTNumber "Number of nodes", > - FieldConfig (\cfg -> rsNormal . length . getGroupNodes cfg . > groupUuid), > + FieldConfig (\cfg -> rsNormal . length . getGroupNodes cfg . uuidOf), > QffNormal) > , (FieldDefinition "node_list" "NodeList" QFTOther "List of nodes", > FieldConfig (\cfg -> rsNormal . map nodeName . > - getGroupNodes cfg . groupUuid), QffNormal) > + getGroupNodes cfg . uuidOf), QffNormal) > , (FieldDefinition "pinst_cnt" "Instances" QFTNumber > "Number of primary instances", > FieldConfig > - (\cfg -> rsNormal . length . fst . getGroupInstances cfg . > groupUuid), > + (\cfg -> rsNormal . length . fst . getGroupInstances cfg . uuidOf), > QffNormal) > , (FieldDefinition "pinst_list" "InstanceList" QFTOther > "List of primary instances", > FieldConfig (\cfg -> rsNormal . niceSort . mapMaybe instName . fst . > - getGroupInstances cfg . groupUuid), QffNormal) > + getGroupInstances cfg . uuidOf), QffNormal) > ] ++ > map buildNdParamField allNDParamFields ++ > timeStampFields ++ > diff --git a/src/Ganeti/Query/Instance.hs b/src/Ganeti/Query/Instance.hs > index 328bb9b..fa74204 100644 > --- a/src/Ganeti/Query/Instance.hs > +++ b/src/Ganeti/Query/Instance.hs > @@ -152,7 +152,7 @@ instanceFields = > FieldConfig (getSecondaryNodeGroupAttribute groupName), QffNormal) > , (FieldDefinition "snodes.group.uuid" "SecondaryNodesGroupsUUID" > QFTOther > "Node group UUIDs of secondary nodes", > - FieldConfig (getSecondaryNodeGroupAttribute groupUuid), QffNormal) > + FieldConfig (getSecondaryNodeGroupAttribute uuidOf), QffNormal) > ] ++ > > -- Instance parameter fields, whole > @@ -227,7 +227,7 @@ instanceFields = > getIndexedOptionalConfField getInstDisksFromObj diskName, QffNormal) > , (fieldDefinitionCompleter "disk.uuid/%d" "DiskUUID/%d" QFTText > "UUID of %s disk", > - getIndexedConfField getInstDisksFromObj diskUuid, QffNormal) > + getIndexedConfField getInstDisksFromObj uuidOf, QffNormal) > ] ++ > > -- Aggregate nic parameter fields > @@ -247,7 +247,7 @@ instanceFields = > QffNormal) > , (FieldDefinition "nic.uuids" "NIC_UUIDs" QFTOther > (nicAggDescPrefix ++ "UUID"), > - FieldSimple (rsNormal . map nicUuid . instNics), QffNormal) > + FieldSimple (rsNormal . map uuidOf . instNics), QffNormal) > , (FieldDefinition "nic.modes" "NIC_modes" QFTOther > (nicAggDescPrefix ++ "mode"), > FieldConfig (\cfg -> rsNormal . map > @@ -288,7 +288,7 @@ instanceFields = > getIndexedOptionalField instNics nicIp, QffNormal) > , (fieldDefinitionCompleter "nic.uuid/%d" "NicUUID/%d" QFTText > ("UUID address" ++ nicDescSuffix), > - getIndexedField instNics nicUuid, QffNormal) > + getIndexedField instNics uuidOf, QffNormal) > , (fieldDefinitionCompleter "nic.mac/%d" "NicMAC/%d" QFTText > ("MAC address" ++ nicDescSuffix), > getIndexedField instNics nicMac, QffNormal) > @@ -411,7 +411,7 @@ getDiskNames cfg = > -- | Get a list of disk UUIDs for an instance > getDiskUuids :: ConfigData -> Instance -> ResultEntry > getDiskUuids cfg = > - rsErrorNoData . liftA (map diskUuid) . getInstDisksFromObj cfg > + rsErrorNoData . liftA (map uuidOf) . getInstDisksFromObj cfg > > -- | Creates a functions which produces a FieldConfig 'FieldGetter' when > fed > -- an index. Works for fields that may not return a value, expressed > through > @@ -582,7 +582,7 @@ getPrimaryNodeGroupName cfg inst = > -- | Get primary node group uuid > getPrimaryNodeGroupUuid :: ConfigData -> Instance -> ResultEntry > getPrimaryNodeGroupUuid cfg inst = > - rsErrorNoData $ groupUuid <$> getPrimaryNodeGroup cfg inst > + rsErrorNoData $ uuidOf <$> getPrimaryNodeGroup cfg inst > > -- | Get secondary nodes - the configuration objects themselves > getSecondaryNodes :: ConfigData -> Instance -> ErrorResult [Node] > @@ -852,7 +852,7 @@ extractLiveInfo :: [(Node, ERpcError > RpcResultAllInstancesInfo)] > -> Instance > -> Runtime > extractLiveInfo nodeResultList nodeConsoleList inst = > - let uuidConvert = map (\(x, y) -> (nodeUuid x, y)) > + let uuidConvert = map (\(x, y) -> (uuidOf x, y)) > uuidResultList = uuidConvert nodeResultList > uuidConsoleList = uuidConvert nodeConsoleList > in case getInstanceInfo uuidResultList inst of > diff --git a/src/Ganeti/Query/Network.hs b/src/Ganeti/Query/Network.hs > index 23818f6..f89c87b 100644 > --- a/src/Ganeti/Query/Network.hs > +++ b/src/Ganeti/Query/Network.hs > @@ -82,17 +82,17 @@ networkFields = > QffNormal) > , (FieldDefinition "group_list" "GroupList" QFTOther > "List of nodegroups (group name, NIC mode, NIC link)", > - FieldConfig (\cfg -> rsNormal . getGroupConnections cfg . > networkUuid), > + FieldConfig (\cfg -> rsNormal . getGroupConnections cfg . uuidOf), > QffNormal) > , (FieldDefinition "group_cnt" "NodeGroups" QFTNumber "Number of > nodegroups", > FieldConfig (\cfg -> rsNormal . length . getGroupConnections cfg > - . networkUuid), QffNormal) > + . uuidOf), QffNormal) > , (FieldDefinition "inst_list" "InstanceList" QFTOther "List of > instances", > - FieldConfig (\cfg -> rsNormal . getInstances cfg . networkUuid), > + FieldConfig (\cfg -> rsNormal . getInstances cfg . uuidOf), > QffNormal) > , (FieldDefinition "inst_cnt" "Instances" QFTNumber "Number of > instances", > FieldConfig (\cfg -> rsNormal . length . getInstances cfg > - . networkUuid), QffNormal) > + . uuidOf), QffNormal) > , (FieldDefinition "external_reservations" "ExternalReservations" > QFTText > "External reservations", > FieldSimple getExtReservationsString, QffNormal) > @@ -161,7 +161,7 @@ getNetworkUuid :: ConfigData -> String -> Maybe String > getNetworkUuid cfg name = > let net = find (\n -> name == fromNonEmpty (networkName n)) > ((Map.elems . fromContainer . configNetworks) cfg) > - in fmap networkUuid net > + in fmap uuidOf net > > -- | Computes the reservations list for a network. > -- > diff --git a/src/Ganeti/Query/Node.hs b/src/Ganeti/Query/Node.hs > index 17c3469..dc78785 100644 > --- a/src/Ganeti/Query/Node.hs > +++ b/src/Ganeti/Query/Node.hs > @@ -209,7 +209,7 @@ nodeFields = > FieldSimple (rsNormal . nodeSecondaryIp), QffNormal) > , (FieldDefinition "master" "IsMaster" QFTBool "Whether node is master", > FieldConfig (\cfg node -> > - rsNormal (nodeUuid node == > + rsNormal (uuidOf node == > clusterMasterNode (configCluster cfg))), > QffNormal) > , (FieldDefinition "group" "Group" QFTText "Node group", > @@ -234,11 +234,11 @@ nodeFields = > , (FieldDefinition "pinst_list" "PriInstances" QFTOther > "List of instances with this node as primary", > FieldConfig (\cfg -> rsNormal . niceSort . mapMaybe instName . fst . > - getNodeInstances cfg . nodeUuid), QffNormal) > + getNodeInstances cfg . uuidOf), QffNormal) > , (FieldDefinition "sinst_list" "SecInstances" QFTOther > "List of instances with this node as secondary", > FieldConfig (\cfg -> rsNormal . niceSort . mapMaybe instName . snd . > - getNodeInstances cfg . nodeUuid), QffNormal) > + getNodeInstances cfg . uuidOf), QffNormal) > , (FieldDefinition "role" "Role" QFTText nodeRoleDoc, > FieldConfig ((rsNormal .) . getNodeRole), QffNormal) > , (FieldDefinition "powered" "Powered" QFTBool > @@ -262,7 +262,7 @@ nodeFields = > -- | Helper function to retrieve the number of (primary or secondary) > instances > getNumInstances :: (([Instance], [Instance]) -> [Instance]) > -> ConfigData -> Node -> Int > -getNumInstances get_fn cfg = length . get_fn . getNodeInstances cfg . > nodeUuid > +getNumInstances get_fn cfg = length . get_fn . getNodeInstances cfg . > uuidOf > > -- | The node fields map. > fieldsMap :: FieldMap Node Runtime > @@ -306,7 +306,7 @@ collectLiveData True cfg fields nodes = do > storage_units = if queryDomainRequired storageFields fields > then getStorageUnitsOfNodes cfg good_nodes > else Map.fromList > - (map (\n -> (nodeUuid n, [])) good_nodes) > + (map (\n -> (uuidOf n, [])) good_nodes) > rpcres <- executeRpcCall good_nodes (RpcCallNodeInfo storage_units hvs) > return $ fillUpList (fillPairFromMaybe rpcResultNodeBroken > pickPairUnique) > nodes rpcres > diff --git a/src/Ganeti/Query/Query.hs b/src/Ganeti/Query/Query.hs > index 31aff65..147303f 100644 > --- a/src/Ganeti/Query/Query.hs > +++ b/src/Ganeti/Query/Query.hs > @@ -336,7 +336,7 @@ queryInner cfg live (Query (ItemTypeOpCode QRExport) > fields qfilter) wanted = > > queryInner cfg live (Query (ItemTypeLuxi QRFilter) fields qfilter) wanted > = > genericQuery FilterRules.fieldsMap (CollectorSimple > dummyCollectLiveData) > - frUuid configFilters getFilterRule cfg live fields qfilter > wanted > + uuidOf configFilters getFilterRule cfg live fields qfilter > wanted > > queryInner _ _ (Query qkind _ _) _ = > return . Bad . GenericError $ "Query '" ++ show qkind ++ "' not > supported" > diff --git a/src/Ganeti/Rpc.hs b/src/Ganeti/Rpc.hs > index a43cc52..c042cbe 100644 > --- a/src/Ganeti/Rpc.hs > +++ b/src/Ganeti/Rpc.hs > @@ -553,7 +553,7 @@ instance RpcCall RpcCallNodeInfo where > rpcCallData n call = J.encode > ( fromMaybe (error $ "Programmer error: missing parameter for node > named " > ++ nodeName n) > - $ Map.lookup (nodeUuid n) (rpcCallNodeInfoStorageUnits call) > + $ Map.lookup (uuidOf n) (rpcCallNodeInfoStorageUnits call) > , rpcCallNodeInfoHypervisors call > ) > > diff --git a/src/Ganeti/Storage/Utils.hs b/src/Ganeti/Storage/Utils.hs > index f72438d..9cfdd7e 100644 > --- a/src/Ganeti/Storage/Utils.hs > +++ b/src/Ganeti/Storage/Utils.hs > @@ -98,4 +98,4 @@ getStorageUnitsOfNode cfg n = > -- | Get the storage unit map for all nodes > getStorageUnitsOfNodes :: ConfigData -> [Node] -> M.Map String > [StorageUnit] > getStorageUnitsOfNodes cfg ns = > - M.fromList (map (\n -> (nodeUuid n, getStorageUnitsOfNode cfg n)) ns) > + M.fromList (map (\n -> (uuidOf n, getStorageUnitsOfNode cfg n)) ns) > diff --git a/src/Ganeti/WConfd/Ssconf.hs b/src/Ganeti/WConfd/Ssconf.hs > index 81db4b3..6ab7f8f 100644 > --- a/src/Ganeti/WConfd/Ssconf.hs > +++ b/src/Ganeti/WConfd/Ssconf.hs > @@ -120,9 +120,9 @@ mkSSConf cdata = SSConf . M.fromList $ > , (SSMaintainNodeHealth, return . show . clusterMaintainNodeHealth > $ cluster) > , (SSUidPool, mapLines formatUidRange . clusterUidPool $ cluster) > - , (SSNodegroups, mapLines (spcPair . (groupUuid &&& groupName)) > + , (SSNodegroups, mapLines (spcPair . (uuidOf &&& groupName)) > nodeGroups) > - , (SSNetworks, mapLines (spcPair . (networkUuid > + , (SSNetworks, mapLines (spcPair . (uuidOf > &&& (fromNonEmpty . networkName))) > . configNetworks $ cdata) > , (SSEnabledUserShutdown, return . show . clusterEnabledUserShutdown > diff --git a/test/hs/Test/Ganeti/Objects.hs > b/test/hs/Test/Ganeti/Objects.hs > index cbc7631..dcb12bc 100644 > --- a/test/hs/Test/Ganeti/Objects.hs > +++ b/test/hs/Test/Ganeti/Objects.hs > @@ -411,7 +411,7 @@ genEmptyCluster ncount = do > nodes <- vector ncount > version <- arbitrary > grp <- arbitrary > - let guuid = groupUuid grp > + let guuid = uuidOf grp > nodes' = zipWith (\n idx -> > let newname = takeWhile (/= '.') (nodeName n) > ++ "-" ++ show idx > @@ -452,7 +452,7 @@ genConfigDataWithNetworks old_cfg = do > let nets_unique = map ( \(name, net) -> net { networkName = name } ) > (zip net_names nets) > net_map = GenericContainer $ Map.fromList > - (map (\n -> (networkUuid n, n)) nets_unique) > + (map (\n -> (uuidOf n, n)) nets_unique) > new_cfg = old_cfg { configNetworks = net_map } > return new_cfg > > -- > 2.6.0.rc2.230.g3dd15c0 > > Hrvoje Ribicic Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Diese E-Mail ist vertraulich. Wenn Sie nicht der richtige Adressat sind, leiten Sie diese bitte nicht weiter, informieren Sie den Absender und löschen Sie die E-Mail und alle Anhänge. Vielen Dank. This e-mail is confidential. If you are not the right addressee please do not forward it, please inform the sender, and please erase this e-mail including any attachments. Thanks.
