Commit 91e5cfae authored by douomo's avatar douomo
Browse files

NetconfLibrary compatbile with older python3 versions

parent 3a82d9e1
Loading
Loading
Loading
Loading
+7 −7
Original line number Original line Diff line number Diff line
"""RobotFramework library to control network element via NETCONF."""
"""RobotFramework library to control network element via NETCONF."""


from csv import DictReader
from csv import DictReader
from typing import NamedTuple
from typing import NamedTuple, Optional


from robot.api.deco import keyword, library
from robot.api.deco import keyword, library
from robot.libraries.BuiltIn import BuiltIn
from robot.libraries.BuiltIn import BuiltIn
@@ -32,7 +32,7 @@ class NetconfLibrary:
    """RobotFramework library to control network element via NETCONF."""
    """RobotFramework library to control network element via NETCONF."""


    builtin = BuiltIn()
    builtin = BuiltIn()
    network: list[NetworkElement] | None = None
    network: Optional[list[NetworkElement]] = None


    @keyword("the network mentioned in ${network_filename}")
    @keyword("the network mentioned in ${network_filename}")
    def the_network_mentioned_in_csv(self, network_filename: str) -> None:
    def the_network_mentioned_in_csv(self, network_filename: str) -> None:
@@ -48,7 +48,7 @@ class NetconfLibrary:
        ``vlan_id`` is pushed in all NEs.
        ``vlan_id`` is pushed in all NEs.
        """
        """
        for ne in self.network:
        for ne in self.network:
            m = connect_with_key(ne.address, ne.mgmt_port, ne.username, "path to private key")
            m = connect_with_key(ne.address, ne.mgmt_port, ne.username, "/home/douomo/.ssh/netconf_key")
            #m = connect_with_credentials(ne.address, ne.mgmt_port, ne.username, ne.password)
            #m = connect_with_credentials(ne.address, ne.mgmt_port, ne.username, ne.password)
            xml = create_VLAN_xml(ne,vlan_id)
            xml = create_VLAN_xml(ne,vlan_id)
            target = "candidate"
            target = "candidate"
@@ -64,7 +64,7 @@ class NetconfLibrary:
        Fails if the VLAN is missing in any of the NEs.
        Fails if the VLAN is missing in any of the NEs.
        """
        """
        for ne in self.network:
        for ne in self.network:
            m = connect_with_key(ne.address, ne.mgmt_port, ne.username, "path to private key")
            m = connect_with_key(ne.address, ne.mgmt_port, ne.username, "/home/douomo/.ssh/netconf_key")
            #m = connect_with_credentials(ne.address, ne.mgmt_port, ne.username, ne.password)
            #m = connect_with_credentials(ne.address, ne.mgmt_port, ne.username, ne.password)
            config = m.get_config(source='running').data_xml
            config = m.get_config(source='running').data_xml
            m.close_session()
            m.close_session()
@@ -80,7 +80,7 @@ class NetconfLibrary:
        ``vlan_id`` is deleted in all NEs.
        ``vlan_id`` is deleted in all NEs.
        """
        """
        for ne in self.network:
        for ne in self.network:
            m = connect_with_key(ne.address, ne.mgmt_port, ne.username, "path to private key")
            m = connect_with_key(ne.address, ne.mgmt_port, ne.username, "/home/douomo/.ssh/netconf_key")
            #m = connect_with_credentials(ne.address, ne.mgmt_port, ne.username, ne.password)
            #m = connect_with_credentials(ne.address, ne.mgmt_port, ne.username, ne.password)
            xml = delete_VLAN_xml(ne, vlan_id)
            xml = delete_VLAN_xml(ne, vlan_id)
            m.edit_config(target="candidate", config=xml)
            m.edit_config(target="candidate", config=xml)
@@ -91,7 +91,7 @@ class NetconfLibrary:
    @keyword("the VLAN ${vlan_id} should not be in the configuration")
    @keyword("the VLAN ${vlan_id} should not be in the configuration")
    def the_vlan_xxx_should_not_be_in_the_configuration(self, vlan_id: int) -> None:
    def the_vlan_xxx_should_not_be_in_the_configuration(self, vlan_id: int) -> None:
        for ne in self.network:
        for ne in self.network:
            m = connect_with_key(ne.address, ne.mgmt_port, ne.username, "path to private key")
            m = connect_with_key(ne.address, ne.mgmt_port, ne.username, "/home/douomo/.ssh/netconf_key")
            #m = connect_with_credentials(ne.address, ne.mgmt_port, ne.username, ne.password)
            #m = connect_with_credentials(ne.address, ne.mgmt_port, ne.username, ne.password)
            config = m.get_config(source='running').data_xml
            config = m.get_config(source='running').data_xml
            assert bool(not(vlan_exists(config, vlan_id)))
            assert bool(not(vlan_exists(config, vlan_id)))
@@ -106,7 +106,7 @@ class NetconfLibrary:
        """
        """
        for vlan_id in range(start, stop, step):
        for vlan_id in range(start, stop, step):
            for ne in self.network:
            for ne in self.network:
                m = connect_with_key(ne.address, ne.mgmt_port, ne.username, "path to private key")
                m = connect_with_key(ne.address, ne.mgmt_port, ne.username, "/home/douomo/.ssh/netconf_key")
                #m = connect_with_credentials(ne.address, ne.mgmt_port, ne.username, ne.password)
                #m = connect_with_credentials(ne.address, ne.mgmt_port, ne.username, ne.password)
                xml = create_VLAN_xml(ne,vlan_id)
                xml = create_VLAN_xml(ne,vlan_id)
                m.edit_config(target="candidate", config=xml)
                m.edit_config(target="candidate", config=xml)
+2 −25
Original line number Original line Diff line number Diff line
@@ -20,32 +20,9 @@ def connect_netconf(host, port, username, key_file):
if __name__=="__main__":
if __name__=="__main__":
    mgr = connect_netconf("192.168.13.134", 830, "domenico", "/home/douomo/.ssh/netconf_key")
    mgr = connect_netconf("192.168.13.134", 830, "domenico", "/home/douomo/.ssh/netconf_key")
    
    
    filter = """
    cap = mgr.server_capabilities
    <filter type="subtree" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:ns1="urn:ietf:params:xml:ns:yang:ietf-keystore" xmlns:ns2="urn:ietf:params:xml:ns:yang:ietf-netconf-server" xmlns:ns3="urn:cesnet:libnetconf2-netconf-server">
    print(cap)
        <ns2:netconf-server>
            <ns2:listen>
            <ns2:endpoints>
                <ns2:endpoint>
                <ns2:ssh>
                    <ns2:tcp-server-parameters>
                    <ns2:local-address/>
                    </ns2:tcp-server-parameters>
                </ns2:ssh>
                </ns2:endpoint>
            </ns2:endpoints>
            </ns2:listen>
        </ns2:netconf-server>
    </filter>
    """
    
    running_config = get_running_config(mgr,None)
    tree = ET.fromstring(running_config)
    print(running_config)

    for addr in tree.findall(".//ns1:local-address", namespaces={"ns0" :"urn:ietf:params:xml:ns:netconf:base:1.0","ns1": "urn:ietf:params:xml:ns:yang:ietf-netconf-server"} ):
        print("\naddress=", addr.text)
    
    
    running_config = get_running_config(mgr,None)
    
    
    mgr.close_session() 
    mgr.close_session() 


+7 −7

File changed.

Preview size limit exceeded, changes collapsed.

+79 −850

File changed.

Preview size limit exceeded, changes collapsed.

Loading