blob: 83964d67d02919c05c42a1856a6ab11990cd2499 [file] [log] [blame]
Jan Kundrátcf5c6362020-01-16 22:54:47 +01001/*
2 * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Jan Kundrát <jan.kundrat@cesnet.cz>
5 *
6*/
7
8#include <pybind11/pybind11.h>
9#include <pybind11/stl.h>
10#include "netconf_access.hpp"
11
12using namespace std::literals;
13using namespace pybind11::literals;
14
15// shamelessly stolen from the docs
16namespace pybind11::detail {
17 template <typename... Ts>
18 struct type_caster<boost::variant<Ts...>> : variant_caster<boost::variant<Ts...>> {};
19
20 // Specifies the function used to visit the variant -- `apply_visitor` instead of `visit`
21 template <>
22 struct visit_helper<boost::variant> {
23 template <typename... Args>
24 static auto call(Args &&...args) -> decltype(boost::apply_visitor(args...)) {
25 return boost::apply_visitor(args...);
26 }
27 };
28}
29
30
31PYBIND11_MODULE(netconf_cli_py, m) {
32 m.doc() = "Python bindings for accessing NETCONF servers";
33
34 pybind11::class_<special_>(m, "YangSpecial")
35 .def("__repr__",
36 [](const special_ s) {
37 return "<netconf_cli_py.YangSpecial " + specialValueToString(s) + ">";
38 });
39
40 pybind11::class_<enum_>(m, "YangEnum")
41 .def("__repr__",
42 [](const enum_ v) {
43 return "<netconf_cli_py.YangEnum '" + v.m_value + "'>";
44 });
45
46 pybind11::class_<binary_>(m, "YangBinary")
47 .def("__repr__",
48 [](const binary_ v) {
49 return "<netconf_cli_py.YangBinary '" + v.m_value + "'>";
50 });
51
52 pybind11::class_<identityRef_>(m, "YangIdentityRef")
53 .def("__repr__",
54 [](const identityRef_ v) {
55 return "<netconf_cli_py.YangIdentityRef '"s
56 + (v.m_prefix ? v.m_prefix->m_name + ":" : ""s) + v.m_value + "'>";
57 });
58
59 pybind11::class_<NetconfAccess>(m, "NetconfAccess")
60 .def(pybind11::init<const std::string&>(), "socketPath"_a)
61 .def("getItems", &NetconfAccess::getItems, "xpath"_a)
62 .def("setLeaf", &NetconfAccess::setLeaf, "xpath"_a, "value"_a)
63 .def("commitChanges", &NetconfAccess::commitChanges)
64 ;
65}