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 | |
Václav Kubernát | bde37ba | 2022-03-25 15:18:12 +0100 | [diff] [blame] | 8 | #include <libnetconf2-cpp/netconf-client.hpp> |
Václav Kubernát | 02a7115 | 2020-01-21 14:52:51 +0100 | [diff] [blame] | 9 | #include "libyang_utils.hpp" |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 10 | #include "netconf_access.hpp" |
| 11 | #include "utils.hpp" |
| 12 | #include "yang_schema.hpp" |
| 13 | |
Jan Kundrát | 8f63fb7 | 2020-01-24 01:40:01 +0100 | [diff] [blame] | 14 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 15 | NetconfAccess::~NetconfAccess() = default; |
Václav Kubernát | f5d7515 | 2020-12-03 03:52:34 +0100 | [diff] [blame] | 16 | namespace { |
| 17 | auto targetToDs_get(const DatastoreTarget target) |
| 18 | { |
| 19 | switch (target) { |
| 20 | case DatastoreTarget::Operational: |
| 21 | return libnetconf::NmdaDatastore::Operational; |
| 22 | case DatastoreTarget::Running: |
| 23 | return libnetconf::NmdaDatastore::Running; |
| 24 | case DatastoreTarget::Startup: |
| 25 | return libnetconf::NmdaDatastore::Startup; |
| 26 | } |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 27 | |
Václav Kubernát | f5d7515 | 2020-12-03 03:52:34 +0100 | [diff] [blame] | 28 | __builtin_unreachable(); |
| 29 | } |
| 30 | |
| 31 | auto targetToDs_set(const DatastoreTarget target) |
| 32 | { |
| 33 | switch (target) { |
| 34 | case DatastoreTarget::Operational: |
| 35 | case DatastoreTarget::Running: |
| 36 | return libnetconf::NmdaDatastore::Candidate; |
| 37 | case DatastoreTarget::Startup: |
| 38 | return libnetconf::NmdaDatastore::Startup; |
| 39 | } |
| 40 | |
| 41 | __builtin_unreachable(); |
| 42 | } |
| 43 | } |
Václav Kubernát | d628291 | 2020-06-23 14:49:34 +0200 | [diff] [blame] | 44 | DatastoreAccess::Tree NetconfAccess::getItems(const std::string& path) const |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 45 | { |
Jan Kundrát | b331b55 | 2020-01-23 15:25:29 +0100 | [diff] [blame] | 46 | Tree res; |
Václav Kubernát | 06b0f38 | 2021-10-04 11:20:47 +0200 | [diff] [blame] | 47 | auto config = [this, &path] { |
| 48 | if (m_serverHasNMDA) { |
| 49 | return m_session->getData(targetToDs_get(m_target), (path != "/") ? std::optional{path} : std::nullopt); |
| 50 | } |
| 51 | |
| 52 | return m_session->get((path != "/") ? std::optional{path} : std::nullopt); |
| 53 | }(); |
Václav Kubernát | 9456b5c | 2019-10-02 21:14:52 +0200 | [diff] [blame] | 54 | |
| 55 | if (config) { |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 56 | lyNodesToTree(res, config->siblings()); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 57 | } |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 58 | return res; |
| 59 | } |
| 60 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 61 | NetconfAccess::NetconfAccess(const std::string& hostname, uint16_t port, const std::string& user, const std::string& pubKey, const std::string& privKey) |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 62 | : m_context(std::nullopt, libyang::ContextOptions::SetPrivParsed) |
Václav Kubernát | ed4e378 | 2022-03-02 23:57:33 +0100 | [diff] [blame] | 63 | , m_session(libnetconf::client::Session::connectPubkey(hostname, port, user, pubKey, privKey, m_context)) |
| 64 | , m_schema(std::make_shared<YangSchema>(m_context)) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 65 | { |
Václav Kubernát | 06b0f38 | 2021-10-04 11:20:47 +0200 | [diff] [blame] | 66 | checkNMDA(); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Václav Kubernát | 7a9463f | 2020-10-30 08:57:59 +0100 | [diff] [blame] | 69 | NetconfAccess::NetconfAccess(const int source, const int sink) |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 70 | : m_context(std::nullopt, libyang::ContextOptions::SetPrivParsed) |
Václav Kubernát | ed4e378 | 2022-03-02 23:57:33 +0100 | [diff] [blame] | 71 | , m_session(libnetconf::client::Session::connectFd(source, sink, m_context)) |
| 72 | , m_schema(std::make_shared<YangSchema>(m_context)) |
Václav Kubernát | 7a9463f | 2020-10-30 08:57:59 +0100 | [diff] [blame] | 73 | { |
Václav Kubernát | 06b0f38 | 2021-10-04 11:20:47 +0200 | [diff] [blame] | 74 | checkNMDA(); |
Václav Kubernát | 7a9463f | 2020-10-30 08:57:59 +0100 | [diff] [blame] | 75 | } |
| 76 | |
Jan Kundrát | dab815e | 2020-01-22 19:44:11 +0100 | [diff] [blame] | 77 | NetconfAccess::NetconfAccess(std::unique_ptr<libnetconf::client::Session>&& session) |
| 78 | : m_session(std::move(session)) |
Václav Kubernát | 1d50a5b | 2020-02-03 16:44:22 +0100 | [diff] [blame] | 79 | , m_schema(std::make_shared<YangSchema>(m_session->libyangContext())) |
Jan Kundrát | dab815e | 2020-01-22 19:44:11 +0100 | [diff] [blame] | 80 | { |
Václav Kubernát | 06b0f38 | 2021-10-04 11:20:47 +0200 | [diff] [blame] | 81 | checkNMDA(); |
Jan Kundrát | dab815e | 2020-01-22 19:44:11 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 84 | NetconfAccess::NetconfAccess(const std::string& socketPath) |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 85 | : m_context(std::nullopt, libyang::ContextOptions::SetPrivParsed) |
Václav Kubernát | ed4e378 | 2022-03-02 23:57:33 +0100 | [diff] [blame] | 86 | , m_session(libnetconf::client::Session::connectSocket(socketPath, m_context)) |
| 87 | , m_schema(std::make_shared<YangSchema>(m_context)) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 88 | { |
Václav Kubernát | 06b0f38 | 2021-10-04 11:20:47 +0200 | [diff] [blame] | 89 | checkNMDA(); |
| 90 | } |
| 91 | |
| 92 | void NetconfAccess::checkNMDA() |
| 93 | { |
| 94 | auto nmdaMod = m_schema->getYangModule("ietf-netconf-nmda"); |
| 95 | m_serverHasNMDA = nmdaMod && nmdaMod->implemented(); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 96 | } |
| 97 | |
Václav Kubernát | bde37ba | 2022-03-25 15:18:12 +0100 | [diff] [blame] | 98 | void NetconfAccess::setNcLogLevel(libnetconf::LogLevel level) |
Václav Kubernát | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 99 | { |
| 100 | libnetconf::client::setLogLevel(level); |
| 101 | } |
| 102 | |
| 103 | void NetconfAccess::setNcLogCallback(const LogCb& callback) |
| 104 | { |
| 105 | libnetconf::client::setLogCallback(callback); |
| 106 | } |
| 107 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 108 | void NetconfAccess::setLeaf(const std::string& path, leaf_data_ value) |
| 109 | { |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 110 | auto lyValue = value.type() == typeid(empty_) ? std::nullopt : std::optional(leafDataToString(value)); |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 111 | auto nodes = m_schema->dataNodeFromPath(path, lyValue); |
| 112 | doEditFromDataNode(*nodes.createdParent); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 115 | void NetconfAccess::createItem(const std::string& path) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 116 | { |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 117 | auto nodes = m_schema->dataNodeFromPath(path); |
| 118 | doEditFromDataNode(*nodes.createdParent); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 121 | void NetconfAccess::deleteItem(const std::string& path) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 122 | { |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 123 | auto nodes = m_schema->dataNodeFromPath(path); |
| 124 | |
| 125 | // When deleting leafs, `nodes.newNode` is opaque, because the leaf does not have a value. We need to use |
| 126 | // newAttrOpaqueJSON for opaque leafs. |
| 127 | if (nodes.createdNode->isOpaque()) { |
| 128 | nodes.createdNode->newAttrOpaqueJSON("ietf-netconf", "ietf-netconf:operation", "delete"); |
| 129 | } else { |
| 130 | nodes.createdNode->newMeta(*m_schema->getYangModule("ietf-netconf"), "operation", "delete"); |
| 131 | } |
| 132 | doEditFromDataNode(*nodes.createdParent); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 135 | struct impl_toYangInsert { |
| 136 | std::string operator()(yang::move::Absolute& absolute) |
| 137 | { |
| 138 | return absolute == yang::move::Absolute::Begin ? "first" : "last"; |
| 139 | } |
| 140 | std::string operator()(yang::move::Relative& relative) |
| 141 | { |
| 142 | return relative.m_position == yang::move::Relative::Position::After ? "after" : "before"; |
| 143 | } |
| 144 | }; |
| 145 | |
| 146 | std::string toYangInsert(std::variant<yang::move::Absolute, yang::move::Relative> move) |
| 147 | { |
| 148 | return std::visit(impl_toYangInsert{}, move); |
| 149 | } |
| 150 | |
| 151 | void NetconfAccess::moveItem(const std::string& source, std::variant<yang::move::Absolute, yang::move::Relative> move) |
| 152 | { |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 153 | auto nodes = m_schema->dataNodeFromPath(source); |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 154 | auto sourceNode = *(nodes.createdNode->findPath(source)); |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 155 | auto yangModule = *m_schema->getYangModule("yang"); |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 156 | sourceNode.newMeta(yangModule, "insert", toYangInsert(move)); |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 157 | |
| 158 | if (std::holds_alternative<yang::move::Relative>(move)) { |
| 159 | auto relative = std::get<yang::move::Relative>(move); |
| 160 | if (m_schema->nodeType(source) == yang::NodeTypes::LeafList) { |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 161 | sourceNode.newMeta(yangModule, "value", leafDataToString(relative.m_path.at("."))); |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 162 | } else { |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 163 | sourceNode.newMeta(yangModule, "key", instanceToString(relative.m_path, std::string{nodes.createdNode->schema().module().name()})); |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | doEditFromDataNode(sourceNode); |
| 167 | } |
| 168 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 169 | void NetconfAccess::doEditFromDataNode(libyang::DataNode dataNode) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 170 | { |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 171 | auto data = dataNode.printStr(libyang::DataFormat::XML, libyang::PrintFlags::WithSiblings); |
Václav Kubernát | 06b0f38 | 2021-10-04 11:20:47 +0200 | [diff] [blame] | 172 | if (m_serverHasNMDA) { |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 173 | m_session->editData(targetToDs_set(m_target), std::string{*data}); |
Václav Kubernát | 06b0f38 | 2021-10-04 11:20:47 +0200 | [diff] [blame] | 174 | } else { |
Václav Kubernát | bde37ba | 2022-03-25 15:18:12 +0100 | [diff] [blame] | 175 | m_session->editConfig( |
| 176 | libnetconf::Datastore::Candidate, |
| 177 | libnetconf::EditDefaultOp::Merge, |
| 178 | libnetconf::EditTestOpt::TestSet, |
| 179 | libnetconf::EditErrorOpt::Stop, |
| 180 | std::string{*data}); |
Václav Kubernát | 06b0f38 | 2021-10-04 11:20:47 +0200 | [diff] [blame] | 181 | } |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | void NetconfAccess::commitChanges() |
| 185 | { |
| 186 | m_session->commit(); |
| 187 | } |
| 188 | |
| 189 | void NetconfAccess::discardChanges() |
| 190 | { |
| 191 | m_session->discard(); |
| 192 | } |
| 193 | |
Václav Kubernát | b3960f8 | 2020-12-01 03:21:48 +0100 | [diff] [blame] | 194 | DatastoreAccess::Tree NetconfAccess::execute(const std::string& path, const Tree& input) |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 195 | { |
Václav Kubernát | fbab2d4 | 2021-02-05 16:12:34 +0100 | [diff] [blame] | 196 | auto inputNode = treeToRpcInput(m_session->libyangContext(), path, input); |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 197 | auto data = inputNode.printStr(libyang::DataFormat::XML, libyang::PrintFlags::WithSiblings); |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 198 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 199 | auto output = m_session->rpc_or_action(std::string{*data}); |
| 200 | if (!output) { |
| 201 | return {}; |
| 202 | } |
| 203 | return rpcOutputToTree(*output); |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 204 | } |
| 205 | |
Václav Kubernát | bde37ba | 2022-03-25 15:18:12 +0100 | [diff] [blame] | 206 | libnetconf::Datastore toNcDatastore(Datastore datastore) |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 207 | { |
| 208 | switch (datastore) { |
| 209 | case Datastore::Running: |
Václav Kubernát | bde37ba | 2022-03-25 15:18:12 +0100 | [diff] [blame] | 210 | return libnetconf::Datastore::Running; |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 211 | case Datastore::Startup: |
Václav Kubernát | bde37ba | 2022-03-25 15:18:12 +0100 | [diff] [blame] | 212 | return libnetconf::Datastore::Startup; |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 213 | } |
| 214 | __builtin_unreachable(); |
| 215 | } |
| 216 | |
| 217 | void NetconfAccess::copyConfig(const Datastore source, const Datastore destination) |
| 218 | { |
| 219 | m_session->copyConfig(toNcDatastore(source), toNcDatastore(destination)); |
| 220 | } |
| 221 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 222 | std::shared_ptr<Schema> NetconfAccess::schema() |
| 223 | { |
| 224 | return m_schema; |
| 225 | } |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 226 | |
| 227 | std::vector<ListInstance> NetconfAccess::listInstances(const std::string& path) |
| 228 | { |
| 229 | std::vector<ListInstance> res; |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 230 | auto keys = m_session->libyangContext().findXPath(path).front().asList().keys(); |
| 231 | auto nodes = m_session->libyangContext().newPath2(path, std::nullopt, libyang::CreationOptions::Opaque); |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 232 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 233 | // Here we create a tree with "selection leafs" for all they keys of our wanted list. These leafs tell NETCONF, that |
| 234 | // we only want the list's keys and not any other data. |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 235 | for (const auto& keyLeaf : keys) { |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 236 | // Selection leafs need to be inserted directly to the list using relative paths, that's why `newNode` is used |
| 237 | // here. |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 238 | nodes.createdNode->newPath(keyLeaf.name().data(), std::nullopt, libyang::CreationOptions::Opaque); |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 239 | } |
| 240 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 241 | // Have to use `newParent` in case our wanted list is a nested list. With `newNode` I would only send the inner |
| 242 | // nested list and not the whole tree. |
| 243 | auto instances = m_session->get(std::string{*nodes.createdParent->printStr(libyang::DataFormat::XML, libyang::PrintFlags::WithSiblings)}); |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 244 | |
Václav Kubernát | 45e5546 | 2020-02-04 11:19:32 +0100 | [diff] [blame] | 245 | if (!instances) { |
| 246 | return res; |
| 247 | } |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 248 | |
Jan Kundrát | f59b83c | 2022-03-18 18:12:08 +0100 | [diff] [blame] | 249 | for (const auto& instance : instances->findXPath(path)) { |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 250 | ListInstance instanceRes; |
| 251 | |
Jan Kundrát | 5c3428b | 2022-06-27 00:10:59 +0200 | [diff] [blame] | 252 | for (const auto& keyLeaf : instance.immediateChildren()) { |
Václav Kubernát | ba84ede | 2021-02-04 17:21:11 +0100 | [diff] [blame] | 253 | // FIXME: even though we specified we only want the key leafs, Netopeer disregards that and sends more data, |
| 254 | // even lists and other stuff. We only want keys, so filter out non-leafs and non-keys |
| 255 | // https://github.com/CESNET/netopeer2/issues/825 |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 256 | if (keyLeaf.schema().nodeType() != libyang::NodeType::Leaf) { |
Václav Kubernát | ba84ede | 2021-02-04 17:21:11 +0100 | [diff] [blame] | 257 | continue; |
| 258 | } |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 259 | if (!keyLeaf.schema().asLeaf().isKey()) { |
Václav Kubernát | ba84ede | 2021-02-04 17:21:11 +0100 | [diff] [blame] | 260 | continue; |
| 261 | } |
| 262 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 263 | auto leafData = keyLeaf.asTerm(); |
| 264 | instanceRes.insert({std::string{leafData.schema().name()}, leafValueFromNode(leafData)}); |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 265 | } |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 266 | res.emplace_back(instanceRes); |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | return res; |
| 270 | } |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 271 | |
| 272 | std::string NetconfAccess::dump(const DataFormat format) const |
| 273 | { |
| 274 | auto config = m_session->get(); |
| 275 | if (!config) { |
| 276 | return ""; |
| 277 | } |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 278 | auto str = config->printStr(format == DataFormat::Xml ? libyang::DataFormat::XML : libyang::DataFormat::JSON, libyang::PrintFlags::WithSiblings); |
| 279 | if (!str) { |
| 280 | return ""; |
| 281 | } |
| 282 | |
| 283 | return std::string{*str}; |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 284 | } |