X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/6c881c52b3f5b040d762a3c0e35b35fab7cfd6a5..a7f884d3bebdbce19bc75e95d107e2ffd6840d2a:/lib/storage.py diff --git a/lib/storage.py b/lib/storage.py index b4b303a..cf87686 100644 --- a/lib/storage.py +++ b/lib/storage.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2009 Google Inc. +# Copyright (C) 2009, 2011 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,6 +23,14 @@ """ +# pylint: disable-msg=W0232,R0201 + +# W0232, since we use these as singletons rather than object holding +# data + +# R0201, for the same reason + +# TODO: FileStorage initialised with paths whereas the others not import logging @@ -50,7 +58,7 @@ class _Base: """ raise NotImplementedError() - def Modify(self, name, changes): + def Modify(self, name, changes): # pylint: disable-msg=W0613 """Modifies an entity within the storage unit. @type name: string @@ -76,7 +84,7 @@ class _Base: raise NotImplementedError() -class FileStorage(_Base): +class FileStorage(_Base): # pylint: disable-msg=W0223 """File storage unit. """ @@ -153,7 +161,7 @@ class FileStorage(_Base): return values -class _LvmBase(_Base): +class _LvmBase(_Base): # pylint: disable-msg=W0223 """Base class for LVM storage containers. @cvar LIST_FIELDS: list of tuples consisting of three elements: SF_* @@ -248,8 +256,10 @@ class _LvmBase(_Base): if callable(mapper): # we got a function, call it with all the declared fields - val = mapper(*values) + val = mapper(*values) # pylint: disable-msg=W0142 elif len(values) == 1: + assert mapper is None, ("Invalid mapper value (neither callable" + " nor None) for one-element fields") # we don't have a function, but we had a single field # declared, pass it unchanged val = values[0] @@ -324,18 +334,23 @@ class _LvmBase(_Base): yield fields -class LvmPvStorage(_LvmBase): - """LVM Physical Volume storage unit. +def _LvmPvGetAllocatable(attr): + """Determines whether LVM PV is allocatable. + + @rtype: bool """ - @staticmethod - def _GetAllocatable(attr): - if attr: - return (attr[0] == "a") - else: - logging.warning("Invalid PV attribute: %r", attr) - return False + if attr: + return (attr[0] == "a") + else: + logging.warning("Invalid PV attribute: %r", attr) + return False + +class LvmPvStorage(_LvmBase): # pylint: disable-msg=W0223 + """LVM Physical Volume storage unit. + + """ LIST_COMMAND = "pvs" # Make sure to update constants.VALID_STORAGE_FIELDS when changing field @@ -345,7 +360,7 @@ class LvmPvStorage(_LvmBase): (constants.SF_SIZE, ["pv_size"], _ParseSize), (constants.SF_USED, ["pv_used"], _ParseSize), (constants.SF_FREE, ["pv_free"], _ParseSize), - (constants.SF_ALLOCATABLE, ["pv_attr"], _GetAllocatable), + (constants.SF_ALLOCATABLE, ["pv_attr"], _LvmPvGetAllocatable), ] def _SetAllocatable(self, name, allocatable):