예제 #1
0
# connexion parameters
host = 'localhost'
port = 2022
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
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>
from netconf.client import NetconfSSHSession

from lxml import etree

session = NetconfSSHSession("localhost", "8300", "admin", "admin")
config = session.get_config(select='<components xmlns="http://openconfig.net/yang/platform"><component><name>shelf-sh41</name><config/></component></components>')

#dom = xml.dom.minidom.parseString(config)

#print(dom.toprettyxml())

print(etree.tostring(config, pretty_print=True))
session.close()