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);
138 result->set(
"option-data", options);
143 result->set(
"pools", pools);
147 [&](DataNode
const& node) ->
ElementPtr const {
155 result->set(
"reservations", hosts);
158 if (
model_ == KEA_DHCP6_SERVER) {
168 result->set(
"pd-pools", pd_pools);
170 }
else if (
model_ == KEA_DHCP4_SERVER) {
183 return (result->empty() ?
ElementPtr() : result);
189 if (
model_ == IETF_DHCPV6_SERVER) {
191 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
192 (
model_ == KEA_DHCP6_SERVER)) {
196 "setSubnet not implemented for the model: " <<
model_);
198 }
catch (Error
const& ex) {
200 "setting subnet '" << elem->str()
201 <<
"' : " << ex.
what());
217 if (context && context->contains(
"description")) {
220 setItem(xpath +
"/network-description", description, LeafBaseType::String);
227 setItem(xpath +
"/network-prefix", subnet, LeafBaseType::String);
229 if (pools && !pools->empty()) {
230 setPools(xpath +
"/address-pools", pools);
232 pools = elem->get(
"pd-pools");
233 if (pools && !pools->empty()) {
253 setItem(xpath +
"/subnet", subnet, LeafBaseType::String);
258 checkAndSetLeaf(elem, xpath,
"calculate-tee-times", LeafBaseType::Bool);
260 checkAndSetLeaf(elem, xpath,
"ddns-generated-prefix", LeafBaseType::String);
261 checkAndSetLeaf(elem, xpath,
"ddns-override-client-update", LeafBaseType::Bool);
262 checkAndSetLeaf(elem, xpath,
"ddns-override-no-update", LeafBaseType::Bool);
263 checkAndSetLeaf(elem, xpath,
"ddns-qualifying-suffix", LeafBaseType::String);
264 checkAndSetLeaf(elem, xpath,
"ddns-replace-client-name", LeafBaseType::String);
267 checkAndSetLeaf(elem, xpath,
"ddns-update-on-renew", LeafBaseType::Bool);
268 checkAndSetLeaf(elem, xpath,
"ddns-use-conflict-resolution", LeafBaseType::Bool);
269 checkAndSetLeaf(elem, xpath,
"ddns-conflict-resolution-mode", LeafBaseType::Enum);
270 checkAndSetLeaf(elem, xpath,
"hostname-char-replacement", LeafBaseType::String);
271 checkAndSetLeaf(elem, xpath,
"hostname-char-set", LeafBaseType::String);
273 checkAndSetLeaf(elem, xpath,
"max-valid-lifetime", LeafBaseType::Uint32);
274 checkAndSetLeaf(elem, xpath,
"min-valid-lifetime", LeafBaseType::Uint32);
277 checkAndSetLeaf(elem, xpath,
"reservations-global", LeafBaseType::Bool);
278 checkAndSetLeaf(elem, xpath,
"reservations-in-subnet", LeafBaseType::Bool);
279 checkAndSetLeaf(elem, xpath,
"reservations-out-of-pool", LeafBaseType::Bool);
280 checkAndSetLeaf(elem, xpath,
"store-extended-info", LeafBaseType::Bool);
288 if (options && !options->empty()) {
292 if (pools && !pools->empty()) {
298 if (addresses && !addresses->empty()) {
299 for (
ElementPtr const& addr : addresses->listValue()) {
300 setItem(xpath +
"/relay/ip-addresses", addr, LeafBaseType::String);
305 if (hosts && !hosts->empty()) {
309 if (
model_ == KEA_DHCP6_SERVER) {
311 checkAndSetLeaf(elem, xpath,
"max-preferred-lifetime", LeafBaseType::Uint32);
312 checkAndSetLeaf(elem, xpath,
"min-preferred-lifetime", LeafBaseType::Uint32);
314 checkAndSetLeaf(elem, xpath,
"preferred-lifetime", LeafBaseType::Uint32);
317 pools = elem->get(
"pd-pools");
318 if (pools && !pools->empty()) {
352 if (
model_ == IETF_DHCPV6_SERVER) {
354 }
else if (
model_ == KEA_DHCP4_SERVER) {
356 }
else if (
model_ == KEA_DHCP6_SERVER) {
359 }
catch (Error
const& ex) {
365 "getSubnets not implemented for the model: " <<
model_);
379 string const& subsel) {
387 if (
model_ == IETF_DHCPV6_SERVER) {
389 }
else if (
model_ == KEA_DHCP4_SERVER) {
391 }
else if (
model_ == KEA_DHCP6_SERVER) {
395 "setSubnets not implemented for the model: " <<
model_);
397 }
catch (Error
const& ex) {
399 "setting subnets '" << elem->str()
400 <<
"' : " << ex.
what());
406 for (
size_t i = 0; i < elem->size(); ++i) {
409 range << xpath <<
"/network-range[network-range-id='";
414 range <<
id->intValue() <<
"']";
421 string const& subsel) {
422 for (
size_t i = 0; i < elem->size(); ++i) {
424 if (!subnet->contains(
"id")) {
427 ostringstream prefix;
428 prefix << xpath <<
"/" << subsel <<
"[id='"
429 << subnet->get(
"id")->intValue() <<
"']";
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 ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
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.
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.
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.
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.
Subnet (aka network range) translation between YANG and 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.