diff --git a/cffi/cdefs.h b/cffi/cdefs.h index dd7bd18..6e61c62 100644 --- a/cffi/cdefs.h +++ b/cffi/cdefs.h @@ -44,11 +44,17 @@ sr_log_level_t sr_log_get_syslog(void); typedef struct sr_conn_ctx_s sr_conn_ctx_t; typedef struct sr_session_ctx_s sr_session_ctx_t; typedef enum sr_conn_flag_e { - SR_CONN_CACHE_RUNNING, - SR_CONN_CTX_SET_PRIV_PARSED, + SR_CONN_DEFAULT, ... } sr_conn_flag_t; -typedef uint32_t sr_conn_options_t; + +typedef enum { + SR_CTX_DEFAULT, + SR_CTX_NO_PRINTED, + SR_CTX_SET_PRIV_PARSED, + ... +} sr_context_flag_t; + typedef enum sr_datastore_e { SR_DS_STARTUP, SR_DS_RUNNING, @@ -76,8 +82,10 @@ struct timespec { long tv_nsec; }; -int sr_connect(const sr_conn_options_t, sr_conn_ctx_t **); +int sr_connect(const uint32_t opts, sr_conn_ctx_t **); int sr_disconnect(sr_conn_ctx_t *); +void sr_cache_running(int); +uint32_t sr_context_options(uint32_t, int, uint32_t *); const struct ly_ctx *sr_acquire_context(sr_conn_ctx_t *); void sr_release_context(sr_conn_ctx_t *); int sr_install_module(sr_conn_ctx_t *, const char *, const char *, const char **); diff --git a/cffi/source.c b/cffi/source.c index 5f754f2..5eab04d 100644 --- a/cffi/source.c +++ b/cffi/source.c @@ -7,9 +7,6 @@ #include #include -#if (SR_VERSION_MAJOR != 7) -#error "This version of sysrepo bindings only works with libsysrepo.so.7" -#endif -#if (SR_VERSION_MINOR < 10) -#error "Need at least libsysrepo.so.7.10" +#if (SR_VERSION_MAJOR != 8) +#error "This version of sysrepo bindings only works with libsysrepo.so.8" #endif diff --git a/sysrepo/connection.py b/sysrepo/connection.py index a4845e6..42d3253 100644 --- a/sysrepo/connection.py +++ b/sysrepo/connection.py @@ -36,26 +36,32 @@ class SysrepoConnection: __slots__ = ("cdata",) - def __init__(self, cache_running: bool = False): + def __init__(self, cache_running: bool = False, not_printed: bool = True): """ :arg cache_running: Always cache running datastore data which makes mainly repeated retrieval of data much faster. Affects all sessions created on this connection. + :arg not_printed: + The context is created from a sysrepo shared memory and is loaded faster. + Some operations on the context do not work. """ - flags = 0 - if cache_running: - flags |= lib.SR_CONN_CACHE_RUNNING + ctx_flags = 0 + if not_printed: + ctx_flags |= lib.SR_CTX_NO_PRINTED # mandatory flag to work with libyang-python - flags |= lib.SR_CONN_CTX_SET_PRIV_PARSED + ctx_flags |= lib.SR_CTX_SET_PRIV_PARSED conn_p = ffi.new("sr_conn_ctx_t **") # valid_signals() is only available since python 3.8 valid_signals = getattr(signal, "valid_signals", lambda: range(1, signal.NSIG)) sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, valid_signals()) try: - check_call(lib.sr_connect, flags, conn_p) + lib.sr_cache_running(cache_running) + lib.sr_context_options(ctx_flags, 0, ffi.NULL) + check_call(lib.sr_connect, 0, conn_p) self.cdata = ffi.gc(conn_p[0], lib.sr_disconnect) + finally: signal.pthread_sigmask(signal.SIG_SETMASK, sigmask) diff --git a/tests/test_connection.py b/tests/test_connection.py index eeb2b84..1d4b528 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -87,3 +87,9 @@ def test_conn_get_module_infos(self): self.assertEqual(pwd.getpwnam(owner).pw_uid, os.geteuid()) self.assertEqual(grp.getgrnam(group).gr_gid, os.getegid()) self.assertEqual(perm, 0o600) + + def test_conn_start_session_with_printed_context(self): + with sysrepo.SysrepoConnection(not_printed=False) as conn: + sess = conn.start_session() + self.assertEqual(sess.get_datastore(), "running") + sess.stop()