 |
Kea
1.5.0
|
Go to the documentation of this file.
16 #ifndef HAVE_PRE_0_7_6_SYSREPO
17 using namespace 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);
105 result->set(
"valid-lifetime", valid);
109 result->set(
"renew-timer", renew);
113 result->set(
"rebind-timer", rebind);
116 if (options && (options->size() > 0)) {
117 result->set(
"option-data", options);
120 if (pools && (pools->size() > 0)) {
121 result->set(
"pools", pools);
123 if (
model_ == KEA_DHCP6_SERVER) {
125 if (pools && (pools->size() > 0)) {
126 result->set(
"pd-pools", pools);
133 result->set(
"subnet", subnet);
136 result->set(
"interface", interface);
138 if (
model_ == KEA_DHCP6_SERVER) {
141 result->set(
"interface-id", interface_id);
148 result->set(
"id",
id);
149 if (
model_ == KEA_DHCP6_SERVER) {
152 result->set(
"rapid-commit", rapid_commit);
157 result->set(
"client-class", guard);
160 if (required && (required->size() > 0)) {
161 result->set(
"require-client-classes", required);
164 if (hosts && (hosts->size() > 0)) {
165 result->set(
"reservations", hosts);
169 result->set(
"reservation-mode", mode);
172 if (relay && (relay->size() > 0)) {
174 relay_map->set(
"ip-addresses", relay);
175 result->set(
"relay", relay_map);
177 if (
model_ == KEA_DHCP4_SERVER) {
180 result->set(
"match-client-id", match);
184 result->set(
"authoritative", auth);
188 result->set(
"next-server", next);
192 result->set(
"server-hostname", hostname);
196 result->set(
"boot-file-name", boot);
200 result->set(
"4o6-interface", s4o6_if);
204 result->set(
"4o6-interface-id", s4o6_id);
208 result->set(
"4o6-subnet", s4o6_sub);
213 result->set(
"user-context", Element::fromJSON(context->stringValue()));
221 if (
model_ == IETF_DHCPV6_SERVER) {
223 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
224 (
model_ == KEA_DHCP6_SERVER)) {
228 "setSubnet not implemented for the model: " <<
model_);
230 }
catch (
const sysrepo_exception& ex) {
232 "sysrepo error setting subnet '" << elem->str()
233 <<
"' at '" << xpath <<
"': " << ex.
what());
242 if (context && context->contains(
"description")) {
244 if (description->getType() == Element::string) {
245 setItem(xpath +
"/network-description", description, SR_STRING_T);
252 setItem(xpath +
"/network-prefix", subnet, SR_STRING_T);
255 if (pools && (pools->size() > 0)) {
256 setPools(xpath +
"/address-pools", pools);
258 pools = elem->get(
"pd-pools");
259 if (pools && (pools->size() > 0)) {
268 if (
model_ == KEA_DHCP6_SERVER) {
271 setItem(xpath +
"/preferred-lifetime", preferred, SR_UINT32_T);
276 setItem(xpath +
"/valid-lifetime", valid, SR_UINT32_T);
280 setItem(xpath +
"/renew-timer", renew, SR_UINT32_T);
284 setItem(xpath +
"/rebind-timer", rebind, SR_UINT32_T);
287 if (options && (options->size() > 0)) {
291 if (pools && (pools->size() > 0)) {
294 if (
model_ == KEA_DHCP6_SERVER) {
295 pools = elem->get(
"pd-pools");
296 if (pools && (pools->size() > 0)) {
304 setItem(xpath +
"/subnet", subnet, SR_STRING_T);
307 setItem(xpath +
"/interface", interface, SR_STRING_T);
309 if (
model_ == KEA_DHCP6_SERVER) {
312 setItem(xpath +
"/interface-id", interface_id, SR_STRING_T);
315 if (
model_ == KEA_DHCP6_SERVER) {
318 setItem(xpath +
"/rapid-commit", rapid_commit, SR_BOOL_T);
323 setItem(xpath +
"/client-class", guard, SR_STRING_T);
326 if (required && (required->size() > 0)) {
328 setItem(xpath +
"/require-client-classes", rclass, SR_STRING_T);
332 if (hosts && (hosts->size() > 0)) {
337 setItem(xpath +
"/reservation-mode", mode, SR_ENUM_T);
344 setItem(xpath +
"/relay/ip-addresses", address, SR_STRING_T);
345 }
else if (addresses && (addresses->size() > 0)) {
347 setItem(xpath +
"/relay/ip-addresses", addr, SR_STRING_T);
351 if (
model_ == KEA_DHCP4_SERVER) {
354 setItem(xpath +
"/match-client-id", match, SR_BOOL_T);
358 setItem(xpath +
"/authoritative", auth, SR_BOOL_T);
362 setItem(xpath +
"/next-server", next, SR_STRING_T);
366 setItem(xpath +
"/server-hostname", hostname, SR_STRING_T);
370 setItem(xpath +
"/boot-file-name", boot, SR_STRING_T);
374 setItem(xpath +
"/subnet-4o6-interface", s4o6_if, SR_STRING_T);
378 setItem(xpath +
"/subnet-4o6-interface-id", s4o6_id, SR_STRING_T);
382 setItem(xpath +
"/subnet-4o6-subnet", s4o6_subnet, SR_STRING_T);
388 setItem(xpath +
"/user-context", repr, SR_STRING_T);
411 if (
model_ == IETF_DHCPV6_SERVER) {
413 }
else if (
model_ == KEA_DHCP4_SERVER) {
415 }
else if (
model_ == KEA_DHCP6_SERVER) {
418 }
catch (
const sysrepo_exception& ex) {
420 "sysrepo error getting subnets at '" << xpath
421 <<
"': " << ex.
what());
424 "getSubnets not implemented for the model: " <<
model_);
429 const std::string& subsel) {
431 S_Iter_Value iter =
getIter(xpath +
"/" + subsel);
437 const string& subnet =
getNext(iter);
438 if (subnet.empty()) {
449 if (
model_ == IETF_DHCPV6_SERVER) {
451 }
else if (
model_ == KEA_DHCP4_SERVER) {
453 }
else if (
model_ == KEA_DHCP6_SERVER) {
457 "setSubnets not implemented for the model: " <<
model_);
459 }
catch (
const sysrepo_exception& ex) {
461 "sysrepo error setting subnets '" << elem->str()
462 <<
"' at '" << xpath <<
"': " << ex.
what());
468 for (
size_t i = 0; i < elem->size(); ++i) {
471 range << xpath <<
"/network-range[network-range-id='";
476 range <<
id->intValue() <<
"']";
483 const std::string& subsel) {
484 for (
size_t i = 0; i < elem->size(); ++i) {
486 if (!subnet->contains(
"id")) {
489 ostringstream prefix;
490 prefix << xpath <<
"/" << subsel <<
"[id='"
491 << subnet->get(
"id")->intValue() <<
"']";
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.
sysrepo::S_Iter_Value getIter(const std::string &xpath)
List iterator methods keeping the session private.
void setSubnetsIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnets for ietf-dhcpv6-server.
isc::data::ConstElementPtr getOptionDataList(const std::string &xpath)
Get and translate option data list from YANG to JSON.
Translation between YANG and JSON for a single host reservation.
virtual ~TranslatorSubnet()
Destructor.
A translator class for converting a pool between YANG and JSON.
void setSubnetIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnet for ietf-dhcpv6-server.
Subnet (aka network range) translation between YANG and JSON.
std::string getNext(sysrepo::S_Iter_Value iter)
Get xpath of the next YANG list item.
isc::data::ElementPtr getItem(const std::string &xpath)
Get and translate basic value from YANG to JSON.
isc::data::ElementPtr getItems(const std::string &xpath)
Get and translate a list of basic values from YANG to JSON.
Option data translation between YANG and JSON.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A translator class for converting pools between YANG and JSON.
#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...
A translator class for converting host reservations list between YANG and JSON.
void setSubnet(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnet from JSON to YANG.
void setSubnets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnets from JSON to YANG.
isc::data::ElementPtr getSubnet(const std::string &xpath)
Get and translate a subnet from YANG to JSON.
isc::data::ElementPtr getSubnetsCommon(const std::string &xpath, const std::string &subsel)
getSubnets common part.
void setOptionDataList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option data list from JSON to YANG.
TranslatorSubnets(sysrepo::S_Session session, const std::string &model)
Constructor.
void setItem(const std::string &xpath, isc::data::ConstElementPtr elem, sr_type_t type)
Translate and set basic value from JSON to YANG.
A translator class for converting a pd-pool list between YANG and JSON.
void setSubnetsKea(const std::string &xpath, isc::data::ConstElementPtr elem, const std::string &subsel)
setSubnets for kea-dhcp[46]-server.
void setPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) pools from JSON to YANG.
isc::data::ElementPtr getSubnetKea(const std::string &xpath)
getSubnet for kea-dhcp[46]-server.
virtual ~TranslatorSubnets()
Destructor.
isc::data::ElementPtr getSubnets(const std::string &xpath)
Get and translate subnets from YANG to JSON.
Between YANG and JSON translator class for basic values.
isc::data::ElementPtr getPools(const std::string &xpath)
Get and translate pools from YANG to JSON.
void setHosts(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) host reservations from JSON to YANG.
static void toSubnet(const std::string &model, isc::data::ElementPtr subnet, isc::data::ConstElementPtr pools)
Move parameters from pools to the subnet.
isc::data::ElementPtr getHosts(const std::string &xpath)
Get and translate host reservations from YANG to JSON.
Prefix delegation pool translation between YANG and JSON.
isc::data::ElementPtr getPdPools(const std::string &xpath)
Get and translate pd-pools from YANG to JSON.
static void fromSubnet(const std::string &model, isc::data::ConstElementPtr subnet, isc::data::ConstElementPtr pools)
Moves parameters from subnets to pools.
boost::shared_ptr< Element > ElementPtr
A generic exception that is thrown when a function is not implemented.
boost::shared_ptr< const Element > ConstElementPtr
std::string model_
The model.
static isc::data::ConstElementPtr getContext(isc::data::ConstElementPtr parent)
Get user context.
isc::data::ElementPtr getSubnetIetf6(const std::string &xpath)
getSubnet for ietf-dhcpv6-server.
void setPdPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set pd-pools from JSON to YANG.
void setSubnetKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnet for kea-dhcp[46]-server.