Automate LVM With Python - Script
Task Description ??
?? 7.1: Elasticity Task -
?(C)
??Automating LVM Partition using Python-Script.
* For this task I will use RedHat 8 ( "192.168.43.160" ) -
* & I have already attached new volumes of "5 GiB" ( '/dev/sdb' , '/dev/sdc' , '/dev/sdd' , '/dev/sde' ) to this VM -
* To know how to attach new volumes to VM in VirtualBox then visit below article -
* To do this task I create make a python file ("lvm.py") who have different classes & method for LVM (Logical Volume Management) , so that we don't need to interact LVM commands directly. To create this python file I will follow these steps -
1) Create "VolumeGroup" Class Which will Manage Volume Group
2) Create "LogicalVolume" Class Which will Manage Logical Volume
* I will use a pre-created python module "subprocess" to develop this program file. First I will import this module.
Step - 1 Create "VolumeGroup" Class -
(A) Create "__init__" Method -
(B) Create "refresh" Method -
(C) Create "create" method -
(D) Create "display" method -
(E) Create "extend" method -
(F) Create "merge" method -
(G) Create "reduce" method -
(H) Create "rename" method -
(I) Create "remove" method -
(J) Create "add" method -
Step - 2 Create "LogicalVolume" Class -
(A) Create "__init__" method -
(B) Create "refresh" method -
(C) Create "create" method -
(D) Create "format" method -
(E) Create "mount" method -
(F) Create "unmount" method -
(G) Create "extend" method -
(H) Create "reduce" method -
(I) Create "remove" method -
(J) Create "display" method -
"lvm.py" python is successfully developed.
Now who want to automate LVM then they can use this python code. & We don't need to interact directly with LVM command. We can use this python program.
<<** Automate LVM Using "lvm.py" **>>
* To automate LVM I will write a python program in "AutomateLVM.py" file.
Step -1 Take Input That in which ( Volume Group & Logical Volume ) user want to perform operation -
> 1 ---------- One is for Volume Group
> 2 ---------- Two is for Logical Volume
> 3 ---------- Three is for break from while last outer while loop
Step - 2 Operations For Volume Groups -
> Operation 'A' to 'E'
> Operation 'F' to 'I'
Step - 3 Operations For Logical Volume -
> Operations 'A' to 'E'
> Operations 'F' to 'I'
Step - 4 Break From Outer While loop & Clear Screen -
<<** Run "AutomateLVM.py" **>
* First I will perform operation for Volume Group.
1) For Volume Group -
(a) "arth" Volume Group -
> Create "arth"
> Display Information About Volume Group -
> Extend Volume Group -
> Exit 'I' -
> Create New Volume Group "lv3" -
> Merge "arth" into "lv3"
> Reduce "lv3" ('/dev/sdd') -
> Rename Volume Group "lv3" to "task" -
> Remove "task" -
2) For Logical Volume -
> Create "VG" -
> "lv1" Logical Volume in Volume Group "VG"
> Create "lv1"
> Display "lv1" Information -
> Format "lv1"
> Mount "lv1" at "/root/LVM/k/" -
> Unmount "lv1"
> Display Information -
> Extend "lv1"
> Reduce "lv1" -
> Remove "lv1" -
Now our Task is successfully completed.
Thank you for giving your time to this Article.
Junior Associate Consultant at MTX | 6x Salesforce Certified | 2X SAP Certified Developer | 1X Azure Cloud Certified | Salesforce Developer
4 å¹´Great job