Add utils::ensureModuleImplemented
Change-Id: I6562afed792da1d09bcfa2a189e1ae9a7cd9528f
diff --git a/src/utils/sysrepo.cpp b/src/utils/sysrepo.cpp
index 4d6ebe0..dc97c52 100644
--- a/src/utils/sysrepo.cpp
+++ b/src/utils/sysrepo.cpp
@@ -96,4 +96,11 @@
session->apply_changes();
}
+/** @brief Checks whether a module is implemented in Sysrepo and throws if not. */
+void ensureModuleImplemented(std::shared_ptr<::sysrepo::Session> session, const std::string& module, const std::string& revision)
+{
+ if (auto mod = session->get_context()->get_module(module.c_str(), revision.c_str()); !mod || !mod->implemented()) {
+ throw std::runtime_error(module + "@" + revision + " is not implemented in sysrepo.");
+ }
+}
}