Skip to content

Commit

Permalink
gNMI adapter - fixes for non default IPC port, namespace is not part …
Browse files Browse the repository at this point in the history
…of returned capabilities, confd.conf - disabled webui, added cli and ipc port

Signed-off-by: Michal Novak <[email protected]>
  • Loading branch information
micnovak committed Nov 1, 2023
1 parent 143ede2 commit a76a97e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
16 changes: 15 additions & 1 deletion confd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
-->
<confdIpcAddress>
<port>4565</port>
</confdIpcAddress>

<loadPath>
<dir>.</dir>
</loadPath>
Expand Down Expand Up @@ -210,6 +214,16 @@
<sshServerKeyDir>./ssh-keydir</sshServerKeyDir>
</aaa>

<cli>
<enabled>true</enabled>
<!-- Use the builtin SSH server -->
<ssh>
<enabled>true</enabled>
<ip>0.0.0.0</ip>
<port>2024</port>
</ssh>
</cli>

<netconf>
<enabled>true</enabled>
<transport>
Expand Down Expand Up @@ -245,7 +259,7 @@
</capabilities>
</netconf>
<webui>
<enabled>true</enabled>
<enabled>false</enabled>

<transport>
<tcp>
Expand Down
20 changes: 11 additions & 9 deletions src/confd_gnmi_api_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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]
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand All @@ -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)))
Expand Down
9 changes: 6 additions & 3 deletions src/confd_gnmi_demo_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]

Expand Down

0 comments on commit a76a97e

Please sign in to comment.