ceph-volume: avoid unnecessary subprocess calls
These calls are slowing down `ceph-volume inventory`.
Especially because of the class `ceph_volume.util.device.Devices`.
It calls the class `ceph_volume.util.device.Device` for each device found
on the host which calls many times the binaries `lsblk`, `pvs`, `vgs`, `lvs` itself.
We can make only one call in `Devices()` to gather all details and use them during the whole runtime
current implementation:
```
1 0.000 0.000 0.892 0.892 device.py:35(__init__) (class Devices)
8 0.001 0.000 0.853 0.107 device.py:151(_parse)
56 0.002 0.000 0.882 0.016 process.py:154(call)
8 0.001 0.000 0.245 0.031 lvm.py:1099(get_lvs)
8 0.000 0.000 0.026 0.003 disk.py:231(lsblk)
8 0.000 0.000 0.435 0.054 device.py:278(_set_lvm_membership)
1 0.000 0.000 0.885 0.885 device.py:38(<listcomp>) (multiple calls to Device() class)
8/5 0.000 0.000 0.885 0.177 device.py:92(__init__) (class Device)
>>> timeit.timeit('Inventory([]).main()', setup='from ceph_volume.inventory import Inventory', number=1)
Device Path Size rotates available Model name
/dev/sdb 200.00 GB True True QEMU HARDDISK
/dev/sda 200.00 GB True False QEMU HARDDISK
/dev/sdc 200.00 GB True False QEMU HARDDISK
/dev/sdd 200.00 GB True False QEMU HARDDISK
/dev/vda 11.00 GB True False
0.
9309048530412838
>>>
```
new approach:
```
1 0.000 0.000 0.253 0.253 device.py:35(__init__) (class Devices)
5 0.000 0.000 0.144 0.029 device.py:167(_parse)
21 0.001 0.000 0.246 0.012 process.py:154(call)
1 0.000 0.000 0.032 0.032 lvm.py:1110(get_lvs)
1 0.000 0.000 0.005 0.005 disk.py:236(lsblk_all)
5 0.000 0.000 0.062 0.012 device.py:309(_set_lvm_membership)
1 0.000 0.000 0.179 0.179 device.py:41(<listcomp>) (multiple calls to Device() class)
5 0.000 0.000 0.179 0.036 device.py:99(__init__) (class Device)
>>> timeit.timeit('Inventory([]).main()', setup='from ceph_volume.inventory import Inventory', number=1)
Device Path Size rotates available Model name
/dev/sdb 200.00 GB True True QEMU HARDDISK
/dev/sda 200.00 GB True False QEMU HARDDISK
/dev/sdc 200.00 GB True False QEMU HARDDISK
/dev/sdd 200.00 GB True False QEMU HARDDISK
/dev/vda 11.00 GB True False
0.
2486933789914474
>>>
```
Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit
bea9f4b643ce32268ad79c0fc257b25ff2f8333c)