当前位置: 首页>>代码示例>>Python>>正文


Python AutoNetkit类代码示例

本文整理汇总了Python中AutoNetkit的典型用法代码示例。如果您正苦于以下问题:Python AutoNetkit类的具体用法?Python AutoNetkit怎么用?Python AutoNetkit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AutoNetkit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load

    def load(self, filename):   
        """Loads the network description from a graph file.
        Note this is done automatically if a filename is given to
        the Internet constructor.

        Args:
           filename:    The file to load from

        Returns:
           None

        Example usage:

        >>> inet = ank.internet.Internet()
        >>> inet.load("simple")
        >>> sorted(inet.network.graph.nodes())
        [RouterB.AS1, RouterA.AS1, RouterD.AS2, RouterC.AS1, RouterA.AS2, RouterA.AS3, RouterB.AS2, RouterC.AS2]

        >>> inet = ank.internet.Internet()
        >>> inet.load("singleas")
        >>> sorted(inet.network.graph.nodes())
        [1a.AS1, 1b.AS1, 1d.AS1, 1c.AS1]

        >>> inet = ank.internet.Internet()
        >>> inet.load("multias")
        >>> sorted(inet.network.graph.nodes())
        [1b.AS1, 1a.AS1, 2d.AS2, 1c.AS1, 2a.AS2, 3a.AS3, 2b.AS2, 2c.AS2]

        """
        LOG.info("Loading")
        ext = os.path.splitext(filename)[1]
        if ext == "":
            #TODO: use try/except block here
            self.network.graph = ank.load_example(filename)

#TODO: allow url to be entered, eg from zoo, if so then download the file and proceed on as normal

        elif ext == ".gml":
            # GML file from Topology Zoo
            ank.load_zoo(self.network, filename)
        elif ext == ".graphml":
            self.network.graph = ank.load_graphml(filename)
        elif ext == ".pickle":
            LOG.warn("AutoNetkit no longer supports pickle file format, please use GraphML")
        elif ext == ".yaml":
            # Legacy ANK file format
            LOG.warn("AutoNetkit no longer supports YAML file format, please use GraphML")
        else:
            LOG.warn("AutoNetkit does not support file format %s" % ext)

        #TODO: check that loaded network has at least one node, if not throw exception
        self.network.instantiate_nodes()
开发者ID:coaj,项目名称:autonetkit,代码行数:52,代码来源:internet.py

示例2: configure_junos

    def configure_junos(self):
        """ Configures Junos"""
        LOG.info("Configuring Junos: %s" % self.target)
        junos_template = lookup.get_template("junos/junos.mako")
        ank_version = pkg_resources.get_distribution("AutoNetkit").version
        date = time.strftime("%Y-%m-%d %H:%M", time.localtime())

        physical_graph = self.network.graph
        igp_graph = ank.igp_graph(self.network)
        ibgp_graph = ank.get_ibgp_graph(self.network)
        ebgp_graph = ank.get_ebgp_graph(self.network)

        #TODO: correct this router type selector
        for router in self.network.routers():
            #check interfaces feasible
            if self.network.graph.in_degree(router) > self.interface_limit:
                LOG.warn("%s exceeds interface count: %s (max %s)" % (self.network.label(router),
                    self.network.graph.in_degree(router), self.interface_limit))
            asn = self.network.asn(router)
            network_list = []
            lo_ip = self.network.lo_ip(router)

            interfaces,static_routes = self.configure_interfaces(router)
            igp_interfaces = self.configure_igp(router, igp_graph,ebgp_graph)
            (bgp_groups, policy_options) = self.configure_bgp(router, physical_graph, ibgp_graph, ebgp_graph)

            # advertise AS subnet
            adv_subnet = self.network.ip_as_allocs[asn]
            if not adv_subnet in network_list:
                network_list.append(adv_subnet)

            juniper_filename = router_conf_path(self.network, router)
            with open( juniper_filename, 'wb') as f_jun:
                f_jun.write( junos_template.render(
                    hostname = router.rtr_folder_name,
                    username = 'autonetkit',
                    interfaces=interfaces,
		    static_routes=static_routes,
                    igp_interfaces=igp_interfaces,
                    igp_protocol = self.igp,
                    asn = asn,
                    lo_ip=lo_ip,
                    router_id = lo_ip.ip,
                    network_list = network_list,
                    bgp_groups = bgp_groups,
                    policy_options = policy_options,
                    ank_version = ank_version,
                    date = date,
                    ))
开发者ID:iainwp,项目名称:ank_le,代码行数:49,代码来源:junoscompiler.py

示例3: configure_ios

    def configure_ios(self):
        """ Configures IOS"""
        LOG.info("Configuring IOS")
        ios_template = lookup.get_template("cisco/ios.mako")
        ank_version = pkg_resources.get_distribution("AutoNetkit").version
        date = time.strftime("%Y-%m-%d %H:%M", time.localtime())

        physical_graph = self.network.graph
        igp_graph = ank.igp_graph(self.network)
        ibgp_graph = ank.get_ibgp_graph(self.network)
        ebgp_graph = ank.get_ebgp_graph(self.network)

        for router in self.network.routers():
            #check interfaces feasible
#TODO: make in_degree a property eg link_count
            asn = self.network.asn(router)
            network_list = []
            lo_ip = self.network.lo_ip(router)

            interfaces = self.configure_interfaces(router)
            igp_interfaces = self.configure_igp(router, igp_graph,ebgp_graph)
            (bgp_groups, policy_options) = self.configure_bgp(router, physical_graph, ibgp_graph, ebgp_graph)

            # advertise AS subnet
            adv_subnet = self.network.ip_as_allocs[asn]
            if not adv_subnet in network_list:
                network_list.append(adv_subnet)

            juniper_filename = router_conf_path(self.network, router)
            with open( juniper_filename, 'wb') as f_jun:
                f_jun.write( ios_template.render(
                    hostname = router.rtr_folder_name,
                    username = 'autonetkit',
                    interfaces=interfaces,
                    igp_interfaces=igp_interfaces,
                    igp_protocol = self.igp,
# explicit protocol
                    use_isis = self.igp == 'isis',
                    asn = asn,
                    lo_ip=lo_ip,
                    #TODO: make router have property "identifier" which maps to lo_ip
                    router_id = lo_ip.ip,
                    network_list = network_list,
                    bgp_groups = bgp_groups,
                    policy_options = policy_options,
                    ank_version = ank_version,
                    date = date,
                    ))
开发者ID:coaj,项目名称:autonetkit,代码行数:48,代码来源:dynagencompiler.py

示例4: load_example

def load_example(filename):
    """
    Load example network
    """
    # No extension, see if filename is an included example Topology
    topology_dir = resource_filename("AutoNetkit", os.path.join("lib", "examples", "topologies"))
    test_filename = os.path.join(topology_dir, "%s.graphml" % filename)
    if os.path.isfile(test_filename):
        LOG.info("Loading example topology %s " % filename)
        return ank.load_graphml(test_filename)
    else:
        example_files = glob.glob(topology_dir + os.sep + "*.graphml")
        # Remove path
        example_files = (os.path.split(filename)[1] for filename in example_files)
        # Remove extension
        example_files = (os.path.splitext(filename)[0] for filename in example_files)
        LOG.warn("Unable to find example topology %s" % filename)
        LOG.info("Valid example topologies are: " + ", ".join(example_files))
开发者ID:ntwrkguru,项目名称:autonetkit,代码行数:18,代码来源:example_topologies.py

示例5: __init__

    def __init__(self, network, services, igp="ospf", target=None, olive_qemu_patched=False):
        self.network = network
        self.services = services
        self.igp = igp
        self.target = target
        self.olive_qemu_patched = olive_qemu_patched
        self.interface_limit = 0

#TODO: tidy up platform: Olive/Junosphere between the vmm and the device configs

        self.junosphere = False
        self.junosphere_olive = False
        if target in ['junosphere', 'junosphere_olive']:
            self.junosphere = True
            self.int_id_em = ank.naming.junos_int_id_em
            self.junosphere_platform = config.settings['Junosphere']['platform']
            if self.junosphere_platform == "Olive":
                self.junosphere_olive = True
                self.target = "junosphere_olive"
                self.olive_qemu_patched = config.settings['Junosphere']['olive_qemu_patched']
                self.int_id_em = ank.interface_id(self.target, olive_qemu_patched=olive_qemu_patched)
            else:
                self.interface_limit = 256 # TODO: check upper bound for VJX

        self.int_id = ank.interface_id(self.target, olive_qemu_patched=olive_qemu_patched)

        self.olive = False
        if self.target in ['olive', 'junosphere_olive']:
            self.olive = True

        if self.olive:
            self.interface_limit = 7
        if self.olive_qemu_patched:
            self.interface_limit = 8 # Patch allows 8 interfaces
开发者ID:iainwp,项目名称:ank_le,代码行数:34,代码来源:junoscompiler.py

示例6: configure_interfaces

    def configure_interfaces(self, device):
        LOG.debug("Configuring interfaces for %s" % self.network.fqdn(device))
        """Interface configuration"""
        lo_ip = self.network.lo_ip(device)
        interfaces = []

        interfaces.append({
            'id':          'lo0',
            'ip':           str(lo_ip.ip),
            'netmask':      str(lo_ip.netmask),
            'prefixlen':    str(lo_ip.prefixlen),
            'net_ent_title': ank.ip_to_net_ent_title(lo_ip.ip),
            'description': 'Loopback',
        })

        for src, dst, data in self.network.graph.edges(device, data=True):
            subnet = data['sn']
            int_id = self.int_id(data['id'])
            description = 'Interface %s -> %s' % (
                    ank.fqdn(self.network, src), 
                    ank.fqdn(self.network, dst))

# Interface information for router config
            interfaces.append({
                'id':          int_id,
                'ip':           str(data['ip']),
                'prefixlen':    str(subnet.prefixlen),
                'broadcast':    str(subnet.broadcast),
                'description':  description,
            })

        return interfaces
开发者ID:gitgnarg,项目名称:autonetkit,代码行数:32,代码来源:junoscompiler.py

示例7: dump

    def dump(self):
        """Dumps overlay graphs to file 

        .. note::
            
            Doesn't currently support saving graphs - NetworkX cannot save nodes/edges with dictionary attributes

        """
        with open( os.path.join(config.log_dir, "physical.txt"), 'w') as f_pol_dump:
            f_pol_dump.write(ank.debug_nodes(self.network.graph))
            f_pol_dump.write(ank.debug_edges(self.network.graph))
        #nx.write_graphml(self.network.graph, os.path.join(config.log_dir, "physical.graphml"))

        with open( os.path.join(config.log_dir, "bgp.txt"), 'w') as f_pol_dump:
            f_pol_dump.write(ank.debug_nodes(self.network.g_session))
            f_pol_dump.write(ank.debug_edges(self.network.g_session))
        #nx.write_graphml(self.network.g_session, os.path.join(config.log_dir, "bgp.graphml"))

        with open( os.path.join(config.log_dir, "dns.txt"), 'w') as f_pol_dump:
            f_pol_dump.write(ank.debug_nodes(self.network.g_dns))
            f_pol_dump.write(ank.debug_edges(self.network.g_session))
        #nx.write_graphml(self.network.g_session, os.path.join(config.log_dir, "dns.graphml"))

        with open( os.path.join(config.log_dir, "dns_auth.txt"), 'w') as f_pol_dump:
            f_pol_dump.write(ank.debug_nodes(self.network.g_dns_auth))
            f_pol_dump.write(ank.debug_edges(self.network.g_dns_auth))
开发者ID:coaj,项目名称:autonetkit,代码行数:26,代码来源:internet.py

示例8: configure_igp

    def configure_igp(self, router, igp_graph, ebgp_graph):
        """igp configuration"""
        LOG.debug("Configuring IGP for %s" % self.network.label(router))
#TODO: get area from router
        default_area = 0
        igp_interfaces = []
        if igp_graph.degree(router) > 0:
            # Only start IGP process if IGP links
#TODO: make loopback a network mask so don't have to do "0.0.0.0"
            igp_interfaces.append({ 'id': 'lo0', 'wildcard': router.lo_ip.hostmask,
                'passive': False,
                'network': router.lo_ip.network,
                'area': default_area, 'weight': self.default_weight,
                })
            for src, dst, data in igp_graph.edges(router, data=True):
                int_id = self.int_id(data['id'])
                subnet = self.network.graph[src][dst]['sn']
                description = 'Interface %s -> %s' % (
                        ank.fqdn(self.network, src), 
                        ank.fqdn(self.network, dst))
                igp_interfaces.append({
                    'id':       int_id,
                    'weight':   data.get('weight', self.default_weight),
                    'area':   data.get('area', default_area),
                    'network': str(subnet.network),
                    'description': description,
                    'wildcard':      str(subnet.hostmask),
                    })

# Need to add eBGP edges as passive interfaces
            for src, dst in ebgp_graph.edges(router):
# Get relevant edges from ebgp_graph, and edge data from physical graph
                data = self.network.graph[src][dst]
                int_id = self.int_id(data['id'])
                subnet = self.network.graph[src][dst]['sn']
                description = 'Interface %s -> %s' % (
                    ank.fqdn(self.network, src), 
                    ank.fqdn(self.network, dst))
                igp_interfaces.append({
                    'id':       int_id,
                    'weight':   data.get('weight', self.default_weight),
                    'area':   data.get('area', default_area),
                    'description': description,
                    'passive': True,
                    'network': str(subnet.network),
                    'wildcard':      str(subnet.hostmask),
                    })

        return igp_interfaces
开发者ID:coaj,项目名称:autonetkit,代码行数:49,代码来源:dynagencompiler.py

示例9: __init__

 def __init__(self, network, services, zebra_password="1234"):
     self.network = network
     self.services = services
     self.zebra_password = zebra_password
     self.interface_id = ank.interface_id('netkit')
     self.tap_interface_id = ank.tap_interface_id
     self.lo_interface = lo_interface
     self.default_weight = 1
开发者ID:medim,项目名称:autonetkit,代码行数:8,代码来源:netkitcompiler.py

示例10: dump_identifiers

def dump_identifiers(network, filename):
    with open( filename, 'w') as f_dump:
# writes out lo_ip for routers, and identifying IP for servers
        for my_as in ank.get_as_graphs(network):
            for router in sorted(network.routers(my_as.asn), key = lambda x: x.fqdn):
                f_dump.write( "%s\t%s\n" % (router, router.lo_ip.ip))
            for server in sorted(network.servers(my_as.asn), key = lambda x: x.fqdn):
                    f_dump.write( "%s\t%s\n" % (server, server_ip(server)))
            f_dump.write("\n")
开发者ID:iainwp,项目名称:ank_le,代码行数:9,代码来源:naming.py

示例11: configure_interfaces

    def configure_interfaces(self, device):
        LOG.debug("Configuring interfaces for %s" % self.network.fqdn(device))
        """Interface configuration"""
        lo_ip = self.network.lo_ip(device)
        interfaces = []
	static_routes = []
        interfaces.append({
            'id':          'lo0',
            'ip':           str(lo_ip.ip),
            'netmask':      str(lo_ip.netmask),
            'prefixlen':    str(lo_ip.prefixlen),
            'net_ent_title': ank.ip_to_net_ent_title(lo_ip.ip),
            'description': 'Loopback',
        })

        for src, dst, data in self.network.graph.edges(device, data=True):
	    neighbor = ank.fqdn(self.network, dst)
            subnet = data['sn']
            int_id = self.int_id(data['id'])
            description = 'Interface %s -> %s' % (
                    ank.fqdn(self.network, src), 
                    ank.fqdn(self.network, dst))

# Interface information for router config
            interfaces.append({
                'id':          int_id,
                'ip':           str(data['ip']),
                'prefixlen':    str(subnet.prefixlen),
		'netmask':	str(subnet.netmask),
                'broadcast':    str(subnet.broadcast),
                'description':  description,
            })
#static routes for the dummy nodes
	    for virtual in sorted(self.network.virtual_nodes(), key = lambda x: x.fqdn):
		virtual_hostname = virtual.hostname
		if neighbor == virtual_hostname:
		    subnet = data['sn']
		    static_routes.append({
		        'network':	str(subnet.network),
			'prefixlen':	str(subnet.prefixlen),
			'ip':		str(data['ip']),
		    })

        return interfaces,static_routes
开发者ID:coaj,项目名称:autonetkit,代码行数:44,代码来源:junoscompiler.py

示例12: configure_igp

    def configure_igp(self, router, igp_graph, ebgp_graph):
        """igp configuration"""
        LOG.debug("Configuring IGP for %s" % self.network.label(router))
        default_weight = 1
        igp_interfaces = []
        if igp_graph.degree(router) > 0:
            # Only start IGP process if IGP links
            igp_interfaces.append({ 'id': 'lo0', 'passive': True})
            for src, dst, data in igp_graph.edges(router, data=True):
                int_id = ank.junos_logical_int_id(self.int_id(data['id']))
                description = 'Interface %s -> %s' % (
                    ank.fqdn(self.network, src), 
                    ank.fqdn(self.network, dst))
                igp_interfaces.append({
                    'id':       int_id,
                    'weight':   data.get('weight', default_weight),
                    'description': description,
                    })

# Need to add eBGP edges as passive interfaces
            for src, dst in ebgp_graph.edges(router):
# Get relevant edges from ebgp_graph, and edge data from physical graph
                data = self.network.graph[src][dst]
                int_id = ank.junos_logical_int_id(self.int_id(data['id']))
                description = 'Interface %s -> %s' % (
                    ank.fqdn(self.network, src), 
                    ank.fqdn(self.network, dst))
                igp_interfaces.append({
                    'id':       int_id,
                    'weight':   data.get('weight', default_weight),
                    'description': description,
                    'passive': True,
                    })

        return igp_interfaces
开发者ID:iainwp,项目名称:ank_le,代码行数:35,代码来源:junoscompiler.py

示例13: configure_interfaces

    def configure_interfaces(self, device):
        LOG.debug("Configuring interfaces for %s" % self.network.fqdn(device))
        """Interface configuration"""
        lo_ip = self.network.lo_ip(device)
        interfaces = []

        interfaces.append({
            'id':          'lo0',
            'ip':           lo_ip.ip,
            'netmask':      lo_ip.netmask,
            'wildcard':      lo_ip.hostmask,
            'prefixlen':    lo_ip.prefixlen,
            'network':       lo_ip.network,
            'description': 'Loopback',
        })

        for src, dst, data in self.network.graph.edges(device, data=True):
            subnet = data['sn']
            int_id = self.interface_id(data['id'])
            description = 'Interface %s -> %s' % (
                    ank.fqdn(self.network, src), 
                    ank.fqdn(self.network, dst))

# Interface information for router config
            interfaces.append({
                'id':          int_id,
                'ip':           data['ip'],
                'network':       subnet.network,
                'prefixlen':    subnet.prefixlen,
                'netmask':    subnet.netmask,
                'wildcard':      subnet.hostmask,
                'broadcast':    subnet.broadcast,
                'description':  description,
                'weight':   data.get('weight', self.default_weight),
            })

        return interfaces
开发者ID:medim,项目名称:autonetkit,代码行数:37,代码来源:netkitcompiler.py

示例14: plot

def plot(network, show=False, save=True):
    """ Plot the network """
    try:
        import matplotlib.pyplot as plt
    except ImportError:
        LOG.warn("Matplotlib not found, not plotting using Matplotlib")
        return
    try:
        import numpy
    except ImportError:
        LOG.warn("Matplotlib plotting requires numpy for graph layout")
        return

    plot_dir = config.plot_dir
    if not os.path.isdir(plot_dir):
        os.mkdir(plot_dir)

    graph = network.graph
    pos=nx.spring_layout(graph)

# Different node color for each AS. Use heatmap based on ASN

    plot_graph(graph, title="Network", pos=pos, show=show, save=save,
            node_color=cmap_index(network, graph))

    graph = ank.get_ebgp_graph(network)
    labels = dict( (n, network.label(n)) for n in graph)
    plot_graph(graph, title="eBGP", pos=pos, labels=labels, show=show, save=save)

    graph = ank.get_ibgp_graph(network)
    labels = dict( (n, network.label(n)) for n in graph)
    plot_graph(graph, title="iBGP", pos=pos, labels=labels, show=show, save=save)

    graph = ank.get_dns_graph(network)
    labels = dict( (n, network.label(n)) for n in graph)
    plot_graph(graph, title="DNS", pos=pos, labels=labels, show=show, save=save)
开发者ID:coaj,项目名称:autonetkit,代码行数:36,代码来源:plot.py

示例15: inv_cap_weights

def inv_cap_weights(network):
    """Updates link weights based on inverse of link speed."""
    #TODO: rewrite this to be cleaner iteration and setting
    for graph in ank.get_as_graphs(network):
        for (src, dst, data) in graph.edges_iter(data=True):    
            # only update if non default weight       
            if 'speed' in data and 'weight' in data and data['weight'] == 1: 
                # assume largest link is 10gb 
                #TODO: use Cisco guidelines for this
                scale_speed = 100000      
                speed = float(data['speed'])
                weight = int((1/speed)*scale_speed)    
                weight = max(weight, 1)
                if weight is 0:
                    weight = 1
                    graph[src][dst]['weight'] = weight
                    network.set_edge_property(src, dst, 'weight', weight)
    return
开发者ID:ntwrkguru,项目名称:autonetkit,代码行数:18,代码来源:inv_cap.py


注:本文中的AutoNetkit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。