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
|
#Dump some information about a specific volume group
|
||||||
def print_vg(h, vg_name):
|
def print_vg(vg_name):
|
||||||
#Open read only
|
#Open read only
|
||||||
vg = h.vgOpen(vg_name, 'r')
|
vg = lvm.vgOpen(vg_name, 'r')
|
||||||
|
|
||||||
print 'Volume group:', vg_name, 'Size: ', vg.getSize()
|
print 'Volume group:', vg_name, 'Size: ', vg.getSize()
|
||||||
|
|
||||||
@ -55,13 +55,13 @@ def print_vg(h, vg_name):
|
|||||||
vg.close()
|
vg.close()
|
||||||
|
|
||||||
#Returns the name of a vg with space available
|
#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
|
free_space = 0
|
||||||
rc = None
|
rc = None
|
||||||
|
|
||||||
vg_names = l.listVgNames()
|
vg_names = lvm.listVgNames()
|
||||||
for v in vg_names:
|
for v in vg_names:
|
||||||
vg = h.vgOpen(v, 'r')
|
vg = lvm.vgOpen(v, 'r')
|
||||||
c_free = vg.getFreeSize()
|
c_free = vg.getFreeSize()
|
||||||
if c_free > free_space:
|
if c_free > free_space:
|
||||||
free_space = c_free
|
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
|
#Walk through the volume groups and fine one with space in which we can
|
||||||
#create a new logical volume
|
#create a new logical volume
|
||||||
def create_delete_logical_volume(h):
|
def create_delete_logical_volume():
|
||||||
vg_name = find_vg_with_free_space(h)
|
vg_name = find_vg_with_free_space()
|
||||||
|
|
||||||
print 'Using volume group ', vg_name, ' for example'
|
print 'Using volume group ', vg_name, ' for example'
|
||||||
|
|
||||||
if vg_name:
|
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())
|
lv = vg.createLvLinear('python_lvm_ok_to_delete', vg.getFreeSize())
|
||||||
|
|
||||||
if lv:
|
if lv:
|
||||||
@ -93,11 +93,11 @@ def create_delete_logical_volume(h):
|
|||||||
#Remove tag
|
#Remove tag
|
||||||
lv.removeTag(t)
|
lv.removeTag(t)
|
||||||
|
|
||||||
#Try to rename
|
|
||||||
lv.rename("python_lvm_ok_to_be_removed_shortly")
|
|
||||||
print 'LV name= ', lv.getName()
|
|
||||||
|
|
||||||
lv.deactivate()
|
lv.deactivate()
|
||||||
|
|
||||||
|
#Try to rename
|
||||||
|
lv.rename("python_lvm_renamed")
|
||||||
|
print 'LV name= ', lv.getName()
|
||||||
lv.remove()
|
lv.remove()
|
||||||
|
|
||||||
vg.close()
|
vg.close()
|
||||||
@ -105,21 +105,16 @@ def create_delete_logical_volume(h):
|
|||||||
print 'No free space available to create demo lv!'
|
print 'No free space available to create demo lv!'
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#Create a new LVM instance
|
|
||||||
l = lvm.Liblvm()
|
|
||||||
|
|
||||||
#What version
|
#What version
|
||||||
print 'lvm version=', l.getVersion()
|
print 'lvm version=', lvm.getVersion()
|
||||||
|
|
||||||
#Get a list of volume group names
|
#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 each volume group display some information about each of them
|
||||||
for vg_i in vg_names:
|
for vg_i in vg_names:
|
||||||
print_vg(l, vg_i)
|
print_vg(vg_i)
|
||||||
|
|
||||||
#Demo creating a logical volume
|
#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