16 #ifndef HAVE_PRE_0_7_6_SYSREPO
23 TranslatorDatabase::TranslatorDatabase(S_Session session,
const string& model)
33 if ((
model_ == KEA_DHCP4_SERVER) ||
34 (
model_ == KEA_DHCP6_SERVER)) {
37 }
catch (
const sysrepo_exception& ex) {
39 "sysrepo error getting database access at '" << xpath
40 <<
"': " << ex.
what());
43 "getDatabase not implemented for the model: " <<
model_);
53 result->set(
"type", type);
56 result->set(
"user", user);
60 result->set(
"password", password);
64 result->set(
"host", host);
68 result->set(
"name", name);
72 result->set(
"persist", persist);
76 result->set(
"port", port);
80 result->set(
"lfc-interval", lfc_interval);
84 result->set(
"readonly", readonly);
87 if (connect_timeout) {
88 result->set(
"connect-timeout", connect_timeout);
92 result->set(
"contact-points", contact_points);
96 result->set(
"keyspace", keyspace);
100 result->set(
"max-reconnect-tries", max_reconnect);
103 if (reconnect_time) {
104 result->set(
"reconnect-wait-time", reconnect_time);
107 if (request_timeout) {
108 result->set(
"request-timeout", request_timeout);
112 result->set(
"tcp-keepalive", keepalive);
116 result->set(
"tcp-nodelay", nodelay);
120 result->set(
"consistency", consistency);
123 if (serial_consistency) {
124 result->set(
"serial-consistency", serial_consistency);
127 if (max_row_errors) {
128 result->set(
"max-row-errors", max_row_errors);
132 result->set(
"user-context", Element::fromJSON(context->stringValue()));
142 if ((
model_ == KEA_DHCP4_SERVER) ||
143 (
model_ == KEA_DHCP6_SERVER)) {
147 "setDatabase not implemented for the model: " <<
model_);
149 }
catch (
const sysrepo_exception& ex) {
151 "sysrepo error setting database access '" << elem->str()
152 <<
"' at '" << xpath <<
"': " << ex.
what());
170 setItem(xpath +
"/database-type", type, SR_STRING_T);
174 setItem(xpath +
"/user", user, SR_STRING_T);
178 setItem(xpath +
"/password", password, SR_STRING_T);
182 setItem(xpath +
"/host", host, SR_STRING_T);
186 setItem(xpath +
"/name", name, SR_STRING_T);
190 setItem(xpath +
"/persist", persist, SR_BOOL_T);
194 setItem(xpath +
"/port", port, SR_UINT16_T);
198 setItem(xpath +
"/lfc-interval", lfc_interval, SR_UINT32_T);
202 setItem(xpath +
"/readonly", readonly, SR_BOOL_T);
205 if (connect_timeout) {
206 setItem(xpath +
"/connect-timeout", connect_timeout, SR_UINT32_T);
209 if (contact_points) {
210 setItem(xpath +
"/contact-points", contact_points, SR_STRING_T);
214 setItem(xpath +
"/keyspace", keyspace, SR_STRING_T);
218 setItem(xpath +
"/max-reconnect-tries", max_reconnect, SR_UINT32_T);
221 if (reconnect_wait) {
222 setItem(xpath +
"/reconnect-wait-time", reconnect_wait, SR_UINT32_T);
225 if (request_timeout) {
226 setItem(xpath +
"/request-timeout", request_timeout, SR_UINT32_T);
230 setItem(xpath +
"/tcp-keepalive", keepalive, SR_UINT32_T);
234 setItem(xpath +
"/tcp-nodelay", nodelay, SR_BOOL_T);
238 setItem(xpath +
"/consistency", consistency, SR_STRING_T);
241 if (serial_consistency) {
242 setItem(xpath +
"/serial-consistency", serial_consistency, SR_STRING_T);
245 if (max_row_errors) {
246 setItem(xpath +
"/max-row-errors", max_row_errors, SR_UINT32_T);
250 setItem(xpath +
"/user-context", Element::create(context->str()),
267 if ((
model_ == KEA_DHCP4_SERVER) ||
268 (
model_ == KEA_DHCP6_SERVER)) {
271 }
catch (
const sysrepo_exception& ex) {
273 "sysrepo error getting database accesses at '" << xpath
274 <<
"': " << ex.
what());
277 "getDatabases not implemented for the model: " <<
model_);
282 S_Iter_Value iter =
getIter(xpath);
289 const string& database =
getNext(iter);
290 if (database.empty()) {
295 if (result->size() > 0) {
305 if ((
model_ == KEA_DHCP4_SERVER) ||
306 (
model_ == KEA_DHCP6_SERVER)) {
310 "setDatabases not implemented for the model: "
313 }
catch (
const sysrepo_exception& ex) {
315 "sysrepo error setting database accesses '" << elem->str()
316 <<
"' at '" << xpath <<
"': " << ex.
what());
327 for (
size_t i = 0; i < elem->size(); ++i) {
329 if (!database->contains(
"type")) {
332 string type = database->get(
"type")->stringValue();
334 key << xpath <<
"[database-type='" << type <<
"']";
A generic exception that is thrown when a function is not implemented.
isc::data::ConstElementPtr getDatabases(const std::string &xpath)
Get and translate database accesses from YANG to JSON.
void setDatabases(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set database accesses from JSON to YANG.
isc::data::ElementPtr getDatabase(const std::string &xpath)
Get and translate a database access from YANG to JSON.
Between YANG and JSON translator class for basic values.
TranslatorDatabases(sysrepo::S_Session session, const std::string &model)
Constructor.
boost::shared_ptr< Element > ElementPtr
isc::data::ElementPtr getDatabaseKea(const std::string &xpath)
getDatabase JSON for kea-dhcp[46]-server models.
sysrepo::S_Iter_Value getIter(const std::string &xpath)
List iterator methods keeping the session private.
isc::data::ElementPtr getDatabasesKea(const std::string &xpath)
getDatabases JSON for kea-dhcp[46]-server models.
virtual ~TranslatorDatabase()
Destructor.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
void setDatabasesKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setDatabases for kea-dhcp[46]-server models.
void setItem(const std::string &xpath, isc::data::ConstElementPtr elem, sr_type_t type)
Translate and set basic value from JSON to YANG.
A generic exception that is thrown when an unexpected error condition occurs.
std::string model_
The model.
Database access translation between YANG and JSON.
boost::shared_ptr< const Element > ConstElementPtr
std::string getNext(sysrepo::S_Iter_Value iter)
Get xpath of the next YANG list item.
static isc::data::ConstElementPtr getContext(isc::data::ConstElementPtr parent)
Get user context.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void delItem(const std::string &xpath)
Delete basic value from YANG.
Defines the logger used by the top-level component of kea-dhcp-ddns.
isc::data::ElementPtr getItem(const std::string &xpath)
Get and translate basic value from YANG to JSON.
virtual ~TranslatorDatabases()
Destructor.
void setDatabase(const std::string &xpath, isc::data::ConstElementPtr elem, bool skip=false)
Translate and set database access from JSON to YANG.
void setDatabaseKea(const std::string &xpath, isc::data::ConstElementPtr elem, bool skip)
setDatabase for kea-dhcp[46]-server models.