From a76a97ed78eba6c0ea65f0209ac83811c760e5f0 Mon Sep 17 00:00:00 2001 From: Michal Novak Date: Tue, 31 Oct 2023 11:13:14 +0100 Subject: [PATCH] gNMI adapter - fixes for non default IPC port, namespace is not part of returned capabilities, confd.conf - disabled webui, added cli and ipc port Signed-off-by: Michal Novak --- confd.conf | 16 +++++++++++++++- src/confd_gnmi_api_adapter.py | 20 +++++++++++--------- src/confd_gnmi_demo_adapter.py | 9 ++++++--- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/confd.conf b/confd.conf index a475704..4eeca7c 100644 --- a/confd.conf +++ b/confd.conf @@ -19,6 +19,10 @@ or the "In-service Data Model Upgrade" procedure described in the User Guide can be used - 'confd - -reload' is not enough. --> + + 4565 + + . @@ -210,6 +214,16 @@ ./ssh-keydir + + true + + + true + 0.0.0.0 + 2024 + + + true @@ -245,7 +259,7 @@ - true + false diff --git a/src/confd_gnmi_api_adapter.py b/src/confd_gnmi_api_adapter.py index 1640eeb..cf77cbf 100644 --- a/src/confd_gnmi_api_adapter.py +++ b/src/confd_gnmi_api_adapter.py @@ -51,7 +51,7 @@ def __init__(self): self.password: str = "" self.mp_inst = None # make sure schemas are loaded - with maapi.Maapi(): + with maapi.Maapi(ip=self.addr, port=self.port): pass nslist = _tm.get_nslist() self.module_to_pfx = {nsentry[-1]: nsentry[1] for nsentry in nslist} @@ -416,7 +416,8 @@ def authenticate(self, username="admin", password="admin"): log.info("==> username=%s password=:-)", username) self.username = username self.password = password - auth_status = maapi.Maapi().authenticate(self.username, self.password, 1) + auth_status = maapi.Maapi(ip=self.addr, port=self.port).authenticate( + self.username, self.password, 1) reason = "N/A" if not isinstance(auth_status, int): reason = auth_status[1] @@ -437,14 +438,15 @@ def get_netconf_capabilities(self): groups = [self.username] try: with maapi.single_read_trans(self.username, context, groups, - src_ip=self.addr, src_port=self.port) as t: + ip=self.addr, port=self.port) as t: root = maagic.get_root(t) values = [] count = 0 for module in root.modules_state.module: log.debug("val=%s", module.name) - name = f'{module.namespace}:{module.name}' - values.append((module.namespace, name, "", module.revision)) + name = f'{module.name}' + revision = str(module.revision) if module.revision else "N/A" + values.append((module.namespace, name, "", revision)) count += 1 log.debug("Value element count=%d" % count) log.debug("values=%s", values) @@ -644,7 +646,7 @@ def get_updates_with_maapi(self, path, data_type, allow_aggregation=False): updates = [] try: with maapi.single_read_trans(self.username, context, groups, db=db, - src_ip=self.addr, src_port=self.port) as t: + ip=self.addr, port=self.port) as t: updates = self.get_updates(t, pfx_path, save_flags, allow_aggregation=allow_aggregation) except ValueError: @@ -702,7 +704,7 @@ def set(self, prefix, updates): context = "netconf" groups = [self.username] with maapi.single_write_trans(self.username, context, groups, - src_ip=self.addr, src_port=self.port) as t: + ip=self.addr, port=self.port) as t: ops = [(up.path, self.set_update(t, prefix, up.path, up.val)) for up in updates] t.apply() @@ -714,8 +716,8 @@ def delete(self, prefix, paths): log.info("==> prefix=%s, paths=%s", prefix, paths) context = "netconf" groups = [self.username] - with maapi.single_write_trans(self.username, context, groups, src_ip=self.addr, - src_port=self.port) as t: + with maapi.single_write_trans(self.username, context, groups, ip=self.addr, + port=self.port) as t: ops = [] for path in paths: t.delete(self.fix_path_prefixes(make_formatted_path(path, prefix))) diff --git a/src/confd_gnmi_demo_adapter.py b/src/confd_gnmi_demo_adapter.py index 90cf504..13d9458 100644 --- a/src/confd_gnmi_demo_adapter.py +++ b/src/confd_gnmi_demo_adapter.py @@ -34,11 +34,14 @@ class GnmiDemoServerAdapter(GnmiServerAdapter): config = {} capability_list = [ - dict(name="http://tail-f.com/ns/aaa/1.1:tailf-aaa", + dict(ns="http://tail-f.com/ns/aaa/1.1", + name="tailf-aaa", organization="", version="2018-09-12"), - dict(name="urn:ietf:params:xml:ns:yang:ietf-inet-types:ietf-inet-types", + dict(ns="urn:ietf:params:xml:ns:yang:ietf-inet-types", + name="ietf-inet-types", organization="", version="2013-07-15"), - dict(name="urn:ietf:params:xml:ns:yang:ietf-interfaces:ietf-interfaces", + dict(ns="urn:ietf:params:xml:ns:yang:ietf-interfaces", + name="ietf-interfaces", organization="", version="2014-05-08"), ]