C++ Configd Client Library

Introduction

Please refer to Configd Client Library for the general concepts behind the API. This document will cover only C++ specifics.

Mechanics

Before we can use the configd API we need to establish a connection to the daemon, instantiating the CfgClient object will do this. The destructor for the client object will close the connection.

#include <vyatta-cfg/client/CfgClient.hpp> int main() { CfgClient client; }

Once connected we can do a variety of actions on the system, one can configure the device, request the operational state of the device, or perform feature specific RPCs. When configuring the device via the Configd APIs one follows much the same procedure as with the CLI. One creates a configuration session, makes changes, commits those changes, then tears down the session. One may view the RUNNING datastore without a session being created. Sessions persist process exit and must be explicitly removed with SessionTeardown. The minimal configuration application looks like the following.

#include <string> #include <sstream> #include <unistd.h> #include <sys/types.h> #include <vyatta-cfg/client/CfgClient.hpp> int main() { CfgClient client; stringstream ss; ss << getpid(); client.SessionSetup(ss.str()); // do something to the configuration client.SessionTeardown(); }

From here, one may perform actions similar to what one does on the CLI. Since the interface here is meant for programatic interaction, one may also introspect on the data-model and the current state of the candidate tree to determine available actions, this is similar to using "tab-completion" to inspect the CLI.

Examples

Configuration

The following example uses the C++ configd API to set all dataplane interfaces to listen for DHCP addresses if no other address is assigned to that interface. While this is a silly thing to do, it demonstrates the basic mechanics of the this API.

#include <string> #include <vector> #include <iterator> #include <iostream> #include <unistd.h> #include <sys/types.h> #include <vyatta-cfg/client/CfgClient.hpp> using namespace std; void setup_interface_address(CfgClient& client, string intf_name) { cout << intf_name << ":"; vector<string> path { "interfaces", "dataplane", intf_name, "address" }; auto addrs = client.NodeGet(CfgClient::AUTO, path); copy(addrs.begin(), addrs.end(), ostream_iterator<string>(cout, ", ")); cout << endl; if (addrs.size() == 0) { path.push_back("dhcp"); client.Set(path); } } int main() { CfgClient client; stringstream ss; ss << getpid(); client.SessionSetup(ss.str()); try { for (auto interface : client.NodeGet(CfgClient::AUTO, { "interfaces", "dataplane" })) { setup_interface_address(client, interface); } client.Commit("setup interface addresses"); } catch (CfgClientException e) { cerr << e.what(); } client.SessionTeardown(); return 0; }

Below is a sample run of the above application.

RPC

One can also call an RPC via this interface.

Below is an example run of the RPC application.

Operational State Data

Finally one may query for operational data information.

Below is an example execution of this program.



Man Page

The following documentation was generated automatically using Doxygen.

CfgClient