Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Václav Kubernát <kubernat@cesnet.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #pragma once |
| 9 | |
Václav Kubernát | ed4e378 | 2022-03-02 23:57:33 +0100 | [diff] [blame] | 10 | #include <libyang-cpp/Context.hpp> |
Václav Kubernát | bde37ba | 2022-03-25 15:18:12 +0100 | [diff] [blame] | 11 | #include <libnetconf2-cpp/Enum.hpp> |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 12 | #include <string> |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 13 | #include "datastore_access.hpp" |
| 14 | |
| 15 | /*! \class NetconfAccess |
| 16 | * \brief Implementation of DatastoreAccess for accessing a NETCONF server |
| 17 | */ |
| 18 | |
Václav Kubernát | f5f6d24 | 2022-04-07 01:06:19 +0200 | [diff] [blame] | 19 | namespace libnetconf::client { |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 20 | class Session; |
| 21 | } |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 22 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 23 | class Schema; |
| 24 | class YangSchema; |
| 25 | |
Václav Kubernát | bde37ba | 2022-03-25 15:18:12 +0100 | [diff] [blame] | 26 | using LogCb = std::function<void(libnetconf::LogLevel, const char*)>; |
Václav Kubernát | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 27 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 28 | class NetconfAccess : public DatastoreAccess { |
| 29 | public: |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 30 | NetconfAccess(const std::string& socketPath); |
Václav Kubernát | 7a9463f | 2020-10-30 08:57:59 +0100 | [diff] [blame] | 31 | NetconfAccess(const int source, const int sink); |
Jan Kundrát | dab815e | 2020-01-22 19:44:11 +0100 | [diff] [blame] | 32 | NetconfAccess(std::unique_ptr<libnetconf::client::Session>&& session); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 33 | ~NetconfAccess() override; |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 34 | [[nodiscard]] Tree getItems(const std::string& path) const override; |
Václav Kubernát | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 35 | |
Václav Kubernát | bde37ba | 2022-03-25 15:18:12 +0100 | [diff] [blame] | 36 | static void setNcLogLevel(libnetconf::LogLevel level); |
Václav Kubernát | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 37 | static void setNcLogCallback(const LogCb& callback); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 38 | void setLeaf(const std::string& path, leaf_data_ value) override; |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 39 | void createItem(const std::string& path) override; |
| 40 | void deleteItem(const std::string& path) override; |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 41 | void moveItem(const std::string& path, std::variant<yang::move::Absolute, yang::move::Relative> move) override; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 42 | void commitChanges() override; |
| 43 | void discardChanges() override; |
Václav Kubernát | b3960f8 | 2020-12-01 03:21:48 +0100 | [diff] [blame] | 44 | Tree execute(const std::string& path, const Tree& input) override; |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 45 | void copyConfig(const Datastore source, const Datastore destination) override; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 46 | |
| 47 | std::shared_ptr<Schema> schema() override; |
| 48 | |
Václav Kubernát | 59e4ee4 | 2020-07-08 17:32:45 +0200 | [diff] [blame] | 49 | [[nodiscard]] std::string dump(const DataFormat format) const override; |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 50 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 51 | private: |
Václav Kubernát | c15fe82 | 2020-06-04 11:28:39 +0200 | [diff] [blame] | 52 | std::vector<ListInstance> listInstances(const std::string& path) override; |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 53 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 54 | void doEditFromDataNode(libyang::DataNode dataNode); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 55 | |
Václav Kubernát | 06b0f38 | 2021-10-04 11:20:47 +0200 | [diff] [blame] | 56 | void checkNMDA(); |
| 57 | |
| 58 | bool m_serverHasNMDA; |
| 59 | |
Václav Kubernát | ed4e378 | 2022-03-02 23:57:33 +0100 | [diff] [blame] | 60 | libyang::Context m_context; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 61 | std::unique_ptr<libnetconf::client::Session> m_session; |
| 62 | std::shared_ptr<YangSchema> m_schema; |
| 63 | }; |