Newer
Older
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
34
35
36
37
38
39
40
41
from ncclient import manager
from ncclient.xml_ import *
import lxml.etree as ET
device = {
'host': '10.0.2.10', # IP address or hostname of the remote machine
'port': 2023, # SSH port (default: 22)
'username': 'admin', # SSH username
'password': 'admin', # SSH password
'device_params': {'name': 'default'},
'hostkey_verify':False,
"allow_agent":False
,"look_for_keys":False
}
def extract_value (xml_data):
xml_bytes = xml_data.encode("utf-8")
root = ET.fromstring(xml_bytes)
namespace = {'oc': 'http://openconfig.net/yang/platform',
'td': 'http://openconfig.net/yang/terminal-device'}
element = root.find('.//oc:component[oc:name="channel-4"]', namespace)
if element is not None:
parameter= element.find('.//td:frequency',namespace)
if (parameter is not None):
print(parameter.text)
else :
print("parameter is None")
else:
print(" element not found.")
with manager.connect(**device) as m:
# Perform operations on the remote machine using the 'm' object
# For example, you can retrieve the running configuration:
#result =m.edit_config(target='running',config=edit_config)
running_config = m.get_config('running').data_xml
extract_value(running_config)