16 #ifndef HAVE_PRE_0_7_6_SYSREPO
23 TranslatorSubnet::TranslatorSubnet(S_Session session,
const string& model)
41 if (
model_ == IETF_DHCPV6_SERVER) {
43 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
44 (
model_ == KEA_DHCP6_SERVER)) {
47 }
catch (
const sysrepo_exception& ex) {
49 "sysrepo error getting subnet at '" << xpath
50 <<
"': " << ex.
what());
53 "getSubnet not implemented for the model: " <<
model_);
64 result->set(
"pools", pools);
67 if (pools && (pools->size() > 0)) {
68 result->set(
"pd-pools", pools);
74 result->set(
"subnet", subnet);
79 result->set(
"id",
id);
86 context->set(
"description", description);
87 result->set(
"user-context", context);
97 if (
model_ == KEA_DHCP6_SERVER) {
100 result->set(
"preferred-lifetime", preferred);
104 result->set(
"min-preferred-lifetime", min_pref);
108 result->set(
"max-preferred-lifetime", max_pref);
113 result->set(
"valid-lifetime", valid);
117 result->set(
"min-valid-lifetime", min_valid);
121 result->set(
"max-valid-lifetime", max_valid);
126 result->set(
"renew-timer", renew);
130 result->set(
"rebind-timer", rebind);
134 result->set(
"calculate-tee-times", calculate);
138 result->set(
"t1-percent", t1_percent);
142 result->set(
"t2-percent", t2_percent);
145 if (options && (options->size() > 0)) {
146 result->set(
"option-data", options);
149 if (pools && (pools->size() > 0)) {
150 result->set(
"pools", pools);
152 if (
model_ == KEA_DHCP6_SERVER) {
154 if (pools && (pools->size() > 0)) {
155 result->set(
"pd-pools", pools);
162 result->set(
"subnet", subnet);
165 result->set(
"interface", interface);
167 if (
model_ == KEA_DHCP6_SERVER) {
170 result->set(
"interface-id", interface_id);
177 result->set(
"id",
id);
178 if (
model_ == KEA_DHCP6_SERVER) {
181 result->set(
"rapid-commit", rapid_commit);
186 result->set(
"client-class", guard);
189 if (required && (required->size() > 0)) {
190 result->set(
"require-client-classes", required);
193 if (hosts && (hosts->size() > 0)) {
194 result->set(
"reservations", hosts);
198 result->set(
"reservation-mode", mode);
201 if (relay && (relay->size() > 0)) {
203 relay_map->set(
"ip-addresses", relay);
204 result->set(
"relay", relay_map);
206 if (
model_ == KEA_DHCP4_SERVER) {
209 result->set(
"match-client-id", match);
213 result->set(
"authoritative", auth);
217 result->set(
"next-server", next);
221 result->set(
"server-hostname", hostname);
225 result->set(
"boot-file-name", boot);
229 result->set(
"4o6-interface", s4o6_if);
233 result->set(
"4o6-interface-id", s4o6_id);
237 result->set(
"4o6-subnet", s4o6_sub);
242 result->set(
"user-context", Element::fromJSON(context->stringValue()));
250 if (
model_ == IETF_DHCPV6_SERVER) {
252 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
253 (
model_ == KEA_DHCP6_SERVER)) {
257 "setSubnet not implemented for the model: " <<
model_);
259 }
catch (
const sysrepo_exception& ex) {
261 "sysrepo error setting subnet '" << elem->str()
262 <<
"' at '" << xpath <<
"': " << ex.
what());
271 if (context && context->contains(
"description")) {
273 if (description->getType() == Element::string) {
274 setItem(xpath +
"/network-description", description, SR_STRING_T);
281 setItem(xpath +
"/network-prefix", subnet, SR_STRING_T);
284 if (pools && (pools->size() > 0)) {
285 setPools(xpath +
"/address-pools", pools);
287 pools = elem->get(
"pd-pools");
288 if (pools && (pools->size() > 0)) {
297 if (
model_ == KEA_DHCP6_SERVER) {
300 setItem(xpath +
"/preferred-lifetime", preferred, SR_UINT32_T);
304 setItem(xpath +
"/min-preferred-lifetime", min_pref, SR_UINT32_T);
308 setItem(xpath +
"/max-preferred-lifetime", max_pref, SR_UINT32_T);
313 setItem(xpath +
"/valid-lifetime", valid, SR_UINT32_T);
317 setItem(xpath +
"/min-valid-lifetime", min_valid, SR_UINT32_T);
321 setItem(xpath +
"/max-valid-lifetime", max_valid, SR_UINT32_T);
325 setItem(xpath +
"/renew-timer", renew, SR_UINT32_T);
329 setItem(xpath +
"/rebind-timer", rebind, SR_UINT32_T);
333 setItem(xpath +
"/calculate-tee-times", calculate, SR_BOOL_T);
337 setItem(xpath +
"/t1-percent", t1_percent, SR_DECIMAL64_T);
341 setItem(xpath +
"/t2-percent", t2_percent, SR_DECIMAL64_T);
344 if (options && (options->size() > 0)) {
348 if (pools && (pools->size() > 0)) {
351 if (
model_ == KEA_DHCP6_SERVER) {
352 pools = elem->get(
"pd-pools");
353 if (pools && (pools->size() > 0)) {
361 setItem(xpath +
"/subnet", subnet, SR_STRING_T);
364 setItem(xpath +
"/interface", interface, SR_STRING_T);
366 if (
model_ == KEA_DHCP6_SERVER) {
369 setItem(xpath +
"/interface-id", interface_id, SR_STRING_T);
372 if (
model_ == KEA_DHCP6_SERVER) {
375 setItem(xpath +
"/rapid-commit", rapid_commit, SR_BOOL_T);
380 setItem(xpath +
"/client-class", guard, SR_STRING_T);
383 if (required && (required->size() > 0)) {
385 setItem(xpath +
"/require-client-classes", rclass, SR_STRING_T);
389 if (hosts && (hosts->size() > 0)) {
394 setItem(xpath +
"/reservation-mode", mode, SR_ENUM_T);
401 setItem(xpath +
"/relay/ip-addresses", address, SR_STRING_T);
402 }
else if (addresses && (addresses->size() > 0)) {
404 setItem(xpath +
"/relay/ip-addresses", addr, SR_STRING_T);
408 if (
model_ == KEA_DHCP4_SERVER) {
411 setItem(xpath +
"/match-client-id", match, SR_BOOL_T);
415 setItem(xpath +
"/authoritative", auth, SR_BOOL_T);
419 setItem(xpath +
"/next-server", next, SR_STRING_T);
423 setItem(xpath +
"/server-hostname", hostname, SR_STRING_T);
427 setItem(xpath +
"/boot-file-name", boot, SR_STRING_T);
431 setItem(xpath +
"/subnet-4o6-interface", s4o6_if, SR_STRING_T);
435 setItem(xpath +
"/subnet-4o6-interface-id", s4o6_id, SR_STRING_T);
439 setItem(xpath +
"/subnet-4o6-subnet", s4o6_subnet, SR_STRING_T);
445 setItem(xpath +
"/user-context", repr, SR_STRING_T);
468 if (
model_ == IETF_DHCPV6_SERVER) {
470 }
else if (
model_ == KEA_DHCP4_SERVER) {
472 }
else if (
model_ == KEA_DHCP6_SERVER) {
475 }
catch (
const sysrepo_exception& ex) {
477 "sysrepo error getting subnets at '" << xpath
478 <<
"': " << ex.
what());
481 "getSubnets not implemented for the model: " <<
model_);
486 const std::string& subsel) {
488 S_Iter_Value iter =
getIter(xpath +
"/" + subsel);
494 const string& subnet =
getNext(iter);
495 if (subnet.empty()) {
506 if (
model_ == IETF_DHCPV6_SERVER) {
508 }
else if (
model_ == KEA_DHCP4_SERVER) {
510 }
else if (
model_ == KEA_DHCP6_SERVER) {
514 "setSubnets not implemented for the model: " <<
model_);
516 }
catch (
const sysrepo_exception& ex) {
518 "sysrepo error setting subnets '" << elem->str()
519 <<
"' at '" << xpath <<
"': " << ex.
what());
525 for (
size_t i = 0; i < elem->size(); ++i) {
528 range << xpath <<
"/network-range[network-range-id='";
533 range <<
id->intValue() <<
"']";
540 const std::string& subsel) {
541 for (
size_t i = 0; i < elem->size(); ++i) {
543 if (!subnet->contains(
"id")) {
546 ostringstream prefix;
547 prefix << xpath <<
"/" << subsel <<
"[id='"
548 << subnet->get(
"id")->intValue() <<
"']";
isc::data::ElementPtr getItems(const std::string &xpath)
Get and translate a list of basic values from YANG to JSON.
virtual ~TranslatorSubnet()
Destructor.
isc::data::ElementPtr getHosts(const std::string &xpath)
Get and translate host reservations from YANG to JSON.
Subnet (aka network range) translation between YANG and JSON.
A generic exception that is thrown when a function is not implemented.
Between YANG and JSON translator class for basic values.
isc::data::ElementPtr getSubnet(const std::string &xpath)
Get and translate a subnet from YANG to JSON.
boost::shared_ptr< Element > ElementPtr
void setSubnetKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnet for kea-dhcp[46]-server.
A translator class for converting a pd-pool list between YANG and JSON.
isc::data::ElementPtr getPdPools(const std::string &xpath)
Get and translate pd-pools from YANG to JSON.
sysrepo::S_Iter_Value getIter(const std::string &xpath)
List iterator methods keeping the session private.
TranslatorSubnets(sysrepo::S_Session session, const std::string &model)
Constructor.
void setPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) pools from JSON to YANG.
#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 setItem(const std::string &xpath, isc::data::ConstElementPtr elem, sr_type_t type)
Translate and set basic value from JSON to YANG.
Translation between YANG and JSON for a single host reservation.
isc::data::ElementPtr getSubnetsCommon(const std::string &xpath, const std::string &subsel)
getSubnets common part.
A translator class for converting an option data list between YANG and JSON.
A generic exception that is thrown when an unexpected error condition occurs.
isc::data::ElementPtr getSubnets(const std::string &xpath)
Get and translate subnets from YANG to JSON.
std::string model_
The model.
boost::shared_ptr< const Element > ConstElementPtr
std::string getNext(sysrepo::S_Iter_Value iter)
Get xpath of the next YANG list item.
void setPdPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set pd-pools from JSON to YANG.
static isc::data::ConstElementPtr getContext(isc::data::ConstElementPtr parent)
Get user context.
isc::data::ElementPtr getSubnetKea(const std::string &xpath)
getSubnet for kea-dhcp[46]-server.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Defines the logger used by the top-level component of kea-dhcp-ddns.
isc::data::ConstElementPtr getOptionDataList(const std::string &xpath)
Get and translate option data list from YANG to JSON.
isc::data::ElementPtr getItem(const std::string &xpath)
Get and translate basic value from YANG to JSON.
Prefix delegation pool translation between YANG and JSON.
A translator class for converting a pool between YANG and JSON.
void setSubnetsIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnets for ietf-dhcpv6-server.
void setSubnet(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnet from JSON to YANG.
virtual ~TranslatorSubnets()
Destructor.
A translator class for converting pools between YANG and JSON.
void setSubnets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnets from JSON to YANG.
isc::data::ElementPtr getPools(const std::string &xpath)
Get and translate pools from YANG to JSON.
static void toSubnet(const std::string &model, isc::data::ElementPtr subnet, isc::data::ConstElementPtr pools)
Move parameters from pools to the subnet.
Option data translation between YANG and JSON.
void setOptionDataList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option data list from JSON to YANG.
void setSubnetIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnet for ietf-dhcpv6-server.
void setSubnetsKea(const std::string &xpath, isc::data::ConstElementPtr elem, const std::string &subsel)
setSubnets for kea-dhcp[46]-server.
A translator class for converting host reservations list between YANG and JSON.
static void fromSubnet(const std::string &model, isc::data::ConstElementPtr subnet, isc::data::ConstElementPtr pools)
Moves parameters from subnets to pools.
isc::data::ElementPtr getSubnetIetf6(const std::string &xpath)
getSubnet for ietf-dhcpv6-server.
void setHosts(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) host reservations from JSON to YANG.