Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 38f8fda

Browse files
committed
[uniconfig] Add ReadStructureData with jsonb filter
1 parent 9d782e1 commit 38f8fda

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

uniconfig/python/frinx_worker/uniconfig/structured_data.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,65 @@ def execute(self, worker_input: WorkerInput) -> TaskResult[WorkerOutput]:
6767

6868
return handle_response(response, self.WorkerOutput)
6969

70+
class ReadStructuredDataWithJsonBFilter(WorkerImpl):
71+
from frinx_api.uniconfig.rest_api import ReadStructuredData as UniconfigApi
72+
73+
class ExecutionProperties(TaskExecutionProperties):
74+
exclude_empty_inputs: bool = True
75+
76+
class WorkerDefinition(TaskDefinition):
77+
name: str = "UNICONFIG_read_structured_device_data_with_jsonb_filter"
78+
description: str = (
79+
"Read device configuration or operational data in structured format e.g. openconfig "
80+
"and filter the output using jsonb (JsonPath) filter"
81+
)
82+
labels: list[str] = ["BASICS", "UNICONFIG", "OPENCONFIG"]
83+
84+
class WorkerInput(TaskInput):
85+
# url
86+
node_id: str
87+
uri: str | None = None
88+
topology_id: str = "uniconfig"
89+
# jsonb request parameters
90+
jsonb_filter: str
91+
add_parent_structure: bool = True
92+
# uniconfig
93+
transaction_id: str | None = None
94+
uniconfig_server_id: str | None = None
95+
uniconfig_url_base: str = UNICONFIG_URL_BASE
96+
97+
class WorkerOutput(TaskOutput):
98+
output: DictAny
99+
100+
def execute(self, worker_input: WorkerInput) -> TaskResult[WorkerOutput]:
101+
uri = ""
102+
if worker_input.uri:
103+
if not worker_input.uri.startswith("/"):
104+
uri = f"/{worker_input.uri}"
105+
else:
106+
uri = worker_input.uri
107+
108+
escaped_node_id = escape_uniconfig_uri_key(worker_input.node_id)
109+
url = worker_input.uniconfig_url_base + self.UniconfigApi.uri.format(
110+
topology_id=worker_input.topology_id, node_id=escaped_node_id, uri=uri
111+
)
112+
113+
response = requests.request(
114+
url=url,
115+
method="POST",
116+
cookies=uniconfig_zone_to_cookie(
117+
uniconfig_server_id=worker_input.uniconfig_server_id, transaction_id=worker_input.transaction_id
118+
),
119+
headers={"Content-Type": "application/filter-data+json"},
120+
params=UNICONFIG_REQUEST_PARAMS,
121+
json={
122+
"query": worker_input.jsonb_filter,
123+
"addParentStructure": worker_input.add_parent_structure
124+
}
125+
)
126+
127+
return handle_response(response, self.WorkerOutput)
128+
70129
class WriteStructuredData(WorkerImpl):
71130
from frinx_api.uniconfig.rest_api import ReadStructuredData as UniconfigApi
72131

0 commit comments

Comments
 (0)