File: yangcli.py

package info (click to toggle)
yuma123 2.14-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,436 kB
  • sloc: ansic: 185,144; cpp: 10,968; python: 7,990; sh: 2,676; makefile: 1,175; xml: 807; exp: 776; perl: 70
file content (33 lines) | stat: -rw-r--r-- 836 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import yangrpc
import yuma
import traceback
from lxml import etree

def yangcli(yangrpc_cb,cmd_line,strip_namespaces=True):

	(res, rpc_val) = yangrpc.parse_cli(yangrpc_cb, cmd_line)
	if(res!=0):
		raise NameError("Error: yangrpc failed to parse cli command!")
		return None

	(res, reply_val) = yangrpc.rpc(yangrpc_cb, rpc_val)
	if(res!=0):
		raise NameError("Error: yangrpc failed to execute rpc!")
		return None

	if(strip_namespaces):
		display_mode=yuma.NCX_DISPLAY_MODE_XML_NONS
	else:
		display_mode=yuma.NCX_DISPLAY_MODE_XML

	(res, reply_xml_str) = yuma.val_make_serialized_string(reply_val, display_mode)
	if(res!=0):
		raise NameError("Error: yuma.val_make_serialized_string failed!")
		return None

	yuma.val_free_value(rpc_val);
	yuma.val_free_value(reply_val);

	myetree = etree.fromstring(reply_xml_str)

	return myetree