Commit a1556cfa authored by Iustin Pop's avatar Iustin Pop
Browse files

LVM: remove old tags when adding new ones



This patch adds a small helper function to clear an LV's tags, and
calls it at SetInfo time. We need this to be able to correctly track
instance renames, once we will call SetInfo at such times.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent e398546b
...@@ -813,12 +813,28 @@ class LogicalVolume(BlockDev): ...@@ -813,12 +813,28 @@ class LogicalVolume(BlockDev):
return (self._vg_name, snap_name) return (self._vg_name, snap_name)
def _RemoveOldInfo(self):
"""Try to remove old tags from the lv.
"""
result = utils.RunCmd(["lvs", "-o", "tags", "--noheadings", "--nosuffix",
self.dev_path])
_CheckResult(result)
raw_tags = result.stdout.strip()
if raw_tags:
for tag in raw_tags.split(","):
_CheckResult(utils.RunCmd(["lvchange", "--deltag",
tag.strip(), self.dev_path]))
def SetInfo(self, text): def SetInfo(self, text):
"""Update metadata with info text. """Update metadata with info text.
""" """
BlockDev.SetInfo(self, text) BlockDev.SetInfo(self, text)
self._RemoveOldInfo()
# Replace invalid characters # Replace invalid characters
text = re.sub("^[^A-Za-z0-9_+.]", "_", text) text = re.sub("^[^A-Za-z0-9_+.]", "_", text)
text = re.sub("[^-A-Za-z0-9_+.]", "_", text) text = re.sub("[^-A-Za-z0-9_+.]", "_", text)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment