'GetInstanceDisks' returns a list of disk objects for the given instance. 'GetDiskInfo' returns information about a disk given its uuid. These functions should be used instead of the Instance's disk method.
Also add the 'getDisk' and 'getInstDisks' functions in Haskell but leave 'getInstDisks' commented out, as it doesn't typecheck yet. Signed-off-by: Ilias Tsitsimpis <[email protected]> --- lib/config.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/Ganeti/Config.hs | 21 +++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/lib/config.py b/lib/config.py index 9662f2a..febc4ee 100644 --- a/lib/config.py +++ b/lib/config.py @@ -350,6 +350,52 @@ class ConfigWriter(object): nodegroup = self._UnlockedGetNodeGroup(node.group) return self._UnlockedGetGroupDiskParams(nodegroup) + def _UnlockedGetInstanceDisks(self, instance): + """Return the disks' info for the given instance + + This function is for internal use, when the config lock is already held. + + """ + return [self._UnlockedGetDiskInfo(disk) for disk in instance.disks] + + @_ConfigSync(shared=1) + def GetInstanceDisks(self, instance): + """Return the disks' info for the given instance + + @type instance: L{objects.Instance} + @param instance: The instance we want to know the disks for + + @rtype: List of L{objects.Disk} + @return: A list with all the disks' info + + """ + return self._UnlockedGetInstanceDisks(instance) + + def _UnlockedGetDiskInfo(self, disk_uuid): + """Returns information about an instance. + + This function is for internal use, when the config lock is already held. + + """ + if disk_uuid not in self._ConfigData().disks: + return None + + return self._ConfigData().disks[disk_uuid] + + @_ConfigSync(shared=1) + def GetDiskInfo(self, disk_uuid): + """Returns information about a disk. + + It takes the information from the configuration file. + + @param disk_uuid: UUID of the disk + + @rtype: L{objects.Disk} + @return: the disk object + + """ + return self._UnlockedGetDiskInfo(disk_uuid) + # pylint: disable=R0201 def _UnlockedGetInstanceNodes(self, instance, disks=None): """Get all disk-related nodes for an instance. diff --git a/src/Ganeti/Config.hs b/src/Ganeti/Config.hs index 790742e..de3da80 100644 --- a/src/Ganeti/Config.hs +++ b/src/Ganeti/Config.hs @@ -39,6 +39,7 @@ module Ganeti.Config , getOnlineNodes , getNode , getInstance + , getDisk , getGroup , getGroupNdParams , getGroupIpolicy @@ -49,6 +50,8 @@ module Ganeti.Config , getInstPrimaryNode , getInstMinorsForNode , getInstAllNodes + , getInstDisks + , getInstDisksByName , getFilledInstHvParams , getFilledInstBeParams , getFilledInstOsParams @@ -216,6 +219,12 @@ getInstance cfg name = (instName . (M.!) instances) instances in getItem "Instance" name by_name +-- | Looks up a disk by uuid. +getDisk :: ConfigData -> String -> ErrorResult Disk +getDisk cfg name = + let disks = fromContainer (configDisks cfg) + in getItem "Disk" name disks + -- | Looks up a node group by name or uuid. getGroup :: ConfigData -> String -> ErrorResult NodeGroup getGroup cfg name = @@ -334,6 +343,18 @@ getInstAllNodes cfg name = do pNode <- getInstPrimaryNode cfg name return . nub $ pNode:diskNodes +-- | Get disks for a given instance object. +getInstDisks :: ConfigData -> Instance -> ErrorResult [Disk] +getInstDisks _cfg = + -- mapM (getDisk cfg) . instDisks + return . instDisks + +-- | Get disks for a given instance. +-- The instance is specified by name or uuid. +getInstDisksByName :: ConfigData -> String -> ErrorResult [Disk] +getInstDisksByName cfg iname = + getInstance cfg iname >>= getInstDisks cfg + -- | Filters DRBD minors for a given node. getDrbdMinorsForNode :: String -> Disk -> [(Int, String)] getDrbdMinorsForNode node disk = -- 1.9.1
