blob: 14288bc957c39d6286d55a697ae97be146eba9f6 [file] [log] [blame]
Václav Kubernátc31bd602019-03-07 11:44:48 +01001/*
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áte2e15ee2020-02-05 17:38:13 +010010#include <libnetconf2/log.h>
Václav Kubernátc31bd602019-03-07 11:44:48 +010011#include <string>
Václav Kubernátc31bd602019-03-07 11:44:48 +010012#include "datastore_access.hpp"
13
14/*! \class NetconfAccess
15 * \brief Implementation of DatastoreAccess for accessing a NETCONF server
16 */
17
18namespace libnetconf {
19namespace client {
20class Session;
21}
22}
23
24namespace libyang {
25class Data_Node;
26}
27
28class Schema;
29class YangSchema;
30
Václav Kubernáte2e15ee2020-02-05 17:38:13 +010031using LogCb = std::function<void(NC_VERB_LEVEL, const char*)>;
32
Václav Kubernátc31bd602019-03-07 11:44:48 +010033class NetconfAccess : public DatastoreAccess {
34public:
35 NetconfAccess(const std::string& hostname, uint16_t port, const std::string& user, const std::string& pubKey, const std::string& privKey);
36 NetconfAccess(const std::string& socketPath);
Václav Kubernát7a9463f2020-10-30 08:57:59 +010037 NetconfAccess(const int source, const int sink);
Jan Kundrátdab815e2020-01-22 19:44:11 +010038 NetconfAccess(std::unique_ptr<libnetconf::client::Session>&& session);
Václav Kubernátc31bd602019-03-07 11:44:48 +010039 ~NetconfAccess() override;
Václav Kubernát59e4ee42020-07-08 17:32:45 +020040 [[nodiscard]] Tree getItems(const std::string& path) const override;
Václav Kubernáte2e15ee2020-02-05 17:38:13 +010041
42 static void setNcLogLevel(NC_VERB_LEVEL level);
43 static void setNcLogCallback(const LogCb& callback);
Václav Kubernátc31bd602019-03-07 11:44:48 +010044 void setLeaf(const std::string& path, leaf_data_ value) override;
Jan Kundrátcbf288b2020-06-18 20:44:39 +020045 void createItem(const std::string& path) override;
46 void deleteItem(const std::string& path) override;
Václav Kubernátbf65dd72020-05-28 02:32:31 +020047 void moveItem(const std::string& path, std::variant<yang::move::Absolute, yang::move::Relative> move) override;
Václav Kubernátc31bd602019-03-07 11:44:48 +010048 void commitChanges() override;
49 void discardChanges() override;
Václav Kubernátb3960f82020-12-01 03:21:48 +010050 Tree execute(const std::string& path, const Tree& input) override;
Václav Kubernát7160a132020-04-03 02:11:01 +020051 void copyConfig(const Datastore source, const Datastore destination) override;
Václav Kubernátc31bd602019-03-07 11:44:48 +010052
53 std::shared_ptr<Schema> schema() override;
54
Václav Kubernát59e4ee42020-07-08 17:32:45 +020055 [[nodiscard]] std::string dump(const DataFormat format) const override;
Václav Kubernát70d7f7a2020-06-23 14:40:40 +020056
Václav Kubernátc31bd602019-03-07 11:44:48 +010057private:
Václav Kubernátc15fe822020-06-04 11:28:39 +020058 std::vector<ListInstance> listInstances(const std::string& path) override;
Václav Kubernáta8789602020-07-20 15:18:19 +020059 DatastoreAccess::Tree impl_execute(const std::string& path, const Tree& input);
Václav Kubernátab612e92019-11-26 19:51:31 +010060
Václav Kubernátb52dc252019-12-04 13:03:39 +010061 std::string fetchSchema(const std::string_view module, const
62 std::optional<std::string_view> revision, const
63 std::optional<std::string_view> submodule, const
64 std::optional<std::string_view> submoduleRevision);
Václav Kubernátc31bd602019-03-07 11:44:48 +010065 std::vector<std::string> listImplementedSchemas();
66 void datastoreInit();
67 void doEditFromDataNode(std::shared_ptr<libyang::Data_Node> dataNode);
68
69 std::unique_ptr<libnetconf::client::Session> m_session;
70 std::shared_ptr<YangSchema> m_schema;
71};