# servers capabilities c = session.capabilities print(c) # get config print("---GET CONFIG---") config = session.get_config() xmlstr = etree.tostring(config, encoding='utf8', xml_declaration=True) print(xmlstr) # edit config new_config = ''' <config> <topology xmlns="urn:topology"> <node operation="merge"> <!-- modify with delete --> <node-id>10.1.7.64</node-id> <port> <port-id>3</port-id> </port> </node> </topology> </config> ''' print("---EDIT CONFIG---") config = session.edit_config(newconf=new_config) xmlstr = etree.tostring(config, encoding='utf8', xml_declaration=True) print(xmlstr) # close connexion session.close()
port = 830 username = "******" password = "******" # connexion to servers session = NetconfSSHSession(host, port, username, password) # servers capabilities c = session.capabilities print(c) # get config print("---GET CONFIG---") config = session.get_config() xmlstr = etree.tostring(config, encoding='utf8', xml_declaration=True) print(xmlstr) # edit config print("---EDIT CONFIG---") xml = etree.parse('new_config.xml') # new configuration config = session.edit_config(method='none', newconf=etree.tostring(xml)) xmlstr = etree.tostring(config, encoding='utf8', xml_declaration=True) print(xmlstr) # print("---GET---") # config = session.get_config() # xmlstr = etree.tostring(config, encoding='utf8', xml_declaration=True) # print(xmlstr) session.close()
from netconf.client import NetconfSSHSession host = '192.168.5.41' port = 8300 username = '******' password = '******' try: session = NetconfSSHSession(host, port, username, password) #config = session.get_config() config = session.edit_config('adf') print(config) except Exception as e: print(e)
from netconf.client import NetconfSSHSession import xmltodict from xmljson import badgerfish as bf from lxml import etree with open('tests/testdata2.xml', 'r') as file: data = file.read().replace('\n', '') etreeX = etree.parse('tests/testdata2.xml') #print(type(etreeX[0])) newconf = etreeX.getroot() print(etree.tostring(newconf, pretty_print=True)) session = NetconfSSHSession("localhost", "8300", "admin", "admin") edit_config_response = session.edit_config(newconf=data) print(etree.tostring(edit_config_response, pretty_print=True)) session.close()
node_con.connection[connectionid].port_out_out = port_out_out node_con.connection[connectionid].transceiver = transceiverid return node_con if __name__ == '__main__': session = NetconfSSHSession(host, port, username, password) c = addConnection("5001", "65792", "65536", "1") c2 = addConnection("5002", "65536", "65792", "1") c3 = addConnection("5003", "65536", "65792", "1") c4 = addConnection("5004", "65536", "65792", "1") opC = 'create' opD = 'delete' print("--EDIT CONFIG 1--") config = session.edit_config(method=opC, newconf=pybindIETFXMLEncoder.serialise(c)) xmlstr = etree.tostring(config, encoding='utf8', xml_declaration=True) print(xmlstr) print("--EDIT CONFIG 2--") config = session.edit_config(method=opC, newconf=pybindIETFXMLEncoder.serialise(c2)) xmlstr = etree.tostring(config, encoding='utf8', xml_declaration=True) print(xmlstr) print("--EDIT CONFIG 3--") config = session.edit_config(method=opC, newconf=pybindIETFXMLEncoder.serialise(c3)) xmlstr = etree.tostring(config, encoding='utf8', xml_declaration=True) print(xmlstr)