Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/atmos/pars

parsers for config files around ey
https://github.com/atmos/pars

Last synced: 9 days ago
JSON representation

parsers for config files around ey

Awesome Lists containing this project

README

        

pars
====

A gem that provides parse routines for various linux file formats. A lot
of config and backup file formats on linux can be parsed into simple data
structures. The goal here is to write real grammars for things like lvmbackups
and xenstore-ls output so we can access the data easily in Ruby. We're
using [treetop](http://http://github.com/nathansobo/treetop/tree/master/ ) for
the fun ones.

Supported Files/Output from shell commands
------------------------------------------
* output generated by 'xm info' and 'xm list' on xen boxes
* output generated from 'xenstore-ls' on xen boxes
* lvm_backup files
* monit's xml status page

Specs
-----
Please run the specs if hack on this. Rake or autotest should both work fine.

% rake
(in /Users/atmos/Source/pars)
.......................................................................

Finished in 0.508595 seconds

71 examples, 0 failures

Doesn't that bring a big smile to your face?

Basics
------
The input file used below can be found as [ey04-data00](http://github.com/atmos/pars/tree/master/spec/fixtures/lvm_backups/ey04-data00)

% irb
>> require 'rubygems'
=> false
>> require 'pp'
=> true
>> require 'pars'
=> true
>> parser = Pars::LvmBackup::Parser.new
=> #
>> result = parser.parse(File.read('spec/fixtures/lvm_backups/ey04-data00'))
=> FileContents offset=0, "...\t\t\t\t]\n\t\t\t}\n\t\t}\n\t}\n}\n":
... (irb will return a huge datastructure here for the parsed result)
>> contents = result.eval({})
=> {"creation_host"=>"ey04-n00", "creation_time"=>1209700877, "description"=>"Created *after* executing 'lvchange --addtag ey04-s00031 /dev/ey04-data00/gfs-00003'", "version"=>1, "contents"=>"Text Format Volume Group", "ey04-data00"=>{"status"=>["RESIZEABLE", "READ", "WRITE", "CLUSTERED"], "seqno"=>13, "max_pv"=>0, "logical_volumes"=>{"root-build"=>{"status"=>["READ", "WRITE", "VISIBLE"], "segment_count"=>1, "id"=>"wguNtc-9t14-m6va-He59-M5Z2-OqT0-pfEw3R", "segment1"=>{"stripe_count"=>1, "start_extent"=>0, "type"=>"striped", "extent_count"=>7680, "stripes"=>["pv0", 0]}}, "gfs-00003"=>{"status"=>["READ", "WRITE", "VISIBLE"], "segment_count"=>1, "tags"=>["ey04-e00031", "ey04-s00032", "ey04-s00031"], "id"=>"YA7e0E-1gpD-DJAq-aSB5-3d72-SEEg-P11Y8C", "segment1"=>{"stripe_count"=>1, "start_extent"=>0, "type"=>"striped", "extent_count"=>3840, "stripes"=>["pv5", 0]}}}, "extent_size"=>8192, "max_lv"=>0, "id"=>"6jKJQg-pFTD-lff8-4xwL-oGk2-z0q2-WVRHTa", "physical_volumes"=>{"pv1"=>{"status"=>["ALLOCATABLE"], "device"=>"/dev/etherd/e0.1", "dev_size"=>1953546237, "id"=>"TEt3bz-id4I-fIfc-PeE0-IBvS-651d-DrDabH", "pe_start"=>384, "pe_count"=>238469}, "pv2"=>{"status"=>["ALLOCATABLE"], "device"=>"/dev/etherd/e0.2", "dev_size"=>1953546237, "id"=>"qmNvbz-LdYf-NBIs-bIR8-AcVT-51Ru-JTsd28", "pe_start"=>384, "pe_count"=>238469}, "pv3"=>{"status"=>["ALLOCATABLE"], "device"=>"/dev/etherd/e0.4", "dev_size"=>1953546237, "id"=>"XeHJ9t-gvQS-38mk-rfPI-RmHC-5eSM-hXufli", "pe_start"=>384, "pe_count"=>238469}, "pv4"=>{"status"=>["ALLOCATABLE"], "device"=>"/dev/etherd/e0.5", "dev_size"=>1953546237, "id"=>"tYhD6P-ZLel-Y5q2-Cj3B-zXll-MEuQ-DBnwrb", "pe_start"=>384, "pe_count"=>238469}, "pv5"=>{"status"=>["ALLOCATABLE"], "device"=>"/dev/etherd/e0.6", "tags"=>["eyinternal", "utility", "data"], "dev_size"=>1953546237, "id"=>"RZJH35-Xe5r-XAo4-7ZI5-jKR1-MVEL-Jz1PFg", "pe_start"=>384, "pe_count"=>238469}, "pv6"=>{"status"=>["ALLOCATABLE"], "device"=>"/dev/etherd/e0.7", "dev_size"=>1953546237, "id"=>"fpNgNS-ll7o-mXFI-1o2t-w38C-U6yH-o1UusH", "pe_start"=>384, "pe_count"=>238469}, "pv7"=>{"status"=>["ALLOCATABLE"], "device"=>"/dev/etherd/e0.3", "dev_size"=>1953546237, "id"=>"RB0cGk-7B7S-4HJ0-mnaj-9o6V-i1iF-rL5LHA", "pe_start"=>384, "pe_count"=>238469}, "pv0"=>{"status"=>["ALLOCATABLE"], "device"=>"/dev/etherd/e0.0p15", "tags"=>["eyinternal", "build"], "dev_size"=>468648117, "id"=>"eIctnq-lQsq-xkLb-w7yj-4m0U-kXeS-xY9qzo", "pe_start"=>384, "pe_count"=>57207}}}}
=> pp contents.keys
["creation_host",
"creation_time",
"description",
"version",
"contents",
"ey04-data00"]
=> nil
>> pp contents['ey04-data00'].keys
["status",
"seqno",
"max_pv",
"logical_volumes",
"extent_size",
"max_lv",
"id",
"physical_volumes"]
=> nil
>> pp contents['ey04-data00']['physical_volumes'].keys
["pv1", "pv2", "pv3", "pv4", "pv5", "pv6", "pv7", "pv0"]
=> nil
>> pp contents['ey04-data00']['physical_volumes']['pv1']
{"status"=>["ALLOCATABLE"],
"device"=>"/dev/etherd/e0.1",
"dev_size"=>1953546237,
"id"=>"TEt3bz-id4I-fIfc-PeE0-IBvS-651d-DrDabH",
"pe_start"=>384,
"pe_count"=>238469}
=> nil
>> pp contents['ey04-data00']['logical_volumes'].keys
["root-build", "gfs-00003"]
=> nil
>> pp contents['ey04-data00']['logical_volumes']['gfs-00003']
{"status"=>["READ", "WRITE", "VISIBLE"],
"segment_count"=>1,
"tags"=>["ey04-e00031", "ey04-s00032", "ey04-s00031"],
"id"=>"YA7e0E-1gpD-DJAq-aSB5-3d72-SEEg-P11Y8C",
"segment1"=>
{"stripe_count"=>1,
"start_extent"=>0,
"type"=>"striped",
"extent_count"=>3840,
"stripes"=>["pv5", 0]}}
=> nil