On Tue, Feb 21, 2012 at 11:05:15AM +0100, Iustin Pop wrote:
> On Mon, Feb 20, 2012 at 05:46:10PM +0100, Michael Hanselmann wrote:
> > Am 20. Februar 2012 15:21 schrieb Iustin Pop <[email protected]>:
> > > --- a/lib/objects.py
> > > +++ b/lib/objects.py
> > > -  result = dict()
> > >   if diskparams is None:
> > >     result = constants.DISK_DT_DEFAULTS.copy()
> > >   else:
> > > +    result = {}
> > >     # Update the disk parameter values for each disk template.
> > >     # The code iterates over constants.DISK_TEMPLATES because new 
> > > templates
> > >     # might have been added.
> > >     for template in constants.DISK_TEMPLATES:
> > > -      if template not in diskparams:
> > > -        result[template] = constants.DISK_DT_DEFAULTS[template].copy()
> > > -      else:
> > > -        result[template] = FillDict(constants.DISK_DT_DEFAULTS[template],
> > > -                                    diskparams[template])
> > > +      result[template] = FillDict(constants.DISK_DT_DEFAULTS[template],
> > > +                                  diskparams.get(template, {}))
> > 
> > Can we have something like “result = dict((dt, FillDict(…)) for dt in
> > constants.DISK_TEMPLATES]”? /me dislikes filling dictionaries by keys.
> 
> Hah, sure, I didn't realise that we can simplify since before the
> explicit loop was needed :)
> 
> Will resend.


diff --git a/lib/objects.py b/lib/objects.py
index e8c558c..8f3df18 100644
--- a/lib/objects.py
+++ b/lib/objects.py
@@ -155,13 +155,12 @@ def UpgradeDiskParams(diskparams):
   if diskparams is None:
     result = constants.DISK_DT_DEFAULTS.copy()
   else:
-    result = {}
     # Update the disk parameter values for each disk template.
     # The code iterates over constants.DISK_TEMPLATES because new templates
     # might have been added.
-    for template in constants.DISK_TEMPLATES:
-      result[template] = FillDict(constants.DISK_DT_DEFAULTS[template],
-                                  diskparams.get(template, {}))
+    result = dict((dt, FillDict(constants.DISK_DT_DEFAULTS[template],
+                                diskparams.get(template, {})))
+                  for dt in constants.DISK_TEMPLATES)
 
   return result

-- 
iustin

Reply via email to