Skip to content
Snippets Groups Projects
Commit 9b648ee7 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

storage: Add function to modify fields


This allows the “allocatable” flag on LVM PVs to be changed.

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent d91427ea
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,20 @@ class _Base:
"""
raise NotImplementedError()
def Modify(self, name, changes):
"""Modifies an entity within the storage unit.
@type name: string
@param name: Entity name
@type changes: dict
@param changes: New field values
"""
# Don't raise an error if no changes are requested
if changes:
raise errors.ProgrammerError("Unable to modify the following"
"fields: %r" % (changes.keys(), ))
class FileStorage(_Base):
"""File storage unit.
......@@ -298,6 +312,43 @@ class LvmPvStorage(_LvmBase):
(constants.SF_ALLOCATABLE, "pv_attr", _GetAllocatable),
]
def _SetAllocatable(self, name, allocatable):
"""Sets the "allocatable" flag on a physical volume.
@type name: string
@param name: Physical volume name
@type allocatable: bool
@param allocatable: Whether to set the "allocatable" flag
"""
args = ["pvchange", "--allocatable"]
if allocatable:
args.append("y")
else:
args.append("n")
args.append(name)
result = utils.RunCmd(args)
if result.failed:
raise errors.StorageError("Failed to modify physical volume,"
" pvchange output: %s" %
result.output)
def Modify(self, name, changes):
"""Modifies flags on a physical volume.
See L{_Base.Modify}.
"""
if constants.SF_ALLOCATABLE in changes:
self._SetAllocatable(name, changes[constants.SF_ALLOCATABLE])
del changes[constants.SF_ALLOCATABLE]
# Other changes will be handled (and maybe refused) by the base class.
return _LvmBase.Modify(self, name, changes)
class LvmVgStorage(_LvmBase):
"""LVM Volume Group storage unit.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment