/parser4
+/export-from-yang4
+/import-to-yang4
/tools4.8
AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src
AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
AM_CPPFLAGS += $(BOOST_INCLUDES)
-#AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+if HAVE_SYSREPO
+AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+endif
CLEANFILES = *.gcno *.gcda
sbin_PROGRAMS = parser4
-#sbin_PROGRAMS += to-yang from-yang
+if HAVE_SYSREPO
+sbin_PROGRAMS += import-to-yang4 export-from-yang4
+endif
parser4_SOURCES = parser4.cc
parser4_LDADD = $(top_builddir)/src/bin/dhcp4/libparser4.la
parser4_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
parser4_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
parser4_LDADD += $(BOOST_LIBS)
-#parser4_LDADD += $(SYSREPO_LIBS)
parser4_LDFLAGS = $(AM_LDFLAGS)
+
+if HAVE_SYSREPO
+import_to_yang4_SOURCES = import_to_yang4.cc
+import_to_yang4_LDADD = $(top_builddir)/src/bin/dhcp4/libparser4.la
+import_to_yang4_LDADD += $(top_builddir)/src/lib/yang/libkea-yang.la
+import_to_yang4_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+import_to_yang4_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+import_to_yang4_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+import_to_yang4_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+import_to_yang4_LDADD += $(BOOST_LIBS)
+import_to_yang4_LDADD += $(SYSREPO_LIBS)
+import_to_yang4_LDFLAGS = $(AM_LDFLAGS)
+
+export_from_yang4_SOURCES = export_from_yang4.cc
+export_from_yang4_LDADD = $(top_builddir)/src/bin/dhcp4/libparser4.la
+export_from_yang4_LDADD += $(top_builddir)/src/lib/yang/libkea-yang.la
+export_from_yang4_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+export_from_yang4_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+export_from_yang4_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+export_from_yang4_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+export_from_yang4_LDADD += $(BOOST_LIBS)
+export_from_yang4_LDADD += $(SYSREPO_LIBS)
+export_from_yang4_LDFLAGS = $(AM_LDFLAGS)
+endif
--- /dev/null
+// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+#include <kea_version.h>
+
+#include <yang/translator_config.h>
+#include <yang/sysrepo_error.h>
+
+#include <fstream>
+#include <iostream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+#ifndef HAVE_PRE_0_7_6_SYSREPO
+using namespace sysrepo;
+#endif
+
+/// @file From YANG to JSON utility: the sysrepo startup datastore is
+/// exported into a configuration file.
+
+/// @brief Print export-from-yang4 usage.
+void
+usage() {
+ cerr << "Usage: export-from-yang4 [-v] [-V] -m <model> -o <output>"
+ << endl;
+}
+
+int
+main(int argc, char* argv[]) {
+ string model("kea-dhcp4-server");
+ string output_file("");
+
+ int ch;
+ while ((ch = getopt(argc, argv, "m:o:vV")) != -1) {
+ switch (ch) {
+ case 'm':
+ model = optarg;
+ break;
+
+ case 'o':
+ output_file = optarg;
+ break;
+
+ case 'v':
+ cout << VERSION << endl;
+ return (EXIT_SUCCESS);
+
+ case 'V':
+ cout << VERSION << endl << EXTENDED_VERSION << endl;
+ return (EXIT_SUCCESS);
+
+ default:
+ usage();
+ return (EXIT_FAILURE);
+ }
+ }
+
+ // Check for extraneous parameters.
+ if (argc > optind) {
+ usage();
+ return (EXIT_FAILURE);
+ }
+
+ try {
+ S_Connection conn;
+ try {
+ conn.reset(new Connection("export-from-yang4"));
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "can't connect to sysrepo: " << ex.what());
+ }
+
+ S_Session sess;
+ try {
+ sess.reset(new Session(conn, SR_DS_STARTUP));
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "can't establish a session: " << ex.what());
+ }
+
+ ConstElementPtr json;
+ try {
+ json = TranslatorConfig(sess, model).getConfig();
+ } catch (const exception& ex) {
+ isc_throw(SysrepoError, "translation failed: " << ex.what());
+ }
+
+ if (!json) {
+ isc_throw(SysrepoError, "got an emoty result");
+ }
+
+ if (output_file.empty()) {
+ cout << prettyPrint(json) << endl;
+ } else {
+ ofstream out(output_file, ios::trunc);
+ if (!out.good()) {
+ isc_throw(Unexpected, "Unable to open file " + output_file +
+ " for writing");
+ out << prettyPrint(json) << endl;
+ }
+ out.close();
+ }
+ } catch (const std::exception& ex) {
+ cerr << "export-from-yang4 failed with " << ex.what() << endl;
+ return (EXIT_FAILURE);
+ }
+ return (EXIT_SUCCESS);
+}
--- /dev/null
+// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+#include <kea_version.h>
+
+#include <yang/translator_config.h>
+#include <yang/sysrepo_error.h>
+#include <dhcp4/parser_context.h>
+
+#include <iostream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+#ifndef HAVE_PRE_0_7_6_SYSREPO
+using namespace sysrepo;
+#endif
+
+/// @file From JSON to YANG utility: the configuration file is translated
+/// and imported in the sysrepo startup datastore.
+
+/// @brief Print import-to-yang4 usage.
+void
+usage() {
+ cerr << "Usage: import-to-yang4 [-v] [-V] -i <input> -m <model>"
+ << endl;
+}
+
+int
+main(int argc, char* argv[]) {
+ string input_file("");
+ string model("kea-dhcp4-server");
+
+ int ch;
+ while ((ch = getopt(argc, argv, "i:m:vV")) != -1) {
+ switch (ch) {
+ case 'i':
+ input_file = optarg;
+ break;
+
+ case 'm':
+ model = optarg;
+ break;
+
+ case 'v':
+ cout << VERSION << endl;
+ return (EXIT_SUCCESS);
+
+ case 'V':
+ cout << VERSION << endl << EXTENDED_VERSION << endl;
+ return (EXIT_SUCCESS);
+
+ default:
+ usage();
+ return (EXIT_FAILURE);
+ }
+ }
+
+ // Check for extraneous parameters.
+ if (argc > optind) {
+ usage();
+ return (EXIT_FAILURE);
+ }
+
+ // Input file is required.
+ if (input_file.empty()) {
+ cerr << "Input file was not specified." << endl;
+ usage();
+ return (EXIT_FAILURE);
+ }
+
+ try {
+ Parser4Context parser;
+ ConstElementPtr json;
+ json = parser.parseFile(input_file, Parser4Context::PARSER_DHCP4);
+ if (!json) {
+ cerr << "No input found" << endl;
+ return (EXIT_FAILURE);
+ }
+
+ S_Connection conn;
+ try {
+ conn.reset(new Connection("import-to-yang4"));
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "can't connect to sysrepo: " << ex.what());
+ }
+
+ S_Session sess;
+ try {
+ sess.reset(new Session(conn, SR_DS_STARTUP));
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "can't establish a session: " << ex.what());
+ }
+
+ try {
+ TranslatorConfig(sess, model).setConfig(json);
+ } catch (const exception& ex) {
+ isc_throw(SysrepoError, "translation failed: " << ex.what());
+ }
+
+ try {
+ sess->validate();
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "failed to validate: " << ex.what());
+ }
+
+ try {
+ sess->commit();
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "failed to commit " << ex.what());
+ }
+ } catch (const std::exception& ex) {
+ cerr << "import-to-yang4 failed with " << ex.what() << endl;
+ return (EXIT_FAILURE);
+ }
+ return (EXIT_SUCCESS);
+}
/parser6
+/export-from-yang6
+/import-to-yang6
/tools6.8
AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src
AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
AM_CPPFLAGS += $(BOOST_INCLUDES)
-#AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+if HAVE_SYSREPO
+AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+endif
CLEANFILES = *.gcno *.gcda
sbin_PROGRAMS = parser6
-#sbin_PROGRAMS += to-yang from-yang
+if HAVE_SYSREPO
+sbin_PROGRAMS += import-to-yang6 export-from-yang6
+endif
parser6_SOURCES = parser6.cc
parser6_LDADD = $(top_builddir)/src/bin/dhcp6/libparser6.la
parser6_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
parser6_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
parser6_LDADD += $(BOOST_LIBS)
-#parser6_LDADD += $(SYSREPO_LIBS)
parser6_LDFLAGS = $(AM_LDFLAGS)
+
+if HAVE_SYSREPO
+import_to_yang6_SOURCES = import_to_yang6.cc
+import_to_yang6_LDADD = $(top_builddir)/src/bin/dhcp6/libparser6.la
+import_to_yang6_LDADD += $(top_builddir)/src/lib/yang/libkea-yang.la
+import_to_yang6_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+import_to_yang6_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+import_to_yang6_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+import_to_yang6_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+import_to_yang6_LDADD += $(BOOST_LIBS)
+import_to_yang6_LDADD += $(SYSREPO_LIBS)
+import_to_yang6_LDFLAGS = $(AM_LDFLAGS)
+
+export_from_yang6_SOURCES = export_from_yang6.cc
+export_from_yang6_LDADD = $(top_builddir)/src/bin/dhcp6/libparser6.la
+export_from_yang6_LDADD += $(top_builddir)/src/lib/yang/libkea-yang.la
+export_from_yang6_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+export_from_yang6_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+export_from_yang6_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+export_from_yang6_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+export_from_yang6_LDADD += $(BOOST_LIBS)
+export_from_yang6_LDADD += $(SYSREPO_LIBS)
+export_from_yang6_LDFLAGS = $(AM_LDFLAGS)
+endif
--- /dev/null
+// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+#include <kea_version.h>
+
+#include <yang/translator_config.h>
+#include <yang/sysrepo_error.h>
+
+#include <fstream>
+#include <iostream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+#ifndef HAVE_PRE_0_7_6_SYSREPO
+using namespace sysrepo;
+#endif
+
+/// @file From YANG to JSON utility: the sysrepo startup datastore is
+/// exported into a configuration file.
+
+/// @brief Print export-from-yang6 usage.
+void
+usage() {
+ cerr << "Usage: export-from-yang6 [-v] [-V] -m <model> -o <output>"
+ << endl;
+}
+
+int
+main(int argc, char* argv[]) {
+ string model("kea-dhcp6-server");
+ string output_file("");
+
+ int ch;
+ while ((ch = getopt(argc, argv, "m:o:vV")) != -1) {
+ switch (ch) {
+ case 'm':
+ model = optarg;
+ break;
+
+ case 'o':
+ output_file = optarg;
+ break;
+
+ case 'v':
+ cout << VERSION << endl;
+ return (EXIT_SUCCESS);
+
+ case 'V':
+ cout << VERSION << endl << EXTENDED_VERSION << endl;
+ return (EXIT_SUCCESS);
+
+ default:
+ usage();
+ return (EXIT_FAILURE);
+ }
+ }
+
+ // Check for extraneous parameters.
+ if (argc > optind) {
+ usage();
+ return (EXIT_FAILURE);
+ }
+
+ try {
+ S_Connection conn;
+ try {
+ conn.reset(new Connection("export-from-yang6"));
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "can't connect to sysrepo: " << ex.what());
+ }
+
+ S_Session sess;
+ try {
+ sess.reset(new Session(conn, SR_DS_STARTUP));
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "can't establish a session: " << ex.what());
+ }
+
+ ConstElementPtr json;
+ try {
+ json = TranslatorConfig(sess, model).getConfig();
+ } catch (const exception& ex) {
+ isc_throw(SysrepoError, "translation failed: " << ex.what());
+ }
+
+ if (!json) {
+ isc_throw(SysrepoError, "got an emoty result");
+ }
+
+ if (output_file.empty()) {
+ cout << prettyPrint(json) << endl;
+ } else {
+ ofstream out(output_file, ios::trunc);
+ if (!out.good()) {
+ isc_throw(Unexpected, "Unable to open file " + output_file +
+ " for writing");
+ out << prettyPrint(json) << endl;
+ }
+ out.close();
+ }
+ } catch (const std::exception& ex) {
+ cerr << "export-from-yang6 failed with " << ex.what() << endl;
+ return (EXIT_FAILURE);
+ }
+ return (EXIT_SUCCESS);
+}
--- /dev/null
+// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+#include <kea_version.h>
+
+#include <yang/translator_config.h>
+#include <yang/sysrepo_error.h>
+#include <dhcp6/parser_context.h>
+
+#include <iostream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+#ifndef HAVE_PRE_0_7_6_SYSREPO
+using namespace sysrepo;
+#endif
+
+/// @file From JSON to YANG utility: the configuration file is translated
+/// and imported in the sysrepo startup datastore.
+
+/// @brief Print import-to-yang6 usage.
+void
+usage() {
+ cerr << "Usage: import-to-yang6 [-v] [-V] -i <input> -m <model>"
+ << endl;
+}
+
+int
+main(int argc, char* argv[]) {
+ string input_file("");
+ string model("kea-dhcp6-server");
+
+ int ch;
+ while ((ch = getopt(argc, argv, "i:m:vV")) != -1) {
+ switch (ch) {
+ case 'i':
+ input_file = optarg;
+ break;
+
+ case 'm':
+ model = optarg;
+ break;
+
+ case 'v':
+ cout << VERSION << endl;
+ return (EXIT_SUCCESS);
+
+ case 'V':
+ cout << VERSION << endl << EXTENDED_VERSION << endl;
+ return (EXIT_SUCCESS);
+
+ default:
+ usage();
+ return (EXIT_FAILURE);
+ }
+ }
+
+ // Check for extraneous parameters.
+ if (argc > optind) {
+ usage();
+ return (EXIT_FAILURE);
+ }
+
+ // Input file is required.
+ if (input_file.empty()) {
+ cerr << "Input file was not specified." << endl;
+ usage();
+ return (EXIT_FAILURE);
+ }
+
+ try {
+ Parser6Context parser;
+ ConstElementPtr json;
+ json = parser.parseFile(input_file, Parser6Context::PARSER_DHCP6);
+ if (!json) {
+ cerr << "No input found" << endl;
+ return (EXIT_FAILURE);
+ }
+
+ S_Connection conn;
+ try {
+ conn.reset(new Connection("import-to-yang6"));
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "can't connect to sysrepo: " << ex.what());
+ }
+
+ S_Session sess;
+ try {
+ sess.reset(new Session(conn, SR_DS_STARTUP));
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "can't establish a session: " << ex.what());
+ }
+
+ try {
+ TranslatorConfig(sess, model).setConfig(json);
+ } catch (const exception& ex) {
+ isc_throw(SysrepoError, "translation failed: " << ex.what());
+ }
+
+ try {
+ sess->validate();
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "failed to validate: " << ex.what());
+ }
+
+ try {
+ sess->commit();
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "failed to commit " << ex.what());
+ }
+ } catch (const std::exception& ex) {
+ cerr << "import-to-yang6 failed with " << ex.what() << endl;
+ return (EXIT_FAILURE);
+ }
+ return (EXIT_SUCCESS);
+}
AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src
AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
AM_CPPFLAGS += $(BOOST_INCLUDES)
-#AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
CLEANFILES = *.gcno *.gcda
sbin_PROGRAMS = parser-nc
-#sbin_PROGRAMS += to-yang from-yang
parser_nc_SOURCES = parser-nc.cc
parser_nc_LDADD = $(top_builddir)/src/bin/netconf/libparser-nc.la
parser_nc_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
parser_nc_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
parser_nc_LDADD += $(BOOST_LIBS)
-#parser_nc_LDADD += $(SYSREPO_LIBS)
parser_nc_LDFLAGS = $(AM_LDFLAGS)