Automate LVM With Python - Script

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" ) -

No alt text provided for this image

* & I have already attached new volumes of "5 GiB" ( '/dev/sdb' , '/dev/sdc' , '/dev/sdd' , '/dev/sde' ) to this VM -

No alt text provided for this image

* 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 -

No alt text provided for this image

(B) Create "refresh" Method -

No alt text provided for this image

(C) Create "create" method -

No alt text provided for this image

(D) Create "display" method -

No alt text provided for this image

(E) Create "extend" method -

No alt text provided for this image

(F) Create "merge" method -

No alt text provided for this image

(G) Create "reduce" method -

No alt text provided for this image

(H) Create "rename" method -

No alt text provided for this image

(I) Create "remove" method -

No alt text provided for this image

(J) Create "add" method -

No alt text provided for this image

Step - 2 Create "LogicalVolume" Class -

(A) Create "__init__" method -

No alt text provided for this image

(B) Create "refresh" method -

No alt text provided for this image

(C) Create "create" method -

No alt text provided for this image
No alt text provided for this image

(D) Create "format" method -

No alt text provided for this image

(E) Create "mount" method -

No alt text provided for this image

(F) Create "unmount" method -

No alt text provided for this image

(G) Create "extend" method -

No alt text provided for this image

(H) Create "reduce" method -

No alt text provided for this image

(I) Create "remove" method -

No alt text provided for this image

(J) Create "display" method -

No alt text provided for this image
"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

No alt text provided for this image

Step - 2 Operations For Volume Groups -

No alt text provided for this image

> Operation 'A' to 'E'

No alt text provided for this image

> Operation 'F' to 'I'

No alt text provided for this image

Step - 3 Operations For Logical Volume -

No alt text provided for this image

> Operations 'A' to 'E'

No alt text provided for this image

> Operations 'F' to 'I'

No alt text provided for this image

Step - 4 Break From Outer While loop & Clear Screen -

No alt text provided for this image

<<** Run "AutomateLVM.py" **>

No alt text provided for this image

* First I will perform operation for Volume Group.

1) For Volume Group -

(a) "arth" Volume Group -

> Create "arth"

No alt text provided for this image

> Display Information About Volume Group -

No alt text provided for this image

> Extend Volume Group -

No alt text provided for this image
No alt text provided for this image

> Exit 'I' -

No alt text provided for this image

> Create New Volume Group "lv3" -

No alt text provided for this image
No alt text provided for this image

> Merge "arth" into "lv3"

No alt text provided for this image
No alt text provided for this image

> Reduce "lv3" ('/dev/sdd') -

No alt text provided for this image
No alt text provided for this image

> Rename Volume Group "lv3" to "task" -

No alt text provided for this image

> Remove "task" -

No alt text provided for this image
No alt text provided for this image

2) For Logical Volume -

> Create "VG" -

No alt text provided for this image
No alt text provided for this image

> "lv1" Logical Volume in Volume Group "VG"

No alt text provided for this image

> Create "lv1"

No alt text provided for this image

> Display "lv1" Information -

No alt text provided for this image

> Format "lv1"

No alt text provided for this image

> Mount "lv1" at "/root/LVM/k/" -

No alt text provided for this image
No alt text provided for this image

> Unmount "lv1"

No alt text provided for this image
No alt text provided for this image

> Display Information -

No alt text provided for this image

> Extend "lv1"

No alt text provided for this image
No alt text provided for this image

> Reduce "lv1" -

No alt text provided for this image
No alt text provided for this image

> Remove "lv1" -

No alt text provided for this image
No alt text provided for this image


Now our Task is successfully completed.

Thank you for giving your time to this Article.

Chirag Goyal

Junior Associate Consultant at MTX | 6x Salesforce Certified | 2X SAP Certified Developer | 1X Azure Cloud Certified | Salesforce Developer

4 å¹´

Great job

要查看或添加评论,请登录

Govind Bhardwaj的更多文章

社区洞察

其他会员也浏览了