mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
python-lvm: Update example to work with lvm object removal.
Signed-off-by: Tony Asleson <tasleson@redhat.com> Signed-off-by: Andy Grover <agrover@redhat.com>
This commit is contained in:
parent
12b631a676
commit
10ba799ab0
@ -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)
|
||||
|
||||
#Try to rename
|
||||
lv.rename("python_lvm_ok_to_be_removed_shortly")
|
||||
print 'LV name= ', lv.getName()
|
||||
|
||||
lv.deactivate()
|
||||
|
||||
#Try to rename
|
||||
lv.rename("python_lvm_renamed")
|
||||
print 'LV name= ', lv.getName()
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user