diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2010-08-12 12:03:54 -0700 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2010-08-12 12:03:54 -0700 |
commit | ced5e57f16b055249be5012bf13bb90c8811eb2a (patch) | |
tree | a2aa5fee46efa459a44668414600298abb77dc1e /src | |
parent | beb3e08460695b9b97eaf57630347c032a51f244 (diff) | |
download | vyatta-cfg-ced5e57f16b055249be5012bf13bb90c8811eb2a.tar.gz vyatta-cfg-ced5e57f16b055249be5012bf13bb90c8811eb2a.zip |
add more functions to shell API
Diffstat (limited to 'src')
-rw-r--r-- | src/cli_shell_api.cpp | 57 | ||||
-rw-r--r-- | src/cstore/cstore.hpp | 8 |
2 files changed, 62 insertions, 3 deletions
diff --git a/src/cli_shell_api.cpp b/src/cli_shell_api.cpp index 7f0a4d1..f0ac34f 100644 --- a/src/cli_shell_api.cpp +++ b/src/cli_shell_api.cpp @@ -212,6 +212,14 @@ existsActive(const vector<string>& args) exit(cstore.cfgPathExists(args, true) ? 0 : 1); } +/* same as isEffective() in Perl API */ +static void +existsEffective(const vector<string>& args) +{ + UnionfsCstore cstore(true); + exit(cstore.cfgPathEffective(args) ? 0 : 1); +} + /* same as listNodes() in Perl API. * * outputs a string representing multiple nodes. this string MUST be @@ -247,6 +255,20 @@ listActiveNodes(const vector<string>& args) print_vec(cnodes, " ", "'"); } +/* same as listEffectiveNodes() in Perl API. + * + * outputs a string representing multiple nodes. this string MUST be + * "eval"ed into an array of nodes. see listNodes above. + */ +static void +listEffectiveNodes(const vector<string>& args) +{ + UnionfsCstore cstore(true); + vector<string> cnodes; + cstore.cfgPathGetEffectiveChildNodes(args, cnodes); + print_vec(cnodes, " ", "'"); +} + /* same as returnValue() in Perl API. outputs a string. */ static void returnValue(const vector<string>& args) @@ -271,6 +293,18 @@ returnActiveValue(const vector<string>& args) printf("%s", val.c_str()); } +/* same as returnEffectiveValue() in Perl API. outputs a string. */ +static void +returnEffectiveValue(const vector<string>& args) +{ + UnionfsCstore cstore(true); + string val; + if (!cstore.cfgPathGetEffectiveValue(args, val)) { + exit(1); + } + printf("%s", val.c_str()); +} + /* same as returnValues() in Perl API. * * outputs a string representing multiple values. this string MUST be @@ -318,6 +352,22 @@ returnActiveValues(const vector<string>& args) print_vec(vvec, " ", "'"); } +/* same as returnEffectiveValues() in Perl API. + * + * outputs a string representing multiple values. this string MUST be + * "eval"ed into an array of values. see returnValues above. + */ +static void +returnEffectiveValues(const vector<string>& args) +{ + UnionfsCstore cstore(true); + vector<string> vvec; + if (!cstore.cfgPathGetEffectiveValues(args, vvec)) { + exit(1); + } + print_vec(vvec, " ", "'"); +} + #define OP(name, exact, exact_err, min, min_err) \ { #name, exact, exact_err, min, min_err, &name } @@ -343,12 +393,19 @@ static OpT ops[] = { OP(exists, -1, NULL, 1, "Must specify config path"), OP(existsActive, -1, NULL, 1, "Must specify config path"), + OP(existsEffective, -1, NULL, 1, "Must specify config path"), + OP(listNodes, -1, NULL, -1, NULL), OP(listActiveNodes, -1, NULL, -1, NULL), + OP(listEffectiveNodes, -1, NULL, 1, "Must specify config path"), + OP(returnValue, -1, NULL, 1, "Must specify config path"), OP(returnActiveValue, -1, NULL, 1, "Must specify config path"), + OP(returnEffectiveValue, -1, NULL, 1, "Must specify config path"), + OP(returnValues, -1, NULL, 1, "Must specify config path"), OP(returnActiveValues, -1, NULL, 1, "Must specify config path"), + OP(returnEffectiveValues, -1, NULL, 1, "Must specify config path"), {NULL, -1, NULL, -1, NULL, NULL} }; diff --git a/src/cstore/cstore.hpp b/src/cstore/cstore.hpp index 34193c2..caf845b 100644 --- a/src/cstore/cstore.hpp +++ b/src/cstore/cstore.hpp @@ -174,6 +174,7 @@ public: bool active_cfg = false); bool cfgPathDefault(const vector<string>& path_comps, bool active_cfg = false); + /* observers for working AND active configs (at the same time). * MUST ONLY be used during config session. */ @@ -184,9 +185,10 @@ public: vector<string>& cnodes); void cfgPathGetChildNodesStatus(const vector<string>& path_comps, map<string, string>& cmap); - /* observers for "effective config" (a combination of working config, - * active config, and commit processing state) only. - * MUST ONLY be used during config session. + + /* observers for "effective config". can be used both during a config + * session and outside a config session. more detailed information + * can be found in the source file. */ bool cfgPathEffective(const vector<string>& path_comps); void cfgPathGetEffectiveChildNodes(const vector<string>& path_comps, |