On Thu, Dec 5, 2013 at 11:30 AM, Santi Raffa <[email protected]> wrote:

> On Thu, Dec 5, 2013 at 10:30 AM, Thomas Thrainer <[email protected]>
> wrote:
> > I'm not quite sure why we should write this simple logic in this way. Is
> it
> > really easier to read than an if-elif-elif-else cascade? I doubt so. And
> the
> > few extra characters/lines won't hurt, IMHO.
>
> eh... I agree it's not the best. How about this?
>
> diff --git a/lib/cmdlib/instance.py b/lib/cmdlib/instance.py
> index d3070c4..49288f9 100644
> --- a/lib/cmdlib/instance.py
> +++ b/lib/cmdlib/instance.py
> @@ -849,19 +849,20 @@ class LUInstanceCreate(LogicalUnit):
>        # build the full file storage dir path
>        joinargs = []
>
> -      cfg_storage = {
> -        constants.DT_FILE: self.cfg.GetFileStorageDir,
> -        constants.DT_SHARED_FILE: self.cfg.GetSharedFileStorageDir,
> -        constants.DT_GLUSTER: self.cfg.GetGlusterStorageDir,
> -      }.get(self.op.disk_template, lambda: None)()
> +      try:
> +        cfg_storage = {
> +          constants.DT_FILE: self.cfg.GetFileStorageDir,
> +          constants.DT_SHARED_FILE: self.cfg.GetSharedFileStorageDir,
> +          constants.DT_GLUSTER: self.cfg.GetGlusterStorageDir,
> +        }[self.op.disk_template]()
>
> -      if not cfg_storage:
> +      except KeyError:
>          raise errors.OpPrereqError(
>            "Cluster file storage dir for {tpl} storage type not
> defined".format(
>              tpl=repr(self.op.disk_template)
>            ),
>            errors.ECODE_STATE
> -      )
> +        )
>
>        joinargs.append(cfg_storage)
>
>
Hmm, IMHO that's an example for the German word "verschlimmbessern". Try to
look it up on http://dict.leo.org.
I'm still in favor of the if-elif-elif-else thing, but if you really don't
like it, keep the first version.


> --
> Raffa Santi
> 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
>



-- 
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