On Thu, Nov 06, 2014 at 12:30:37AM +0200, Alex Pyrgiotis wrote: > Add GetDiskInfoByName function that accepts a disk name as a parameter > and returns the associated disk object. The search algorithm follows > below: > > * Iterate all disks in config: > - Compare their name with the provided name. > - If there is a match, increment a counter and store the disk. > * Once all disks have been checked, if the counter is 1, return the > stored disk. > * Else, if there are more than one disks with the same name, raise a > proper exception. > > Signed-off-by: Alex Pyrgiotis <[email protected]> > > diff --git a/lib/config.py b/lib/config.py > index 9ad33fe..11cd2f0 100644 > --- a/lib/config.py > +++ b/lib/config.py > @@ -588,6 +588,40 @@ class ConfigWriter(object): > """ > return self._UnlockedGetDiskInfo(disk_uuid) > > + def _UnlockedGetDiskInfoByName(self, disk_name): > + """Return information about a named disk. > + > + Return disk information from the configuration file, searching with the > + name of the disk. > + > + @param disk_name: Name of the disk > + > + @rtype: L{objects.Disk} > + @return: the disk object > + > + """ > + disk = None > + count = 0 > + for d in self._ConfigData().disks.itervalues(): > + if d.name == disk_name: > + count += 1 > + disk = d > + > + if count > 1: > + raise errors.ConfigurationError("There are %s disks with this name: %s" > + % (count, disk_name)) > + > + return disk > + > + @_ConfigSync(shared=1) > + def GetDiskInfoByName(self, disk_name): > + """Return information about a named disk. > + > + This is a simple wrapper over L{_UnlockedGetDiskInfoByName}. > + > + """ > + return self._UnlockedGetDiskInfoByName(disk_name) > + > def _UnlockedGetDiskList(self): > """Get the list of disks. >
LGTM > -- > 1.7.10.4 > -- 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
