Accessing NETCONF servers from Python

This is pretty basic, but it allows me to read data over NETCONF while
returning nice Python types, and to set leaf values as well. That's
awesome if you ask me.

The "nice Python types" have no way of distinguishing between different
integer sizes. I was afraid that this might be a problem, but according
to the test, it looks that libnetconf2 (and all the C++ layers in front
of that) are happy even when a number is passed in as a string. That's
nice.

This test requires running "alone" with no other sysrepo- or
NETCONF-talking tests in parallel. I do not really know why, but if I'm
running this locally (T460s) with high parallelism, I'm getting failures
about `ietf-netconf-server` module not being recognized. Strange,
perhaps it does not like parallel `sysrepoctl --install` for some
reason?

Finally, the sanitizer handling is super-ugly, but at least it unbreaks
my local workflow. That one also requires an extra fixup touch for
libyang:

diff --git a/src/common.c b/src/common.c
index 7f941196..801a523f 100755
--- a/src/common.c
+++ b/src/common.c
@@ -37,6 +37,8 @@ API LY_ERR *
 ly_errno_glob_address(void)
 {
     FUN_IN;
+    static _Thread_local LY_ERR xx;
+    return &xx;

     return (LY_ERR *)&ly_errno_glob;
 }

I'm not submitting that upstream because I think the old code is valid
as well, and I somehow doubt that upstream  would be thrilled by that.

Change-Id: I4e81f8ba44700747f9bf719fcba2c460e079babd
diff --git a/src/python_netconf.cpp b/src/python_netconf.cpp
new file mode 100644
index 0000000..83964d6
--- /dev/null
+++ b/src/python_netconf.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
+ *
+ * Written by Jan Kundrát <jan.kundrat@cesnet.cz>
+ *
+*/
+
+#include <pybind11/pybind11.h>
+#include <pybind11/stl.h>
+#include "netconf_access.hpp"
+
+using namespace std::literals;
+using namespace pybind11::literals;
+
+// shamelessly stolen from the docs
+namespace pybind11::detail {
+    template <typename... Ts>
+    struct type_caster<boost::variant<Ts...>> : variant_caster<boost::variant<Ts...>> {};
+
+    // Specifies the function used to visit the variant -- `apply_visitor` instead of `visit`
+    template <>
+    struct visit_helper<boost::variant> {
+        template <typename... Args>
+        static auto call(Args &&...args) -> decltype(boost::apply_visitor(args...)) {
+            return boost::apply_visitor(args...);
+        }
+    };
+}
+
+
+PYBIND11_MODULE(netconf_cli_py, m) {
+    m.doc() = "Python bindings for accessing NETCONF servers";
+
+    pybind11::class_<special_>(m, "YangSpecial")
+            .def("__repr__",
+                 [](const special_ s) {
+                    return "<netconf_cli_py.YangSpecial " + specialValueToString(s) + ">";
+                 });
+
+    pybind11::class_<enum_>(m, "YangEnum")
+            .def("__repr__",
+                 [](const enum_ v) {
+                    return "<netconf_cli_py.YangEnum '" + v.m_value + "'>";
+                 });
+
+    pybind11::class_<binary_>(m, "YangBinary")
+            .def("__repr__",
+                 [](const binary_ v) {
+                    return "<netconf_cli_py.YangBinary '" + v.m_value + "'>";
+                 });
+
+    pybind11::class_<identityRef_>(m, "YangIdentityRef")
+            .def("__repr__",
+                 [](const identityRef_ v) {
+                    return "<netconf_cli_py.YangIdentityRef '"s
+                            + (v.m_prefix ? v.m_prefix->m_name + ":" : ""s) + v.m_value + "'>";
+                 });
+
+    pybind11::class_<NetconfAccess>(m, "NetconfAccess")
+            .def(pybind11::init<const std::string&>(), "socketPath"_a)
+            .def("getItems", &NetconfAccess::getItems, "xpath"_a)
+            .def("setLeaf", &NetconfAccess::setLeaf, "xpath"_a, "value"_a)
+            .def("commitChanges", &NetconfAccess::commitChanges)
+            ;
+}