The LVM class is used as a wrapper to the global lvm handle provided by the api.
LVM works by providing a “handle” that represents each object instance (volume groups, logical and physical volumes). This class provides the “global” lvm handle used to access each of the above mentioned objects:
from lvm2py import *
lvm = LVM()
Closes the lvm handle. Usually you would never need to use this method unless you are trying to do operations using the ctypes function wrappers in conversion.py
Raises:
Returns a new instance of VolumeGroup with the given name and added physycal volumes (devices):
from lvm2py import *
lvm = LVM()
vg = lvm.create_vg("myvg", ["/dev/sdb1", "/dev/sdb2"])
Args:
Raises:
Returns an instance of VolumeGroup. The name parameter should be an existing volume group. By default, all volume groups are open in “read” mode:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg")
To open a volume group with write permissions set the mode parameter to “w”:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg", "w")
Args:
Raises:
Returns the lvm handle provided by the api represented by a ctypes opaque structure. After calling the close() method this will return None.
Returns the lvm library version.
Obtains the lvm handle. Usually you would never need to use this method unless you are trying to do operations using the ctypes function wrappers in conversion.py
Raises:
Removes a volume group:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg", "w")
lvm.remove_vg(vg)
Args:
Raises:
Note
The VolumeGroup instance must be in write mode, otherwise CommitError is raised.
This class method overrides the default system directory:
from lvm2py import *
lvm = LVM()
lvm.set_system_dir("/path/to/dir")
Note
LVM probes the environment variable LVM_SYSTEM_DIR, if this is not set it will use the default directory (usually /etc/lvm/) .
Returns the lvm system directory. Returns None if you have not set it using the set_system_dir method.
Probes the system for volume groups and returns a list of VolumeGroup instances:
from lvm2py import *
lvm = LVM()
vgs = lvm.vgscan()
Raises:
The VolumeGroup class is used as a wrapper to the global vg_t handle provided by the LVM api.
LVM works by providing a “handle” that represents each object instance (volume groups, logical and physical volumes). This class provides the “global” vg_t handle used to do volume group operations. You need to provide an LVM instance to instantiate this class:
from lvm2py import *
lvm = LVM()
vg1 = lvm.get_vg("myexistingvg")
# or just provide the LVM instance
vg2 = VolumeGroup(lvm, "myexistingvg", mode="w")
Raises:
Note
To create a new volume group use the LVM method create_vg.
Initializes a device as a physical volume and adds it to the volume group:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg", "w")
vg.add_pv("/dev/sdbX")
*Args:*
* device (str): An existing device.
*Raises:*
* ValueError, CommitError, HandleError
Note
The VolumeGroup instance must be in write mode, otherwise CommitError is raised.
Closes the lvm and vg_t handle. Usually you would never need to use this method unless you are doing operations using the ctypes function wrappers in conversion.py
Raises:
Creates a logical volume and returns the LogicalVolume instance associated with the lv_t handle:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg", "w")
lv = vg.create_lv("mylv", 40, "MiB")
Args:
Raises:
Note
The VolumeGroup instance must be in write mode, otherwise CommitError is raised.
Returns the volume group extent count.
Returns the volume group extent size in the given units. Default units are MiB.
Args:
Returns the volume group free extent count.
Returns the volume group free size in the given units. Default units are MiB.
Args:
Returns a LogicalVolume instance given an existin logical volume name:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg", "w")
vg.get_lv("mylv")
Args:
Raises:
Returns the physical volume associated with the given device:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg", "w")
vg.get_pv("/dev/sdb1")
Args:
Raises:
Returns the vg_t handle.
Returns True if the VG is clustered, False otherwise.
Returns True if the VG is exported, False otherwise.
Returns True if the VG is partial, False otherwise.
Returns the LVM instance holding the lvm handle.
Probes the volume group for logical volumes and returns a list of LogicalVolume instances:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg")
lvs = vg.lvscan()
Raises:
Returns the maximum allowed logical volume count.
Returns the maximum allowed physical volume count.
Returns the mode the instance is operating on (‘r’ or ‘w’).
returns the name of the volume group.
Obtains the lvm and vg_t handle. Usually you would never need to use this method unless you are doing operations using the ctypes function wrappers in conversion.py
Raises:
Returns the physical volume count.
Probes the volume group for physical volumes and returns a list of PhysicalVolume instances:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg")
pvs = vg.pvscan()
Raises:
Removes all logical volumes from the volume group.
Raises:
Removes a logical volume from the volume group:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg", "w")
lv = vg.lvscan()[0]
vg.remove_lv(lv)
Args:
Raises:
Note
The VolumeGroup instance must be in write mode, otherwise CommitError is raised.
Removes a physical volume from the volume group:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg", "w")
pv = vg.pvscan()[0]
vg.remove_pv(pv)
Args:
Raises:
Note
The VolumeGroup instance must be in write mode, otherwise CommitError is raised. Also, when removing the last physical volume, the volume group is deleted in lvm, leaving the instance with a null handle.
Returns the volume group sequence number. This number increases everytime the volume group is modified.
Sets the volume group extent size in the given units:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myvg", "w")
vg.set_extent_size(2, "MiB")
Args:
Raises:
Note
The VolumeGroup instance must be in write mode, otherwise CommitError is raised.
Sets the volume group in write or read mode.
Args:
Returns the volume group size in the given units. Default units are MiB.
Args:
Returns the volume group uuid.
The PhysicalVolume class is used as a wrapper to the global pv_t handle provided by the LVM api.
LVM works by providing a “handle” that represents each object instance (volume groups, logical and physical volumes). This class provides the “global” pv_t handle used to do physical volume operations. You need to provide an VolumeGroup instance to instantiate this class:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myexistingvg")
# get pv from pvscan
pv1 = vg.pvscan()[0]
# get it by name
pv2 = vg.get_pv("/dev/sdb1")
# or just instantiate it
pv3 = PhysicalVolume(vg, name="/dev/sdb1")
Raises:
Note
To add a new physical volume use the VolumeGroup method add_pv.
Closes the lvm, vg_t and pv_t handle. Usually you would never need to use this method unless you are doing operations using the ctypes function wrappers in conversion.py
Raises:
Returns the device size in the given units. Default units are MiB.
Args:
Returns the free size in the given units. Default units are MiB.
Args:
Returns the pv_t handle.
Returns the physical volume mda count.
Returns the physical volume device path.
Obtains the lvm, vg_t and pv_t handle. Usually you would never need to use this method unless you are doing operations using the ctypes function wrappers in conversion.py
Raises:
Returns the physical volume size in the given units. Default units are MiB.
Args:
Returns the physical volume uuid.
Returns the VG instance holding the lvm and vg_t handle.
The LogicalVolume class is used as a wrapper to the global lv_t handle provided by the LVM api.
LVM works by providing a “handle” that represents each object instance (volume groups, logical and physical volumes). This class provides the “global” lv_t handle used to do logical volume operations. You need to provide an VolumeGroup instance to instantiate this class:
from lvm2py import *
lvm = LVM()
vg = lvm.get_vg("myexistingvg")
# get pv from pvscan
lv1 = vg.lvscan()[0]
# get it by name
lv2 = vg.get_lv("mylv")
# or just instantiate it
lv3 = LogicalVolume(vg, name="mylv")
Raises:
Note
To create a new logical volume use the VolumeGroup method create_lv.
Activates the logical volume.
Raises:
Closes the lvm, vg_t and lv_t handle. Usually you would never need to use this method unless you are doing operations using the ctypes function wrappers in conversion.py
Raises:
Deactivates the logical volume.
Raises:
Returns the lv_t handle.
Returns True if the logical volume is active, False otherwise.
Returns True if the logical volume is suspended, False otherwise.
Returns the logical volume name.
Obtains the lvm, vg_t and lv_t handle. Usually you would never need to use this method unless you are doing operations using the ctypes function wrappers in conversion.py
Raises:
Returns the logical volume size in the given units. Default units are MiB.
Args:
Returns the logical volume uuid.
Returns the VG instance holding the lvm and vg_t handle.
Raised when there is an error in committing changes to lvm due to invalid actions such as initiating devices as physical volumes that are already associated to another volume group or trying to perform operations on a read-only volume group.
Raised when the lvm handle for LVM, VolumeGroup, PhysicalVolume or LogicalVolume is null or for some reason it can’t be obtained (bad parameters, duplicate namespaces, etc...)