17using namespace libyang;
18using namespace sysrepo;
38 if (
model_ == IETF_DHCPV6_SERVER) {
40 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
41 (
model_ == KEA_DHCP6_SERVER)) {
44 }
catch (Error
const& ex) {
50 "getSubnet not implemented for the model: " <<
model_);
69 [&](DataNode
const& node) ->
ElementPtr const {
74 [&](DataNode
const& node) ->
ElementPtr const {
81 context->set(
"description", description);
82 result->set(
"user-context", context);
85 if (result->get(
"pools")) {
93 return (result->empty() ?
ElementPtr() : result);
144 result->set(
"option-data", options);
149 result->set(
"pools", pools);
153 [&](DataNode
const& node) ->
ElementPtr const {
161 result->set(
"reservations", hosts);
164 if (
model_ == KEA_DHCP6_SERVER) {
174 result->set(
"pd-pools", pd_pools);
176 }
else if (
model_ == KEA_DHCP4_SERVER) {
189 return (result->empty() ?
ElementPtr() : result);
195 if (
model_ == IETF_DHCPV6_SERVER) {
197 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
198 (
model_ == KEA_DHCP6_SERVER)) {
202 "setSubnet not implemented for the model: " <<
model_);
204 }
catch (Error
const& ex) {
206 "setting subnet '" << elem->str()
207 <<
"' : " << ex.
what());
223 if (context && context->contains(
"description")) {
226 setItem(xpath +
"/network-description", description, LeafBaseType::String);
233 setItem(xpath +
"/network-prefix", subnet, LeafBaseType::String);
235 if (pools && !pools->empty()) {
236 setPools(xpath +
"/address-pools", pools);
238 pools = elem->get(
"pd-pools");
239 if (pools && !pools->empty()) {
259 setItem(xpath +
"/subnet", subnet, LeafBaseType::String);
264 checkAndSetLeaf(elem, xpath,
"calculate-tee-times", LeafBaseType::Bool);
266 checkAndSetLeaf(elem, xpath,
"ddns-generated-prefix", LeafBaseType::String);
267 checkAndSetLeaf(elem, xpath,
"ddns-override-client-update", LeafBaseType::Bool);
268 checkAndSetLeaf(elem, xpath,
"ddns-override-no-update", LeafBaseType::Bool);
269 checkAndSetLeaf(elem, xpath,
"ddns-qualifying-suffix", LeafBaseType::String);
270 checkAndSetLeaf(elem, xpath,
"ddns-replace-client-name", LeafBaseType::String);
276 checkAndSetLeaf(elem, xpath,
"ddns-update-on-renew", LeafBaseType::Bool);
277 checkAndSetLeaf(elem, xpath,
"ddns-use-conflict-resolution", LeafBaseType::Bool);
278 checkAndSetLeaf(elem, xpath,
"ddns-conflict-resolution-mode", LeafBaseType::Enum);
279 checkAndSetLeaf(elem, xpath,
"hostname-char-replacement", LeafBaseType::String);
280 checkAndSetLeaf(elem, xpath,
"hostname-char-set", LeafBaseType::String);
282 checkAndSetLeaf(elem, xpath,
"max-valid-lifetime", LeafBaseType::Uint32);
283 checkAndSetLeaf(elem, xpath,
"min-valid-lifetime", LeafBaseType::Uint32);
286 checkAndSetLeaf(elem, xpath,
"reservations-global", LeafBaseType::Bool);
287 checkAndSetLeaf(elem, xpath,
"reservations-in-subnet", LeafBaseType::Bool);
288 checkAndSetLeaf(elem, xpath,
"reservations-out-of-pool", LeafBaseType::Bool);
289 checkAndSetLeaf(elem, xpath,
"store-extended-info", LeafBaseType::Bool);
293 checkAndSetLeaf(elem, xpath,
"adaptive-lease-time-threshold", LeafBaseType::Dec64);
299 if (options && !options->empty()) {
303 if (pools && !pools->empty()) {
309 if (addresses && !addresses->empty()) {
310 for (
ElementPtr const& addr : addresses->listValue()) {
311 setItem(xpath +
"/relay/ip-addresses", addr, LeafBaseType::String);
316 if (hosts && !hosts->empty()) {
320 if (
model_ == KEA_DHCP6_SERVER) {
322 checkAndSetLeaf(elem, xpath,
"max-preferred-lifetime", LeafBaseType::Uint32);
323 checkAndSetLeaf(elem, xpath,
"min-preferred-lifetime", LeafBaseType::Uint32);
325 checkAndSetLeaf(elem, xpath,
"preferred-lifetime", LeafBaseType::Uint32);
328 pools = elem->get(
"pd-pools");
329 if (pools && !pools->empty()) {
363 if (
model_ == IETF_DHCPV6_SERVER) {
365 }
else if (
model_ == KEA_DHCP4_SERVER) {
367 }
else if (
model_ == KEA_DHCP6_SERVER) {
370 }
catch (Error
const& ex) {
376 "getSubnets not implemented for the model: " <<
model_);
390 string const& subsel) {
398 if (
model_ == IETF_DHCPV6_SERVER) {
400 }
else if (
model_ == KEA_DHCP4_SERVER) {
402 }
else if (
model_ == KEA_DHCP6_SERVER) {
406 "setSubnets not implemented for the model: " <<
model_);
408 }
catch (Error
const& ex) {
410 "setting subnets '" << elem->str()
411 <<
"' : " << ex.
what());
417 for (
size_t i = 0; i < elem->size(); ++i) {
420 range << xpath <<
"/network-range[network-range-id='";
425 range <<
id->intValue() <<
"']";
432 string const& subsel) {
433 for (
size_t i = 0; i < elem->size(); ++i) {
435 if (!subnet->contains(
"id")) {
438 ostringstream prefix;
439 prefix << xpath <<
"/" << subsel <<
"[id='"
440 << subnet->get(
"id")->intValue() <<
"']";
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
static void toSubnet(const std::string &model, isc::data::ElementPtr subnet, isc::data::ConstElementPtr pools)
Move parameters from pools to the subnet.
static void fromSubnet(const std::string &model, isc::data::ConstElementPtr subnet, isc::data::ConstElementPtr pools)
Moves parameters from subnets to pools.
Translation between YANG and JSON for a single host reservation.
A translator class for converting host reservations list between YANG and JSON.
isc::data::ElementPtr getHosts(libyang::DataNode const &data_node)
Translate host reservations from YANG to JSON.
TranslatorHosts(sysrepo::Session session, const std::string &model)
Constructor.
void setHosts(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) host reservations from JSON to YANG.
A translator class for converting an option data list between YANG and JSON.
void setOptionDataList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option data list from JSON to YANG.
isc::data::ConstElementPtr getOptionDataList(libyang::DataNode const &data_node)
Translate option data list from YANG to JSON.
Option data translation between YANG and JSON.
Prefix delegation pool translation between YANG and JSON.
A translator class for converting a pd-pool list between YANG and JSON.
TranslatorPdPools(sysrepo::Session session, const std::string &model)
Constructor.
void setPdPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set pd-pools from JSON to YANG.
isc::data::ElementPtr getPdPools(libyang::DataNode const &data_node)
Translate pd-pools from YANG to JSON.
A translator class for converting a pool between YANG and JSON.
A translator class for converting pools between YANG and JSON.
TranslatorPools(sysrepo::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.
isc::data::ElementPtr getPools(libyang::DataNode const &data_node)
Translate pools from YANG to JSON.
isc::data::ElementPtr getSubnet(libyang::DataNode const &data_node)
Get and translate a subnet from YANG to JSON.
void setSubnetIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnet for ietf-dhcpv6-server.
void setSubnet(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnet from JSON to YANG.
isc::data::ElementPtr getSubnetIetf6(libyang::DataNode const &data_node)
getSubnet for ietf-dhcpv6-server.
isc::data::ElementPtr getSubnetFromAbsoluteXpath(std::string const &xpath)
Get and translate a subnet from YANG to JSON.
TranslatorSubnet(sysrepo::Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getSubnetKea(libyang::DataNode const &data_node)
getSubnet for kea-dhcp[46]-server.
void setSubnetKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnet for kea-dhcp[46]-server.
isc::data::ElementPtr getSubnetsCommon(libyang::DataNode const &data_node, const std::string &subsel)
getSubnets common part.
void setSubnets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnets from JSON to YANG.
void setSubnetsKea(const std::string &xpath, isc::data::ConstElementPtr elem, const std::string &subsel)
setSubnets for kea-dhcp[46]-server.
isc::data::ElementPtr getSubnets(libyang::DataNode const &data_node)
Get and translate subnets from YANG to JSON.
isc::data::ElementPtr getSubnetsFromAbsoluteXpath(std::string const &xpath)
Get and translate subnets from YANG to JSON.
void setSubnetsIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnets for ietf-dhcpv6-server.
TranslatorSubnets(sysrepo::Session session, const std::string &model)
Constructor.
Between YANG and JSON translator class for basic values.
void getMandatoryDivergingLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name, std::string const &yang_name) const
Retrieves a child YANG data node identified by one name from the given parent YANG container node and...
isc::data::ElementPtr getList(libyang::DataNode const &data_node, std::string const &xpath, T &t, isc::data::ElementPtr(T::*f)(libyang::DataNode const &)) const
Retrieve a list as ElementPtr from sysrepo from a certain xpath.
void checkAndSetLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
isc::data::ElementPtr getItem(libyang::DataNode const &data_node, std::string const &xpath) const
Translate a basic value from YANG to JSON for a given xpath that is relative to the given source node...
void checkAndGet(isc::data::ElementPtr const &storage, libyang::DataNode const &data_node, std::string const &xpath, T translate) const
Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {st...
void setMandatoryDivergingLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, std::string const &yang_name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
libyang::DataNode findXPath(std::string const &xpath) const
Retrieves a YANG data node by xpath.
void getMandatoryLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
void checkAndGetLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
void checkAndSetUserContext(isc::data::ConstElementPtr const &from, std::string const &xpath)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void checkAndGetDivergingLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name, std::string const &yang_name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
void setItem(const std::string &xpath, isc::data::ConstElementPtr const elem, libyang::LeafBaseType const type)
Translate and set basic value from JSON to YANG.
std::string model_
The model.
void checkAndSetDivergingLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, std::string const &yang_name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void checkAndGetAndJsonifyLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, const std::string &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node,...
void checkAndSetLeafList(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath as a leaf-list.
void checkAndGetDiverging(isc::data::ElementPtr const &storage, libyang::DataNode const &data_node, std::string const &key, std::string const &xpath, T translate) const
Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {st...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
Defines the logger used by the top-level component of kea-lfc.