blob: d9830bdc1b247ae57e11494f11b47162e4a8ce60 [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
10#include <string>
Václav Kubernátc31bd602019-03-07 11:44:48 +010011#include "datastore_access.hpp"
12
13/*! \class NetconfAccess
14 * \brief Implementation of DatastoreAccess for accessing a NETCONF server
15 */
16
17namespace libnetconf {
18namespace client {
19class Session;
20}
21}
22
23namespace libyang {
24class Data_Node;
25}
26
27class Schema;
28class YangSchema;
29
30class NetconfAccess : public DatastoreAccess {
31public:
32 NetconfAccess(const std::string& hostname, uint16_t port, const std::string& user, const std::string& pubKey, const std::string& privKey);
33 NetconfAccess(const std::string& socketPath);
Jan Kundrátdab815e2020-01-22 19:44:11 +010034 NetconfAccess(std::unique_ptr<libnetconf::client::Session>&& session);
Václav Kubernátc31bd602019-03-07 11:44:48 +010035 ~NetconfAccess() override;
Václav Kubernátd6282912020-06-23 14:49:34 +020036 Tree getItems(const std::string& path) const override;
Václav Kubernátc31bd602019-03-07 11:44:48 +010037 void setLeaf(const std::string& path, leaf_data_ value) override;
Jan Kundrátcbf288b2020-06-18 20:44:39 +020038 void createItem(const std::string& path) override;
39 void deleteItem(const std::string& path) override;
Václav Kubernátbf65dd72020-05-28 02:32:31 +020040 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 +010041 void commitChanges() override;
42 void discardChanges() override;
Jan Kundrát6ee84792020-01-24 01:43:36 +010043 Tree executeRpc(const std::string& path, const Tree& input) override;
Václav Kubernát7160a132020-04-03 02:11:01 +020044 void copyConfig(const Datastore source, const Datastore destination) override;
Václav Kubernátc31bd602019-03-07 11:44:48 +010045
46 std::shared_ptr<Schema> schema() override;
47
Václav Kubernát70d7f7a2020-06-23 14:40:40 +020048 std::string dump(const DataFormat format) const override;
49
Václav Kubernátc31bd602019-03-07 11:44:48 +010050private:
Václav Kubernátc15fe822020-06-04 11:28:39 +020051 std::vector<ListInstance> listInstances(const std::string& path) override;
Václav Kubernátab612e92019-11-26 19:51:31 +010052
Václav Kubernátb52dc252019-12-04 13:03:39 +010053 std::string fetchSchema(const std::string_view module, const
54 std::optional<std::string_view> revision, const
55 std::optional<std::string_view> submodule, const
56 std::optional<std::string_view> submoduleRevision);
Václav Kubernátc31bd602019-03-07 11:44:48 +010057 std::vector<std::string> listImplementedSchemas();
58 void datastoreInit();
59 void doEditFromDataNode(std::shared_ptr<libyang::Data_Node> dataNode);
60
61 std::unique_ptr<libnetconf::client::Session> m_session;
62 std::shared_ptr<YangSchema> m_schema;
63};