Вопрос

So here is a snippet from the config file I'd like to parse (It is an LVM2 Config):

VolGroup00 {
    id = "vyllep-rfI6-LCvO-h6mN-zYZu-hiAN-QShmG6"
        seqno = 3
        status = ["RESIZEABLE", "READ", "WRITE"]
        flags = []
        extent_size = 65536             # 32 Megabytes
        max_lv = 0
        max_pv = 0
        metadata_copies = 0

        physical_volumes {

                pv0 {
                        id = "1yLiSl-x0fp-ZkyU-HMQl-eTVt-xiId-cFnih0"
                        device = "/dev/xvda2"   # Hint only

                        status = ["ALLOCATABLE"]
                        flags = []
                        dev_size = 31246425     # 14.8995 Gigabytes
                        pe_start = 384
                        pe_count = 476  # 14.875 Gigabytes
                }
        }
}

I would like to parse this into a Perl data structure. What format is this config in? My guess is it looks likes a python data structure.

Any thoughts the format, or better yet, an existent module to parse it with?

Это было полезно?

Решение

The config uses a custom config language specifically for LVM. The lvm userspace tools include code to parse this language.

You could grab the userspace code for lvm2 and attempt to replicate its parser, maybe using Parse::RecDescent.

Or maybe the Perl Linux::LVM module in CPAN provides the functionality to extract the information you need.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top