LGTM, thanks.

On Tue, Dec 17, 2013 at 10:28 AM, Santi Raffa <[email protected]> wrote:

> A large part of the complexity in this function is due to the need
> to translate from "template-specific" parameter names to
> "template-agnostic" parameter names. This logic is complex and having
> complex code for complex logic is okay.
>
> However, for all other cases, the additional complexity is not needed.
> Additionally this function would do the wrong thing silently for new,
> unhandled disk templates by just not changing the resulting paramters.
>
> This commit replaces the ad-hoc logic with a more generally useful
> logic while leaving the DRBD code carefully alone.
>
> Signed-off-by: Santi Raffa <[email protected]>
> ---
>  lib/objects.py |   26 +++++++-------------------
>  1 file changed, 7 insertions(+), 19 deletions(-)
>
> diff --git a/lib/objects.py b/lib/objects.py
> index 7e59f63..ea88a9d 100644
> --- a/lib/objects.py
> +++ b/lib/objects.py
> @@ -857,6 +857,7 @@ class Disk(ConfigObject):
>
>      result = list()
>      dt_params = disk_params[disk_template]
> +
>      if disk_template == constants.DT_DRBD8:
>
>  result.append(FillDict(constants.DISK_LD_DEFAULTS[constants.DT_DRBD8], {
>          constants.LDP_RESYNC_RATE: dt_params[constants.DRBD_RESYNC_RATE],
> @@ -884,25 +885,12 @@ class Disk(ConfigObject):
>          constants.LDP_STRIPES: dt_params[constants.DRBD_META_STRIPES],
>          }))
>
> -    elif disk_template in (constants.DT_FILE, constants.DT_SHARED_FILE):
> -      result.append(constants.DISK_LD_DEFAULTS[disk_template])
> -
> -    elif disk_template == constants.DT_PLAIN:
> -
>  result.append(FillDict(constants.DISK_LD_DEFAULTS[constants.DT_PLAIN], {
> -        constants.LDP_STRIPES: dt_params[constants.LV_STRIPES],
> -        }))
> -
> -    elif disk_template == constants.DT_BLOCK:
> -      result.append(constants.DISK_LD_DEFAULTS[constants.DT_BLOCK])
> -
> -    elif disk_template == constants.DT_RBD:
> -
>  result.append(FillDict(constants.DISK_LD_DEFAULTS[constants.DT_RBD], {
> -        constants.LDP_POOL: dt_params[constants.RBD_POOL],
> -        constants.LDP_ACCESS: dt_params[constants.RBD_ACCESS],
> -        }))
> -
> -    elif disk_template == constants.DT_EXT:
> -      result.append(constants.DISK_LD_DEFAULTS[constants.DT_EXT])
> +    else:
> +      defaults = constants.DISK_LD_DEFAULTS[disk_template]
> +      values = {}
> +      for field in defaults:
> +        values[field] = dt_params[field]
> +      result.append(FillDict(defaults, values))
>
>      return result
>
> --
> 1.7.10.4
>
>


-- 
Thomas Thrainer | Software Engineer | [email protected] |

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

Reply via email to