commit 10ba799ab08001d5435425e65f039f20cadd306e Author: Tony Asleson Date: Mon Oct 15 13:54:19 2012 -0700 python-lvm: Update example to work with lvm object removal. Signed-off-by: Tony Asleson Signed-off-by: Andy Grover --- python/example.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/python/example.py b/python/example.py index 67bb7e4..5c14ee1 100644 --- a/python/example.py +++ b/python/example.py @@ -31,9 +31,9 @@ def print_pv(pv): #Dump some information about a specific volume group -def print_vg(h, vg_name): +def print_vg(vg_name): #Open read only - vg = h.vgOpen(vg_name, 'r') + vg = lvm.vgOpen(vg_name, 'r') print 'Volume group:', vg_name, 'Size: ', vg.getSize() @@ -55,13 +55,13 @@ def print_vg(h, vg_name): vg.close() #Returns the name of a vg with space available -def find_vg_with_free_space(h): +def find_vg_with_free_space(): free_space = 0 rc = None - vg_names = l.listVgNames() + vg_names = lvm.listVgNames() for v in vg_names: - vg = h.vgOpen(v, 'r') + vg = lvm.vgOpen(v, 'r') c_free = vg.getFreeSize() if c_free > free_space: free_space = c_free @@ -72,13 +72,13 @@ def find_vg_with_free_space(h): #Walk through the volume groups and fine one with space in which we can #create a new logical volume -def create_delete_logical_volume(h): - vg_name = find_vg_with_free_space(h) +def create_delete_logical_volume(): + vg_name = find_vg_with_free_space() print 'Using volume group ', vg_name, ' for example' if vg_name: - vg = h.vgOpen(vg_name, 'w') + vg = lvm.vgOpen(vg_name, 'w') lv = vg.createLvLinear('python_lvm_ok_to_delete', vg.getFreeSize()) if lv: @@ -93,11 +93,11 @@ def create_delete_logical_volume(h): #Remove tag lv.removeTag(t) + lv.deactivate() + #Try to rename - lv.rename("python_lvm_ok_to_be_removed_shortly") + lv.rename("python_lvm_renamed") print 'LV name= ', lv.getName() - - lv.deactivate() lv.remove() vg.close() @@ -105,21 +105,16 @@ def create_delete_logical_volume(h): print 'No free space available to create demo lv!' if __name__ == '__main__': - #Create a new LVM instance - l = lvm.Liblvm() - #What version - print 'lvm version=', l.getVersion() + print 'lvm version=', lvm.getVersion() #Get a list of volume group names - vg_names = l.listVgNames() + vg_names = lvm.listVgNames() #For each volume group display some information about each of them for vg_i in vg_names: - print_vg(l, vg_i) + print_vg(vg_i) #Demo creating a logical volume - create_delete_logical_volume(l) + create_delete_logical_volume() - #Close - l.close()