1

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?

Michael Slade
  • 13,802
  • 2
  • 39
  • 44
GoldenNewby
  • 4,382
  • 8
  • 33
  • 44
  • could be something specific to lvm2... – Marc B Apr 17 '12 at 00:50
  • "looks likes a python data structure" makes no sense. Maybe you meant "looks like python code"? But it's my understanding that Python uses indentation instead of curlies, so I strongly doubt that. – ikegami Apr 17 '12 at 06:22

1 Answers1

8

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.

Michael Slade
  • 13,802
  • 2
  • 39
  • 44