How to use the autonetkit.nidb.ConfigStanza function in autonetkit

To help you get started, we’ve selected a few autonetkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sk2 / autonetkit / autonetkit / compilers / platform / netkit.py View on Github external
for node in sorted(subgraph.l3devices()):
            for interface in node.physical_interfaces():
                broadcast_domain = str(interface.ipv4_subnet).replace("/", ".")
                # netkit lab.conf uses 1 instead of eth1
                numeric_id = interface.numeric_id
                stanza = ConfigStanza(
                    device=naming.network_hostname(node),
                    key=numeric_id,
                    value=broadcast_domain,
                )
                lab_topology.config_items.append(stanza)

        lab_topology.tap_ips = []
        for node in subgraph:
            if node.tap:
                stanza = ConfigStanza(
                    device=naming.network_hostname(node),
                    id=node.tap.id.replace("eth", ""),  # strip ethx -> x
                    ip=node.tap.ip,
                )
                lab_topology.tap_ips.append(stanza)

        lab_topology.tap_ips = sorted(lab_topology.tap_ips, key=lambda x: x.ip)
        lab_topology.config_items = sorted(
            lab_topology.config_items, key=lambda x: x.device)
github sk2 / autonetkit / autonetkit / compilers / platform / cisco.py View on Github external
DmNode.render.template = os.path.join("templates", "nx_os.mako")
            if to_memory:
                DmNode.render.to_memory = True
            else:
                DmNode.render.dst_folder = dst_folder
                DmNode.render.dst_file = "%s.conf" % naming.network_hostname(
                    phy_node)

            # Assign interfaces
            int_ids = self.interface_ids_nxos()
            for interface in DmNode.physical_interfaces():
                if not interface.id:
                    interface.id = self.numeric_to_interface_label_nxos(
                        interface.numeric_id)

            DmNode.supported_features = ConfigStanza(
                mpls_te=False, mpls_oam=False, vrf=False)

            nxos_compiler.compile(DmNode)
            # TODO: make this work other way around

            if use_mgmt_interfaces:
                mgmt_int_id = "mgmt0"
                mgmt_int = DmNode.add_interface(management=True)
                mgmt_int.id = mgmt_int_id

        staros_compiler = StarOsCompiler(self.nidb, self.anm)
        for phy_node in g_phy.routers(host=self.host, syntax='StarOS'):
            DmNode = self.nidb.node(phy_node)
            DmNode.add_stanza("render")
            DmNode.render.template = os.path.join("templates", "staros.mako")
            if to_memory:
github sk2 / autonetkit / autonetkit / compilers / device / cisco.py View on Github external
def vrf(self, node):
        g_vrf = self.anm['vrf']
        vrf_node = self.anm['vrf'].node(node)
        node.add_stanza("vrf")
        node.add_stanza("mpls")
        node.vrf.vrfs = []
        if vrf_node and vrf_node.vrf_role is 'PE':

            # TODO: check if mpls ldp already set elsewhere

            for vrf in vrf_node.node_vrf_names:
                route_target = g_vrf.data.route_targets[node.asn][vrf]
                rd_index = vrf_node.rd_indices[vrf]
                rd = '%s:%s' % (node.asn, rd_index)

                stanza = ConfigStanza(
                    vrf=vrf, rd=rd, route_target=route_target)
                node.vrf.vrfs.append(stanza)

            for interface in node.interfaces:
                vrf_int = self.anm['vrf'].interface(interface)
                if vrf_int.vrf_name:
                    # mark interface as being part of vrf
                    interface.vrf = vrf_int.vrf_name
                    if interface.physical:
                        interface.description += ' vrf %s' \
                            % vrf_int.vrf_name

        if vrf_node and vrf_node.vrf_role in ('P', 'PE'):

            # Add PE -> P, PE -> PE interfaces to MPLS LDP
github sk2 / autonetkit / autonetkit / compilers / device / cisco.py View on Github external
if interface.exclude_igp:
                continue  # don't configure IGP for this interface

            eigrp_int = g_eigrp.interface(interface)
            if eigrp_int and eigrp_int.is_bound:
                # TODO: for here and below use stanza directly
                data = {'id': interface.id, 'passive': False}
                stanza = ConfigStanza(**data)
                if node.eigrp.use_ipv4:
                    ipv4_interfaces.append(stanza)
                if node.eigrp.use_ipv6:
                    ipv6_interfaces.append(stanza)

        loopback_zero = node.loopback_zero
        data = {'id': node.loopback_zero.id, 'passive': True}
        stanza = ConfigStanza(**data)
        if node.eigrp.use_ipv4:
            ipv4_interfaces.append(stanza)
        if node.eigrp.use_ipv6:
            ipv6_interfaces.append(stanza)

        node.eigrp.ipv4_interfaces = ipv4_interfaces
        node.eigrp.ipv6_interfaces = ipv6_interfaces
github sk2 / autonetkit / autonetkit / compilers / device / cisco.py View on Github external
def mpls_te(self, node):
        super(IosXrCompiler, self).mpls_te(node)

        g_mpls_te = self.anm['mpls_te']
        if node not in g_mpls_te:
            return   # no mpls te configured

        rsvp_interfaces = []
        mpls_te_interfaces = []
        mpls_te_node = g_mpls_te.node(node)

        for interface in mpls_te_node.physical_interfaces():
            nidb_interface = self.nidb.interface(interface)
            stanza = ConfigStanza(id=nidb_interface.id,
                                  bandwidth_percent=100)
            rsvp_interfaces.append(stanza)

            mpls_te_interfaces.append(nidb_interface.id)

        node.add_stanza("rsvp")
        node.rsvp.interfaces = rsvp_interfaces
        node.mpls.te_interfaces = mpls_te_interfaces
github datacenter / ignite-DEPRECATED / ank / autonetkit / autonetkit / compilers / platform / cisco.py View on Github external
DmNode.add_stanza("ntp")
                                DmNode.ntp.enabled = node_id['configs']['ntp'].get('enabled')
                                DmNode.ntp.server_ip = node_id['configs']['ntp'].get('server_ip')
                            if  node_id['configs'].has_key('snmp'):
                                DmNode.add_stanza('snmp')
                                DmNode.snmp.enabled = node_id['configs']['snmp'].get('enabled')
                                DmNode.snmp.server=[]
                                for server in node_id['configs']['snmp']['servers']:
                                   snmp_server_stanza =  ConfigStanza(ip = server['ip'],
                                                                      version = server['version'],
                                                                      udp_port=server['udp_port'],
                                                                      community=server['community'])
                                   DmNode.snmp.server.append(snmp_server_stanza)
                                DmNode.snmp.users = []
                                for user_prof in node_id['configs']['snmp']['users']:
                                    snmp_user_stanza = ConfigStanza(user=user_prof['user'],
                                                                auth=user_prof['auth'],
                                                                pwd=user_prof['pwd'],
                                                                priv_passphrase=user_prof['priv_passphrase'],
                                                                engine_id=user_prof['engineID'])
                                    DmNode.snmp.users.append(snmp_user_stanza)
                                DmNode.snmp.features=[]
                                for configs in node_id['configs']['snmp']['features']:
                                    snmp_feature_stanza = ConfigStanza(id=configs['id'], enabled=configs['enabled'])
                                    DmNode.snmp.features.append(snmp_feature_stanza)

                        break
            """for node_id in node_profiles:
                if DmNode._graph.node['profile'] == node_id['id']:
                    DmNode.ntp.enabled = node_profiles[0]['configs']['ntp'].get('enabled')
                    DmNode.ntp.server_ip = node_profiles[0]['configs']['ntp'].get('server_ip')
                    """
github sk2 / autonetkit / autonetkit / compilers / device / cisco.py View on Github external
def gre(self, node):
        node.gre_tunnels = []
        if not self.anm.has_overlay('gre_tunnel'):
            return

        g_gre_tunnel = self.anm['gre_tunnel']
        if node not in g_gre_tunnel:
            return   # no gre tunnel for node

        gre_node = g_gre_tunnel.node(node)
        neighbors = gre_node.neighbors()
        for index, neigh in enumerate(neighbors, start=1):
            stanza = ConfigStanza(id=index, endpoint=neigh)

            # TODO: try/except here
            # TODO: Explain logic here
            src_int = g_gre_tunnel.edge(node, neigh).src_int
            tunnel_source = node.interface(src_int).id
            stanza.source = tunnel_source
            stanza.destination = "0.0.0.0"  # placeholder for user to replace

            if neigh.tunnel_enabled_ipv4:
                ip_address = neigh.tunnel_ipv4_address
                cidr = neigh.tunnel_ipv4_cidr
                stanza.ipv4_address = ip_address
                stanza.ipv4_subnet = cidr
                stanza.use_ipv4 = True

            if neigh.tunnel_enabled_ipv6:
github datacenter / ignite-DEPRECATED / ank / autonetkit / autonetkit / compilers / device / cisco.py View on Github external
def gre(self, node):
        node.gre_tunnels = []
        if not self.anm.has_overlay('gre_tunnel'):
            return

        g_gre_tunnel = self.anm['gre_tunnel']
        if node not in g_gre_tunnel:
            return   # no gre tunnel for node

        gre_node = g_gre_tunnel.node(node)
        neighbors = gre_node.neighbors()
        for index, neigh in enumerate(neighbors, start=1):
            stanza = ConfigStanza(id=index, endpoint=neigh)

            # TODO: try/except here
            # TODO: Explain logic here
            src_int = g_gre_tunnel.edge(node, neigh).src_int
            tunnel_source = node.interface(src_int).id
            stanza.source = tunnel_source
            stanza.destination = "0.0.0.0"  # placeholder for user to replace

            if neigh.tunnel_enabled_ipv4:
                ip_address = neigh.tunnel_ipv4_address
                cidr = neigh.tunnel_ipv4_cidr
                stanza.ipv4_address = ip_address
                stanza.ipv4_subnet = cidr
                stanza.use_ipv4 = True

            if neigh.tunnel_enabled_ipv6: