-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpython_netconf.cpp
More file actions
71 lines (60 loc) · 2.56 KB
/
python_netconf.cpp
File metadata and controls
71 lines (60 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
*
* Written by Jan Kundrát <[email protected]>
*
*/
#include <pybind11/functional.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <libnetconf2-cpp/netconf-client.hpp>
#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(pybind11::init<const int, const int>(), "source"_a, "sink"_a)
.def("getItems", &NetconfAccess::getItems, "xpath"_a)
.def("setLeaf", &NetconfAccess::setLeaf, "xpath"_a, "value"_a)
.def("createItem", &NetconfAccess::createItem, "xpath"_a)
.def("deleteItem", &NetconfAccess::deleteItem, "xpath"_a)
.def("execute", &NetconfAccess::execute, "rpc"_a, "input"_a=DatastoreAccess::Tree{})
.def("commitChanges", &NetconfAccess::commitChanges)
;
}