Esempio n. 1
0
 def connect(self, module, yang_location, tag='client', yang_ctx=None):
     if yang_ctx:
         self.libyang_ctx = yang_ctx
     elif yang_location:
         self.libyang_ctx = libyang.Context(yang_location)
     else:
         self.libyang_ctx = libyang.Context()
     self.libyang_ctx.load_module(module)
     self.module = module
     if not hasattr(self, 'libyang_data'):
         self.libyang_data = libyang.DataTree(self.libyang_ctx)
Esempio n. 2
0
    def connect(self, module=None,  yang_location=None, tag='client', yang_ctx=None):
        """
        Connect to the datastore.

        returns: True
        """
        if yang_location and not os.path.exists(yang_location + "/" + module + ".yang"):
            raise ValueError("YANG Module "+module+" not present in "+yang_location)
        self.module = module
        if not yang_ctx:
            self.yang_ctx = libyang.Context(yang_location)
            self.yang_schema = self.yang_ctx.load_module(self.module)
        else:
            self.yang_ctx = yang_ctx
            self.yang_schema = self.yang_ctx.load_module(self.module)

        connect_status = self.data_abstraction_layer.connect(self.module, yang_location, tag,
                                                             self.yang_ctx)

        self.session = self.data_abstraction_layer.session
        self.conn = self.data_abstraction_layer.conn
        self.connected = True

        self.context = yangvoodoo.VoodooNode.Context(self.module, self, self.yang_schema,
                                                     self.yang_ctx, log=self.log)
        self.data_abstraction_layer.context = self.context

        self.log.trace("CONNECT: module %s. yang_location %s", module, yang_location)
        self.log.trace("       : libyangctx %s ", self.yang_ctx)
        self.log.trace("       : context %s", self.context)
        self.log.trace("       : data_abstraction_layer %s", self.data_abstraction_layer)
        return connect_status
Esempio n. 3
0
 def get_ly_ctx(self) -> libyang.Context:
     """
     :returns:
         The `libyang.Context` object associated with this connection.
     """
     ctx = lib.sr_get_context(self.cdata)
     if not ctx:
         raise SysrepoInternalError("sr_get_context failed")
     return libyang.Context(cdata=ctx)
Esempio n. 4
0
 def get_ly_ctx(self) -> libyang.Context:
     """
     :returns:
         The libyang context object associated with this session.
     """
     conn = lib.sr_session_get_connection(self.cdata)
     if not conn:
         raise SysrepoInternalError("sr_session_get_connection failed")
     ctx = lib.sr_get_context(conn)
     if not ctx:
         raise SysrepoInternalError("sr_get_context failed")
     return libyang.Context(cdata=ctx)
Esempio n. 5
0
__author__ = "Mislav Novakovic <*****@*****.**>"
__copyright__ = "Copyright 2017, Deutsche Telekom AG"
__license__ = "BSD 3-Clause"

import libyang as ly

try:
    ctx = ly.Context("/etc/sysrepo/yang")
except Exception as e:
    print(e)
    sys.exit()

module = ctx.load_module("turing-machine", None)
if module is None:
    print("module not loaded")
    sys.exit()

try:
    node = ctx.parse_data_path("/etc/sysrepo/data/turing-machine.startup",
                               ly.LYD_XML, ly.LYD_OPT_CONFIG)
except Exception as e:
    print(e)
    sys.exit()

node_set = node.find_path(
    "/turing-machine:turing-machine/transition-function/delta[label='left summand']/*"
)
if node_set is None:
    print("could not find data for xpath")
    sys.exit()