From 946ef718c9dc53ade475d54eba6e5a2657b4ba41 Mon Sep 17 00:00:00 2001 From: Chris Mildebrandt Date: Wed, 27 Aug 2014 17:29:04 -0700 Subject: [PATCH 01/10] Surround raise calls with try/finally to ensure the handle is closed. --- lvm2py/lv.py | 17 ++++--- lvm2py/lvm.py | 85 ++++++++++++++++++---------------- lvm2py/pv.py | 17 ++++--- lvm2py/vg.py | 123 ++++++++++++++++++++++++++++---------------------- 4 files changed, 138 insertions(+), 104 deletions(-) diff --git a/lvm2py/lv.py b/lvm2py/lv.py index 36407a1..1a39812 100644 --- a/lvm2py/lv.py +++ b/lvm2py/lv.py @@ -51,11 +51,13 @@ def __init__(self, vg, lvh=None, name=None): self.__vg = vg if name: self.__vg.open() - self.__lvh = lvm_lv_from_name(vg.handle, name) - if not bool(self.__lvh): - raise HandleError("Failed to initialize LV Handle.") - self.__uuid = lvm_lv_get_uuid(self.__lvh) - self.__vg.close() + try: + self.__lvh = lvm_lv_from_name(vg.handle, name) + if not bool(self.__lvh): + raise HandleError("Failed to initialize LV Handle.") + self.__uuid = lvm_lv_get_uuid(self.__lvh) + finally: + self.__vg.close() else: self.__lvh = lvh if not bool(self.__lvh): @@ -75,7 +77,10 @@ def open(self): self.vg.open() self.__lvh = lvm_lv_from_uuid(self.vg.handle, self.uuid) if not bool(self.__lvh): - raise HandleError("Failed to initialize LV Handle.") + try: + self.vg.close() + finally: + raise HandleError("Failed to initialize LV Handle.") def close(self): """ diff --git a/lvm2py/lvm.py b/lvm2py/lvm.py index fcedb5d..c1e3cdd 100644 --- a/lvm2py/lvm.py +++ b/lvm2py/lvm.py @@ -177,25 +177,28 @@ def create_vg(self, name, devices): """ self.open() vgh = lvm_vg_create(self.handle, name) - if not bool(vgh): + try: + if not bool(vgh): + self.close() + raise HandleError("Failed to create VG.") + for device in devices: + if not os.path.exists(device): + self._destroy_vg(vgh) + raise ValueError("%s does not exist." % device) + ext = lvm_vg_extend(vgh, device) + if ext != 0: + self._destroy_vg(vgh) + raise CommitError("Failed to extend Volume Group.") + try: + self._commit_vg(vgh) + except CommitError: + self._destroy_vg(vgh) + raise CommitError("Failed to add %s to VolumeGroup." % device) + vg = VolumeGroup(self, name) + return vg + finally: + self._close_vg(vgh) self.close() - raise HandleError("Failed to create VG.") - for device in devices: - if not os.path.exists(device): - self._destroy_vg(vgh) - raise ValueError("%s does not exist." % device) - ext = lvm_vg_extend(vgh, device) - if ext != 0: - self._destroy_vg(vgh) - raise CommitError("Failed to extend Volume Group.") - try: - self._commit_vg(vgh) - except CommitError: - self._destroy_vg(vgh) - raise CommitError("Failed to add %s to VolumeGroup." % device) - self._close_vg(vgh) - vg = VolumeGroup(self, name) - return vg def remove_vg(self, vg): """ @@ -221,15 +224,17 @@ def remove_vg(self, vg): is raised. """ vg.open() - rm = lvm_vg_remove(vg.handle) - if rm != 0: + try: + rm = lvm_vg_remove(vg.handle) + if rm != 0: + vg.close() + raise CommitError("Failed to remove VG.") + com = lvm_vg_write(vg.handle) + if com != 0: + vg.close() + raise CommitError("Failed to commit changes to disk.") + finally: vg.close() - raise CommitError("Failed to remove VG.") - com = lvm_vg_write(vg.handle) - if com != 0: - vg.close() - raise CommitError("Failed to commit changes to disk.") - vg.close() def vgscan(self): """ @@ -247,19 +252,21 @@ def vgscan(self): """ vg_list = [] self.open() - names = lvm_list_vg_names(self.handle) - if not bool(names): - return vg_list - vgnames = [] - vg = dm_list_first(names) - while vg: - c = cast(vg, POINTER(lvm_str_list)) - vgnames.append(c.contents.str) - if dm_list_end(names, vg): - # end of linked list - break - vg = dm_list_next(names, vg) - self.close() + try: + names = lvm_list_vg_names(self.handle) + if not bool(names): + return vg_list + vgnames = [] + vg = dm_list_first(names) + while vg: + c = cast(vg, POINTER(lvm_str_list)) + vgnames.append(c.contents.str) + if dm_list_end(names, vg): + # end of linked list + break + vg = dm_list_next(names, vg) + finally: + self.close() for name in vgnames: vginst = self.get_vg(name) vg_list.append(vginst) diff --git a/lvm2py/pv.py b/lvm2py/pv.py index d995bef..bd29413 100644 --- a/lvm2py/pv.py +++ b/lvm2py/pv.py @@ -55,11 +55,13 @@ def __init__(self, vg, pvh=None, name=None): self.__vg = vg if name: self.__vg.open() - self.__pvh = lvm_pv_from_name(vg.handle, name) - if not bool(self.__pvh): - raise HandleError("Failed to initialize PV Handle.") - self.__uuid = lvm_pv_get_uuid(self.__pvh) - self.__vg.close() + try: + self.__pvh = lvm_pv_from_name(vg.handle, name) + if not bool(self.__pvh): + raise HandleError("Failed to initialize PV Handle.") + self.__uuid = lvm_pv_get_uuid(self.__pvh) + finally: + self.__vg.close() else: self.__pvh = pvh if not bool(self.__pvh): @@ -79,7 +81,10 @@ def open(self): self.vg.open() self.__pvh = lvm_pv_from_uuid(self.vg.handle, self.uuid) if not bool(self.__pvh): - raise HandleError("Failed to initialize PV Handle.") + try: + self.vg.close() + finally: + raise HandleError("Failed to initialize PV Handle.") def close(self): """ diff --git a/lvm2py/vg.py b/lvm2py/vg.py index 336b15b..451ad95 100644 --- a/lvm2py/vg.py +++ b/lvm2py/vg.py @@ -56,13 +56,17 @@ def __init__(self, handle, name, mode="r"): # verify we can open this vg in the desired mode handle.open() vgh = lvm_vg_open(handle.handle, name, mode) - if not bool(vgh): - raise HandleError("Failed to initialize VG Handle.") - # Close the handle so we can proceed - cl = lvm_vg_close(vgh) - if cl != 0: - raise HandleError("Failed to close VG handle after init check.") - handle.close() + try: + if not bool(vgh): + raise HandleError("Failed to initialize VG Handle.") + # Close the handle so we can proceed + finally: + try: + cl = lvm_vg_close(vgh) + if cl != 0: + raise HandleError("Failed to close VG handle after init check.") + finally: + handle.close() def open(self): """ @@ -77,7 +81,10 @@ def open(self): self.lvm.open() self.__vgh = lvm_vg_open(self.lvm.handle, self.name, self.mode) if not bool(self.__vgh): - raise HandleError("Failed to initialize VG Handle.") + try: + self.lvm.close() + finally: + raise HandleError("Failed to initialize VG Handle.") def close(self): """ @@ -295,13 +302,15 @@ def add_pv(self, device): if not os.path.exists(device): raise ValueError("%s does not exist." % device) self.open() - ext = lvm_vg_extend(self.handle, device) - if ext != 0: + try: + ext = lvm_vg_extend(self.handle, device) + if ext != 0: + self.close() + raise CommitError("Failed to extend Volume Group.") + self._commit() + return PhysicalVolume(self, name=device) + finally: self.close() - raise CommitError("Failed to extend Volume Group.") - self._commit() - self.close() - return PhysicalVolume(self, name=device) def get_pv(self, device): """ @@ -372,12 +381,14 @@ def remove_pv(self, pv): """ name = pv.name self.open() - rm = lvm_vg_reduce(self.handle, name) - if rm != 0: + try: + rm = lvm_vg_reduce(self.handle, name) + if rm != 0: + self.close() + raise CommitError("Failed to remove %s." % name) + self._commit() + finally: self.close() - raise CommitError("Failed to remove %s." % name) - self._commit() - self.close() def pvscan(self): """ @@ -395,21 +406,23 @@ def pvscan(self): * HandleError """ self.open() - pv_list = [] - pv_handles = lvm_vg_list_pvs(self.handle) - if not bool(pv_handles): + try: + pv_list = [] + pv_handles = lvm_vg_list_pvs(self.handle) + if not bool(pv_handles): + return pv_list + pvh = dm_list_first(pv_handles) + while pvh: + c = cast(pvh, POINTER(lvm_pv_list)) + pv = PhysicalVolume(self, pvh=c.contents.pv) + pv_list.append(pv) + if dm_list_end(pv_handles, pvh): + # end of linked list + break + pvh = dm_list_next(pv_handles, pvh) return pv_list - pvh = dm_list_first(pv_handles) - while pvh: - c = cast(pvh, POINTER(lvm_pv_list)) - pv = PhysicalVolume(self, pvh=c.contents.pv) - pv_list.append(pv) - if dm_list_end(pv_handles, pvh): - # end of linked list - break - pvh = dm_list_next(pv_handles, pvh) - self.close() - return pv_list + finally: + self.close() def lvscan(self): """ @@ -427,21 +440,23 @@ def lvscan(self): * HandleError """ self.open() - lv_list = [] - lv_handles = lvm_vg_list_lvs(self.handle) - if not bool(lv_handles): + try: + lv_list = [] + lv_handles = lvm_vg_list_lvs(self.handle) + if not bool(lv_handles): + return lv_list + lvh = dm_list_first(lv_handles) + while lvh: + c = cast(lvh, POINTER(lvm_lv_list)) + lv = LogicalVolume(self, lvh=c.contents.lv) + lv_list.append(lv) + if dm_list_end(lv_handles, lvh): + # end of linked list + break + lvh = dm_list_next(lv_handles, lvh) return lv_list - lvh = dm_list_first(lv_handles) - while lvh: - c = cast(lvh, POINTER(lvm_lv_list)) - lv = LogicalVolume(self, lvh=c.contents.lv) - lv_list.append(lv) - if dm_list_end(lv_handles, lvh): - # end of linked list - break - lvh = dm_list_next(lv_handles, lvh) - self.close() - return lv_list + finally: + self.close() def create_lv(self, name, length, units): """ @@ -476,13 +491,15 @@ def create_lv(self, name, length, units): raise ValueError("Length not supported.") size = (self.size("B") / 100) * length self.open() - lvh = lvm_vg_create_lv_linear(self.handle, name, c_ulonglong(size)) - if not bool(lvh): + try: + lvh = lvm_vg_create_lv_linear(self.handle, name, c_ulonglong(size)) + if not bool(lvh): + self.close() + raise CommitError("Failed to create LV.") + lv = LogicalVolume(self, lvh=lvh) + return lv + finally: self.close() - raise CommitError("Failed to create LV.") - lv = LogicalVolume(self, lvh=lvh) - self.close() - return lv def remove_lv(self, lv): """ From 2b18789b07551fcfb99499e86c55f76adb7fb3b9 Mon Sep 17 00:00:00 2001 From: Chris Mildebrandt Date: Sat, 6 Sep 2014 11:22:43 -0700 Subject: [PATCH 02/10] Remove overzealous closing of volume groups. --- lvm2py/lv.py | 17 +++---- lvm2py/lvm.py | 89 +++++++++++++++++------------------ lvm2py/pv.py | 17 +++---- lvm2py/vg.py | 126 ++++++++++++++++++++++---------------------------- 4 files changed, 111 insertions(+), 138 deletions(-) diff --git a/lvm2py/lv.py b/lvm2py/lv.py index 1a39812..36407a1 100644 --- a/lvm2py/lv.py +++ b/lvm2py/lv.py @@ -51,13 +51,11 @@ def __init__(self, vg, lvh=None, name=None): self.__vg = vg if name: self.__vg.open() - try: - self.__lvh = lvm_lv_from_name(vg.handle, name) - if not bool(self.__lvh): - raise HandleError("Failed to initialize LV Handle.") - self.__uuid = lvm_lv_get_uuid(self.__lvh) - finally: - self.__vg.close() + self.__lvh = lvm_lv_from_name(vg.handle, name) + if not bool(self.__lvh): + raise HandleError("Failed to initialize LV Handle.") + self.__uuid = lvm_lv_get_uuid(self.__lvh) + self.__vg.close() else: self.__lvh = lvh if not bool(self.__lvh): @@ -77,10 +75,7 @@ def open(self): self.vg.open() self.__lvh = lvm_lv_from_uuid(self.vg.handle, self.uuid) if not bool(self.__lvh): - try: - self.vg.close() - finally: - raise HandleError("Failed to initialize LV Handle.") + raise HandleError("Failed to initialize LV Handle.") def close(self): """ diff --git a/lvm2py/lvm.py b/lvm2py/lvm.py index c1e3cdd..33dfd7e 100644 --- a/lvm2py/lvm.py +++ b/lvm2py/lvm.py @@ -177,28 +177,29 @@ def create_vg(self, name, devices): """ self.open() vgh = lvm_vg_create(self.handle, name) - try: - if not bool(vgh): - self.close() - raise HandleError("Failed to create VG.") - for device in devices: - if not os.path.exists(device): - self._destroy_vg(vgh) - raise ValueError("%s does not exist." % device) - ext = lvm_vg_extend(vgh, device) - if ext != 0: - self._destroy_vg(vgh) - raise CommitError("Failed to extend Volume Group.") - try: - self._commit_vg(vgh) - except CommitError: - self._destroy_vg(vgh) - raise CommitError("Failed to add %s to VolumeGroup." % device) - vg = VolumeGroup(self, name) - return vg - finally: - self._close_vg(vgh) + if not bool(vgh): self.close() + raise HandleError("Failed to create VG.") + for device in devices: + if not os.path.exists(device): + self._destroy_vg(vgh) + self.close() + raise ValueError("%s does not exist." % device) + ext = lvm_vg_extend(vgh, device) + if ext != 0: + self._destroy_vg(vgh) + self.close() + raise CommitError("Failed to extend Volume Group.") + try: + self._commit_vg(vgh) + except CommitError: + self._destroy_vg(vgh) + self.close() + raise CommitError("Failed to add %s to VolumeGroup." % device) + self._close_vg(vgh) + vg = VolumeGroup(self, name) + self.close() + return vg def remove_vg(self, vg): """ @@ -224,17 +225,15 @@ def remove_vg(self, vg): is raised. """ vg.open() - try: - rm = lvm_vg_remove(vg.handle) - if rm != 0: - vg.close() - raise CommitError("Failed to remove VG.") - com = lvm_vg_write(vg.handle) - if com != 0: - vg.close() - raise CommitError("Failed to commit changes to disk.") - finally: + rm = lvm_vg_remove(vg.handle) + if rm != 0: + vg.close() + raise CommitError("Failed to remove VG.") + com = lvm_vg_write(vg.handle) + if com != 0: vg.close() + raise CommitError("Failed to commit changes to disk.") + vg.close() def vgscan(self): """ @@ -252,21 +251,19 @@ def vgscan(self): """ vg_list = [] self.open() - try: - names = lvm_list_vg_names(self.handle) - if not bool(names): - return vg_list - vgnames = [] - vg = dm_list_first(names) - while vg: - c = cast(vg, POINTER(lvm_str_list)) - vgnames.append(c.contents.str) - if dm_list_end(names, vg): - # end of linked list - break - vg = dm_list_next(names, vg) - finally: - self.close() + names = lvm_list_vg_names(self.handle) + if not bool(names): + return vg_list + vgnames = [] + vg = dm_list_first(names) + while vg: + c = cast(vg, POINTER(lvm_str_list)) + vgnames.append(c.contents.str) + if dm_list_end(names, vg): + # end of linked list + break + vg = dm_list_next(names, vg) + self.close() for name in vgnames: vginst = self.get_vg(name) vg_list.append(vginst) diff --git a/lvm2py/pv.py b/lvm2py/pv.py index bd29413..d995bef 100644 --- a/lvm2py/pv.py +++ b/lvm2py/pv.py @@ -55,13 +55,11 @@ def __init__(self, vg, pvh=None, name=None): self.__vg = vg if name: self.__vg.open() - try: - self.__pvh = lvm_pv_from_name(vg.handle, name) - if not bool(self.__pvh): - raise HandleError("Failed to initialize PV Handle.") - self.__uuid = lvm_pv_get_uuid(self.__pvh) - finally: - self.__vg.close() + self.__pvh = lvm_pv_from_name(vg.handle, name) + if not bool(self.__pvh): + raise HandleError("Failed to initialize PV Handle.") + self.__uuid = lvm_pv_get_uuid(self.__pvh) + self.__vg.close() else: self.__pvh = pvh if not bool(self.__pvh): @@ -81,10 +79,7 @@ def open(self): self.vg.open() self.__pvh = lvm_pv_from_uuid(self.vg.handle, self.uuid) if not bool(self.__pvh): - try: - self.vg.close() - finally: - raise HandleError("Failed to initialize PV Handle.") + raise HandleError("Failed to initialize PV Handle.") def close(self): """ diff --git a/lvm2py/vg.py b/lvm2py/vg.py index 451ad95..975fa02 100644 --- a/lvm2py/vg.py +++ b/lvm2py/vg.py @@ -56,17 +56,14 @@ def __init__(self, handle, name, mode="r"): # verify we can open this vg in the desired mode handle.open() vgh = lvm_vg_open(handle.handle, name, mode) - try: - if not bool(vgh): - raise HandleError("Failed to initialize VG Handle.") - # Close the handle so we can proceed - finally: - try: - cl = lvm_vg_close(vgh) - if cl != 0: - raise HandleError("Failed to close VG handle after init check.") - finally: - handle.close() + if not bool(vgh): + handle.close() + raise HandleError("Failed to initialize VG Handle.") + # Close the handle so we can proceed + cl = lvm_vg_close(vgh) + if cl != 0: + raise HandleError("Failed to close VG handle after init check.") + handle.close() def open(self): """ @@ -81,10 +78,7 @@ def open(self): self.lvm.open() self.__vgh = lvm_vg_open(self.lvm.handle, self.name, self.mode) if not bool(self.__vgh): - try: - self.lvm.close() - finally: - raise HandleError("Failed to initialize VG Handle.") + raise HandleError("Failed to initialize VG Handle.") def close(self): """ @@ -302,15 +296,13 @@ def add_pv(self, device): if not os.path.exists(device): raise ValueError("%s does not exist." % device) self.open() - try: - ext = lvm_vg_extend(self.handle, device) - if ext != 0: - self.close() - raise CommitError("Failed to extend Volume Group.") - self._commit() - return PhysicalVolume(self, name=device) - finally: + ext = lvm_vg_extend(self.handle, device) + if ext != 0: self.close() + raise CommitError("Failed to extend Volume Group.") + self._commit() + self.close() + return PhysicalVolume(self, name=device) def get_pv(self, device): """ @@ -381,14 +373,12 @@ def remove_pv(self, pv): """ name = pv.name self.open() - try: - rm = lvm_vg_reduce(self.handle, name) - if rm != 0: - self.close() - raise CommitError("Failed to remove %s." % name) - self._commit() - finally: + rm = lvm_vg_reduce(self.handle, name) + if rm != 0: self.close() + raise CommitError("Failed to remove %s." % name) + self._commit() + self.close() def pvscan(self): """ @@ -406,23 +396,22 @@ def pvscan(self): * HandleError """ self.open() - try: - pv_list = [] - pv_handles = lvm_vg_list_pvs(self.handle) - if not bool(pv_handles): - return pv_list - pvh = dm_list_first(pv_handles) - while pvh: - c = cast(pvh, POINTER(lvm_pv_list)) - pv = PhysicalVolume(self, pvh=c.contents.pv) - pv_list.append(pv) - if dm_list_end(pv_handles, pvh): - # end of linked list - break - pvh = dm_list_next(pv_handles, pvh) - return pv_list - finally: + pv_list = [] + pv_handles = lvm_vg_list_pvs(self.handle) + if not bool(pv_handles): self.close() + return pv_list + pvh = dm_list_first(pv_handles) + while pvh: + c = cast(pvh, POINTER(lvm_pv_list)) + pv = PhysicalVolume(self, pvh=c.contents.pv) + pv_list.append(pv) + if dm_list_end(pv_handles, pvh): + # end of linked list + break + pvh = dm_list_next(pv_handles, pvh) + self.close() + return pv_list def lvscan(self): """ @@ -440,23 +429,22 @@ def lvscan(self): * HandleError """ self.open() - try: - lv_list = [] - lv_handles = lvm_vg_list_lvs(self.handle) - if not bool(lv_handles): - return lv_list - lvh = dm_list_first(lv_handles) - while lvh: - c = cast(lvh, POINTER(lvm_lv_list)) - lv = LogicalVolume(self, lvh=c.contents.lv) - lv_list.append(lv) - if dm_list_end(lv_handles, lvh): - # end of linked list - break - lvh = dm_list_next(lv_handles, lvh) - return lv_list - finally: + lv_list = [] + lv_handles = lvm_vg_list_lvs(self.handle) + if not bool(lv_handles): self.close() + return lv_list + lvh = dm_list_first(lv_handles) + while lvh: + c = cast(lvh, POINTER(lvm_lv_list)) + lv = LogicalVolume(self, lvh=c.contents.lv) + lv_list.append(lv) + if dm_list_end(lv_handles, lvh): + # end of linked list + break + lvh = dm_list_next(lv_handles, lvh) + self.close() + return lv_list def create_lv(self, name, length, units): """ @@ -491,15 +479,13 @@ def create_lv(self, name, length, units): raise ValueError("Length not supported.") size = (self.size("B") / 100) * length self.open() - try: - lvh = lvm_vg_create_lv_linear(self.handle, name, c_ulonglong(size)) - if not bool(lvh): - self.close() - raise CommitError("Failed to create LV.") - lv = LogicalVolume(self, lvh=lvh) - return lv - finally: + lvh = lvm_vg_create_lv_linear(self.handle, name, c_ulonglong(size)) + if not bool(lvh): self.close() + raise CommitError("Failed to create LV.") + lv = LogicalVolume(self, lvh=lvh) + self.close() + return lv def remove_lv(self, lv): """ From 2c6b62e6569ba704056e2f076eeced658399d85d Mon Sep 17 00:00:00 2001 From: Chris Mildebrandt Date: Mon, 8 Sep 2014 14:17:22 -0700 Subject: [PATCH 03/10] Ensure vg is closed when raising an exception --- lvm2py/lv.py | 1 + lvm2py/vg.py | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lvm2py/lv.py b/lvm2py/lv.py index 36407a1..92f16a0 100644 --- a/lvm2py/lv.py +++ b/lvm2py/lv.py @@ -53,6 +53,7 @@ def __init__(self, vg, lvh=None, name=None): self.__vg.open() self.__lvh = lvm_lv_from_name(vg.handle, name) if not bool(self.__lvh): + self.__vg.close() raise HandleError("Failed to initialize LV Handle.") self.__uuid = lvm_lv_get_uuid(self.__lvh) self.__vg.close() diff --git a/lvm2py/vg.py b/lvm2py/vg.py index 975fa02..d502d3e 100644 --- a/lvm2py/vg.py +++ b/lvm2py/vg.py @@ -55,15 +55,16 @@ def __init__(self, handle, name, mode="r"): self.__lvm = handle # verify we can open this vg in the desired mode handle.open() - vgh = lvm_vg_open(handle.handle, name, mode) - if not bool(vgh): + try: + vgh = lvm_vg_open(handle.handle, name, mode) + if not bool(vgh): + raise HandleError("Failed to initialize VG Handle.") + # Close the handle so we can proceed + cl = lvm_vg_close(vgh) + if cl != 0: + raise HandleError("Failed to close VG handle after init check.") + finally: handle.close() - raise HandleError("Failed to initialize VG Handle.") - # Close the handle so we can proceed - cl = lvm_vg_close(vgh) - if cl != 0: - raise HandleError("Failed to close VG handle after init check.") - handle.close() def open(self): """ From b6ddeff70dd2f1f9b72df31fab164e2958f751d1 Mon Sep 17 00:00:00 2001 From: Court Date: Mon, 22 Oct 2018 09:17:07 -0500 Subject: [PATCH 04/10] Update lv.py Modified for relative import. --- lvm2py/lv.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lvm2py/lv.py b/lvm2py/lv.py index 92f16a0..45c1ddd 100644 --- a/lvm2py/lv.py +++ b/lvm2py/lv.py @@ -13,9 +13,9 @@ #You should have received a copy of the GNU General Public License #along with lvm2py. If not, see . -from conversion import * -from exception import * -from util import * +from .conversion import * +from .exception import * +from .util import * class LogicalVolume(object): @@ -180,4 +180,4 @@ def deactivate(self): d = lvm_lv_deactivate(self.handle) self.close() if d != 0: - raise CommitError("Failed to deactivate LV.") \ No newline at end of file + raise CommitError("Failed to deactivate LV.") From d6e3921f7833533da2c59f32bfdda9de6d0db706 Mon Sep 17 00:00:00 2001 From: Court Date: Mon, 22 Oct 2018 09:18:01 -0500 Subject: [PATCH 05/10] modified for relative import --- lvm2py/vg.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lvm2py/vg.py b/lvm2py/vg.py index d502d3e..a80a084 100644 --- a/lvm2py/vg.py +++ b/lvm2py/vg.py @@ -15,11 +15,11 @@ from ctypes import cast, c_ulonglong, c_ulong import os -from conversion import * -from exception import * -from util import * -from pv import PhysicalVolume -from lv import LogicalVolume +from .conversion import * +from .exception import * +from .util import * +from .pv import PhysicalVolume +from .lv import LogicalVolume class VolumeGroup(object): @@ -572,4 +572,4 @@ def set_extent_size(self, length, units): self._commit() self.close() if ext != 0: - raise CommitError("Failed to set extent size.") \ No newline at end of file + raise CommitError("Failed to set extent size.") From 5f4ff5cfd5b655a769556de72849fac001116f3e Mon Sep 17 00:00:00 2001 From: Court Date: Mon, 22 Oct 2018 09:18:54 -0500 Subject: [PATCH 06/10] modified for relative import --- lvm2py/pv.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lvm2py/pv.py b/lvm2py/pv.py index d995bef..dea3a13 100644 --- a/lvm2py/pv.py +++ b/lvm2py/pv.py @@ -13,9 +13,9 @@ #You should have received a copy of the GNU General Public License #along with lvm2py. If not, see . -from conversion import * -from exception import * -from util import * +from .conversion import * +from .exception import * +from .util import * # Physical volume handling should not be needed anymore. Only physical volumes # bound to a vg contain useful information. Therefore the creation, @@ -171,4 +171,4 @@ def free(self, units="MiB"): self.open() size = lvm_pv_get_free(self.handle) self.close() - return size_convert(size, units) \ No newline at end of file + return size_convert(size, units) From 8c86a8069210b2b4d8a0e112ee6564f282b18d86 Mon Sep 17 00:00:00 2001 From: Court Date: Mon, 22 Oct 2018 09:19:19 -0500 Subject: [PATCH 07/10] modified for relative import --- lvm2py/lvm.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lvm2py/lvm.py b/lvm2py/lvm.py index 33dfd7e..a5ed4d7 100644 --- a/lvm2py/lvm.py +++ b/lvm2py/lvm.py @@ -14,10 +14,10 @@ #along with lvm2py. If not, see . from ctypes import cast, c_ulonglong, c_ulong -from conversion import * -from exception import * -from util import * -from vg import VolumeGroup +from .conversion import * +from .exception import * +from .util import * +from .vg import VolumeGroup import os @@ -267,4 +267,4 @@ def vgscan(self): for name in vgnames: vginst = self.get_vg(name) vg_list.append(vginst) - return vg_list \ No newline at end of file + return vg_list From c00b556bd042c875fdf41ef8ac7eafcecbfcb075 Mon Sep 17 00:00:00 2001 From: James Vasile Date: Mon, 25 Feb 2019 14:51:45 -0500 Subject: [PATCH 08/10] Add branch history/origin to README --- README.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index bf11617..2b914f4 100644 --- a/README.rst +++ b/README.rst @@ -3,10 +3,11 @@ Introduction lvm2py is a ctypes based binding for lvm's liblvm2app api. There are some limitations to what it can do compared to the command line options available. For example, the -resize of Physical and Logical volumes is not implemented in the api yet. Still, -contributions are planned in the near future. This is the first release, tested using -LVM 2.2, please report any bugs or suggestions to my github repo in the links below or -by e-mail: rq.sysadmin@gmail.com +resize of Physical and Logical volumes is not implemented in the api yet. + +As of February 2019, there were two people who had forked and patched +the upstream repo at https://github.com/xzased/lvm2py and this branch +just combines their minimal changes. Downloads ========= From 85dc7241e5d8b6cb3b35173a9a47fd19739e1cdd Mon Sep 17 00:00:00 2001 From: hobbez1 Date: Tue, 12 Jan 2021 10:06:53 +0200 Subject: [PATCH 09/10] Ensure that mode type is bytes --- lvm2py/vg.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lvm2py/vg.py b/lvm2py/vg.py index a80a084..8853297 100644 --- a/lvm2py/vg.py +++ b/lvm2py/vg.py @@ -48,15 +48,17 @@ class VolumeGroup(object): To create a new volume group use the LVM method create_vg. """ - def __init__(self, handle, name, mode="r"): + def __init__(self, handle, name, mode=b"r"): self.__name = name self.__vgh = None + if isinstance(mode, str): + mode = mode.encode() self.__mode = mode self.__lvm = handle # verify we can open this vg in the desired mode handle.open() try: - vgh = lvm_vg_open(handle.handle, name, mode) + vgh = lvm_vg_open(handle.handle, name, self.mode) if not bool(vgh): raise HandleError("Failed to initialize VG Handle.") # Close the handle so we can proceed From 7832ac818de873d4c814da166f14fe3805b02f3a Mon Sep 17 00:00:00 2001 From: hobbez1 Date: Tue, 12 Jan 2021 10:10:58 +0200 Subject: [PATCH 10/10] Make library python3 --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 50af13d..5da381d 100644 --- a/setup.py +++ b/setup.py @@ -8,5 +8,6 @@ author='Ruben Quinones', author_email='rq.sysadmin@gmail.com', url='http://github.com/xzased/lvm2py', + python_requires='>=3.5' packages=['lvm2py'], )