LGTM.

Thanks,
Jose

On Apr 16 15:19, Ilias Tsitsimpis wrote:
> '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        | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/Ganeti/Config.hs | 21 +++++++++++++++++++++
>  2 files changed, 72 insertions(+)
> 
> diff --git a/lib/config.py b/lib/config.py
> index 54df32e..f926e30 100644
> --- a/lib/config.py
> +++ b/lib/config.py
> @@ -350,6 +350,57 @@ class ConfigWriter(object):
>      nodegroup = self._UnlockedGetNodeGroup(node.group)
>      return self._UnlockedGetGroupDiskParams(nodegroup)
>  
> +  def _UnlockedGetInstanceDisks(self, inst_uuid):
> +    """Return the disks' info for the given instance
> +
> +    @type inst_uuid: string
> +    @param inst_uuid: The UUID of the instance we want to know the disks for
> +
> +    @rtype: List of L{objects.Disk}
> +    @return: A list with all the disks' info
> +
> +    """
> +    instance = self._UnlockedGetInstanceInfo(inst_uuid)
> +    if instance is None:
> +      raise errors.ConfigurationError("Unknown instance '%s'" % inst_uuid)
> +
> +    return [self._UnlockedGetDiskInfo(disk_uuid)
> +            for disk_uuid in instance.disks]
> +
> +  @_ConfigSync(shared=1)
> +  def GetInstanceDisks(self, inst_uuid):
> +    """Return the disks' info for the given instance
> +
> +    This is a simple wrapper over L{_UnlockedGetInstanceDisks}.
> +
> +    """
> +    return self._UnlockedGetInstanceDisks(inst_uuid)
> +
> +  def _UnlockedGetDiskInfo(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
> +
> +    """
> +    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.
> +
> +    This is a simple wrapper over L{_UnlockedGetDiskInfo}.
> +
> +    """
> +    return self._UnlockedGetDiskInfo(disk_uuid)
> +
>    def _UnlockedGetInstanceNodes(self, inst_uuid):
>      """Get all disk-related nodes for an instance.
>  
> diff --git a/src/Ganeti/Config.hs b/src/Ganeti/Config.hs
> index 790742e..bfffc2e 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
> +    , getInstDisksFromObj
>      , 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.
> +-- The instance is specified by name or uuid.
> +getInstDisks :: ConfigData -> String -> ErrorResult [Disk]
> +getInstDisks cfg =
> +  -- getInstance cfg iname >>= mapM (getDisk cfg) . instDisks
> +  liftM instDisks . getInstance cfg
> +
> +-- | Get disks for a given instance object.
> +getInstDisksFromObj :: ConfigData -> Instance -> ErrorResult [Disk]
> +getInstDisksFromObj cfg =
> +  getInstDisks cfg . instUuid
> +
>  -- | Filters DRBD minors for a given node.
>  getDrbdMinorsForNode :: String -> Disk -> [(Int, String)]
>  getDrbdMinorsForNode node disk =
> -- 
> 1.9.1
> 

-- 
Jose Antonio Lopes
Ganeti Engineering
Google Germany GmbH
Dienerstr. 12, 80331, München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores
Steuernummer: 48/725/00206
Umsatzsteueridentifikationsnummer: DE813741370

Reply via email to