diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2010-02-09 18:55:36 -0800 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2010-02-09 18:55:36 -0800 |
commit | 242d3138f5ab34de27a12ad8605aba3f58526afb (patch) | |
tree | 52c714abd6f5049df014cd1b3d46b53bc762a7e4 /lib/Vyatta | |
parent | a6c94c6dfc1605fa1928cff1ab013fe670da1404 (diff) | |
download | vyatta-cfg-242d3138f5ab34de27a12ad8605aba3f58526afb.tar.gz vyatta-cfg-242d3138f5ab34de27a12ad8605aba3f58526afb.zip |
add util function
Diffstat (limited to 'lib/Vyatta')
-rwxr-xr-x | lib/Vyatta/Config.pm | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/Vyatta/Config.pm b/lib/Vyatta/Config.pm index acd695f..633d747 100755 --- a/lib/Vyatta/Config.pm +++ b/lib/Vyatta/Config.pm @@ -729,6 +729,34 @@ sub parseTmpl { return ($is_multi, $is_text, $default); } +# $cfg_path: config path of the node. +# returns a hash ref containing attributes in the template +# or undef if specified node is not valid. +sub parseTmplAll { + my ($self, $cfg_path) = @_; + my @pdirs = split(/ +/, $cfg_path); + my %ret = (); + my $tpath = $self->getTmplPath(\@pdirs); + return unless $tpath; + return undef if (! -r "$tpath/node.def"); + open(my $tmpl, '<', "$tpath/node.def") or return undef; + foreach (<$tmpl>) { + if (/^multi:/) { + $ret{multi} = 1; + } elsif (/^tag:/) { + $ret{tag} = 1; + } elsif (/^type:\s+(\S+)\s*$/) { + $ret{type} = $1; + } elsif (/^default:\s+(\S+)\s*$/) { + $ret{default} = $1; + } elsif (/^help:\s+(\S.*)$/) { + $ret{help} = $1; + } + } + close($tmpl); + return \%ret; +} + ###### misc functions ###### # compare two value lists and return "deleted" and "added" lists. |