16 #ifndef HAVE_PRE_0_7_6_SYSREPO
23 TranslatorHost::TranslatorHost(S_Session session,
const string& model)
35 if ((
model_ == KEA_DHCP4_SERVER) ||
36 (
model_ == KEA_DHCP6_SERVER)) {
39 }
catch (
const sysrepo_exception& ex) {
41 "sysrepo error getting host reservation at '" << xpath
42 <<
"': " << ex.
what());
45 "getHost not implemented for the model: " <<
model_);
52 if (!id_type || !
id) {
57 result->set(id_type->stringValue(), id);
60 result->set(
"hostname", hostname);
62 if (
model_ == KEA_DHCP4_SERVER) {
65 result->set(
"ip-address", address);
69 if (addresses && (addresses->size() > 0)) {
70 result->set(
"ip-addresses", addresses);
73 if (prefixes && (prefixes->size() > 0)) {
74 result->set(
"prefixes", prefixes);
78 if (options && (options->size() > 0)) {
79 result->set(
"option-data", options);
83 result->set(
"client-classes", classes);
85 if (
model_ == KEA_DHCP4_SERVER) {
88 result->set(
"next-server", next);
92 result->set(
"server-hostname", hostname);
96 result->set(
"boot-file-name", boot);
101 result->set(
"user-context", Element::fromJSON(context->stringValue()));
109 if ((
model_ == KEA_DHCP4_SERVER) ||
110 (
model_ == KEA_DHCP6_SERVER)) {
114 "setHost not implemented for the model: " <<
model_);
116 }
catch (
const sysrepo_exception& ex) {
118 "sysrepo error setting host reservation '" << elem->str()
119 <<
"' at '" << xpath <<
"': " << ex.
what());
128 setItem(xpath +
"/hostname", hostname, SR_STRING_T);
130 if (
model_ == KEA_DHCP4_SERVER) {
133 setItem(xpath +
"/ip-address", address, SR_STRING_T);
137 if (addresses && (addresses->size() > 0)) {
139 setItem(xpath +
"/ip-addresses", address, SR_STRING_T);
143 if (prefixes && (prefixes->size() > 0)) {
145 setItem(xpath +
"/prefixes", prefix, SR_STRING_T);
150 if (options && (options->size() > 0)) {
154 if (classes && (classes->size() > 0)) {
156 setItem(xpath +
"/client-classes", cclass, SR_STRING_T);
161 if (
model_ == KEA_DHCP4_SERVER) {
164 setItem(xpath +
"/next-server", next, SR_STRING_T);
168 setItem(xpath +
"/server-hostname", hostname, SR_STRING_T);
172 setItem(xpath +
"/boot-file-name", boot, SR_STRING_T);
179 setItem(xpath +
"/user-context", Element::create(context->str()),
198 S_Iter_Value iter =
getIter(xpath +
"/host");
204 const string& host =
getNext(iter);
211 }
catch (
const sysrepo_exception& ex) {
213 "sysrepo error getting host reservations at '" << xpath
214 <<
"': " << ex.
what());
221 if ((
model_ == KEA_DHCP4_SERVER) ||
222 (
model_ == KEA_DHCP6_SERVER)) {
226 "setHosts not implemented for the model: " <<
model_);
228 }
catch (
const sysrepo_exception& ex) {
230 "sysrepo error setting host reservations '" << elem->str()
231 <<
"' at '" << xpath <<
"': " << ex.
what());
237 for (
size_t i = 0; i < elem->size(); ++i) {
238 string id_type =
"unknown";
242 id_type =
"hw-address";
245 id = host->get(
"duid");
250 if (
model_ == KEA_DHCP4_SERVER) {
251 id = host->get(
"circuit-id");
253 id_type =
"circuit-id";
256 id = host->get(
"client-id");
258 id_type =
"client-id";
262 id = host->get(
"flex-id");
269 if (id_type ==
"unknown") {
274 key << xpath <<
"/host[identifier-type='" << id_type
275 <<
"'][identifier='" <<
id->stringValue() <<
"']";
isc::data::ElementPtr getItems(const std::string &xpath)
Get and translate a list of basic values from YANG to JSON.
isc::data::ElementPtr getHostKea(const std::string &xpath)
getHost for kea-dhcp[46]-server models.
isc::data::ElementPtr getHosts(const std::string &xpath)
Get and translate host reservations from YANG to JSON.
void setHostsKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setHosts for kea-dhcp[46].
A generic exception that is thrown when a function is not implemented.
Between YANG and JSON translator class for basic values.
boost::shared_ptr< Element > ElementPtr
virtual ~TranslatorHost()
Destructor.
sysrepo::S_Iter_Value getIter(const std::string &xpath)
List iterator methods keeping the session private.
isc::data::ElementPtr getHost(const std::string &xpath)
Get and translate a host reservation from YANG to 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...
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.
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.
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.
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 setHostKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setHost for kea-dhcp[46]-server models.
TranslatorHosts(sysrepo::S_Session session, const std::string &model)
Constructor.
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.
virtual ~TranslatorHosts()
Destructor.
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 setHost(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set host reservation from JSON to YANG.
void setHosts(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) host reservations from JSON to YANG.