Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement request - wrapper for sr_install_modules and sr_remove_modules #26

Open
irfanHaslanded opened this issue Dec 10, 2024 · 2 comments

Comments

@irfanHaslanded
Copy link

Is it possible to have this functionality within sysrepo-cpp?

This is missing, and users need to either invoke sysrepocfg/sysrepoctl, or use a raw sysrepo connection and call these api and then wrap the connection into a managed Connection..

@jktjkt
Copy link
Collaborator

jktjkt commented Dec 11, 2024

Do you feel like sending a patch?

@irfanHaslanded
Copy link
Author

I am unable to login into CESNET gerrit, it just says 'Forbidden'.

Maybe something like below?
Connection.hpp

    void installModules(const std::vector<std::string>& schema_paths,
            const std::optional<std::string>& search_dir);

    void removeModules(const std::vector<std::string>& modules);

Connection.cpp

static std::vector<const char*> to_vec_c_str(const std::vector<std::string>& list)
{
    std::vector<const char*> native_list;
    native_list.reserve(1 + list.size());

    // iterate with reference to elements to ensure `elem.c_str()` lives as long as `list`
    // and avoid copying
    for (const auto &elem : list) {
        native_list.push_back(elem.c_str());
    }

    // sysrepo expects this array to be null terminated!
    native_list.push_back(nullptr);

    return native_list;
}

void Connection::installModules(const std::vector<std::string>& schema_paths, const std::optional<std::string>& search_dir)
{
    auto schema_paths_c = to_vec_c_str(schema_paths);
    auto res = sr_install_modules(ctx.get(), schema_paths_c.data(),
            search_dir ? search_dir->c_str() : nullptr, nullptr);

    throwIfError(res, "Couldn't install modules");
}

void Connection::removeModules(const std::vector<std::string>& modules)
{
    auto modules_c = to_vec_c_str(modules);
    auto res = sr_remove_modules(ctx.get(), modules_c.data(), 1);
    throwIfError(res, "Couldn't remove modules");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants