def addtag(vg, lv, tag): lvname = "%s/%s" % (vg, lv) cmd = ("lvchange", ) + LVM_NOBACKUP + ("--addtag", tag) + (lvname, ) rc, out, err = _lvminfo.cmd(cmd, _lvminfo._getVGDevs((vg, ))) _lvminfo._invalidatelvs(vg, lv) if rc != 0: # Fix me: should be se.ChangeLogicalVolumeError but this not exists. raise se.MissingTagOnLogicalVolume("%s/%s" % (vg, lv), tag)
def _getVolumeTag(sdUUID, volUUID, tagPrefix): tags = lvm.getLV(sdUUID, volUUID).tags if TAG_VOL_UNINIT in tags: log.warning("Reloading uninitialized volume %s/%s", sdUUID, volUUID) lvm.invalidateVG(sdUUID) tags = lvm.getLV(sdUUID, volUUID).tags if TAG_VOL_UNINIT in tags: log.error("Found uninitialized volume: %s/%s", sdUUID, volUUID) raise se.VolumeDoesNotExist("%s/%s" % (sdUUID, volUUID)) for tag in tags: if tag.startswith(tagPrefix): return tag[len(tagPrefix):] else: log.error("Missing tag %s in volume: %s/%s. tags: %s", tagPrefix, sdUUID, volUUID, tags) raise se.MissingTagOnLogicalVolume(volUUID, tagPrefix)
def changeVolumeTag(self, tagPrefix, uuid): if tagPrefix not in VOLUME_TAGS: raise se.LogicalVolumeWrongTagError(tagPrefix) oldTag = "" for tag in lvm.getLV(self.sdUUID, self.volUUID).tags: if tag.startswith(tagPrefix): oldTag = tag break if not oldTag: raise se.MissingTagOnLogicalVolume(self.volUUID, tagPrefix) newTag = tagPrefix + uuid if oldTag != newTag: lvm.replaceLVTag(self.sdUUID, self.volUUID, oldTag, newTag)
def _getVolumeTag(sdUUID, volUUID, tagPrefix): for tag in lvm.getLV(sdUUID, volUUID).tags: if tag.startswith(tagPrefix): return tag[len(tagPrefix):] raise se.MissingTagOnLogicalVolume(volUUID, tagPrefix)