|
@@ -10,6 +10,9 @@
|
|
|
#include <klish/kplugin.h>
|
|
|
#include <klish/kcontext.h>
|
|
|
|
|
|
+#include <sysrepo.h>
|
|
|
+#include <sysrepo/xpath.h>
|
|
|
+
|
|
|
#include "private.h"
|
|
|
|
|
|
|
|
@@ -21,11 +24,28 @@ int kplugin_sysrepo_init(kcontext_t *context)
|
|
|
{
|
|
|
kplugin_t *plugin = NULL;
|
|
|
ksym_t *sym = NULL;
|
|
|
+ int err = SR_ERR_OK;
|
|
|
+ sr_conn_ctx_t *conn = NULL;
|
|
|
+ sr_session_ctx_t *sess = NULL;
|
|
|
|
|
|
assert(context);
|
|
|
plugin = kcontext_plugin(context);
|
|
|
assert(plugin);
|
|
|
|
|
|
+ err = sr_connect(SR_CONN_DEFAULT, &conn);
|
|
|
+ if (err) {
|
|
|
+ fprintf(stderr, "Can't connect to Sysrepo\n");
|
|
|
+ return -1;;
|
|
|
+ }
|
|
|
+ err = sr_session_start(conn, SR_DS_RUNNING, &sess);
|
|
|
+ if (err) {
|
|
|
+ fprintf(stderr, "Can't start Sysrepo session\n");
|
|
|
+ sr_disconnect(conn);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ kplugin_set_udata(plugin, sess);
|
|
|
+
|
|
|
|
|
|
|
|
|
kplugin_add_syms(plugin, ksym_new_ext("nop", klish_nop,
|
|
@@ -62,7 +82,16 @@ int kplugin_sysrepo_init(kcontext_t *context)
|
|
|
|
|
|
int kplugin_sysrepo_fini(kcontext_t *context)
|
|
|
{
|
|
|
- context = context;
|
|
|
+ kplugin_t *plugin = NULL;
|
|
|
+ sr_session_ctx_t *sess = NULL;
|
|
|
+
|
|
|
+ if (!context)
|
|
|
+ return -1;
|
|
|
+
|
|
|
+ plugin = kcontext_plugin(context);
|
|
|
+ sess = (sr_session_ctx_t *)kplugin_udata(plugin);
|
|
|
+
|
|
|
+ sr_disconnect(sr_session_get_connection(sess));
|
|
|
|
|
|
return 0;
|
|
|
}
|