コード例 #1
0
ファイル: internet.py プロジェクト: coaj/autonetkit
    def compile(self):        
        """Compile into device configuration files.

          Args:
             None

          Returns:
             None

          Example usage:

          >>> inet = ank.internet.Internet()
          >>> inet.compile()

          >>> inet = ank.internet.Internet()
          >>> inet.compile()

          """

        #TODO: fix import order problem with doctests:
        #No handlers could be found for logger "ANK"
        LOG.info("Compiling")

        # Sanity check
        if self.network.graph.number_of_nodes() == 0:
            LOG.warn("Cannot compile empty network")
            return

        # Clean up old archives
        ank.tidy_archives()
      
        #TODO: 
        #config.get_plugin("Inv Cap").run(self.network)   
        #ank.inv_cap_weights(self.network)
        #config.get_plugin("Test").run()
        ank.initialise_bgp(self.network)
        
        # Ensure nodes have a type set
        self.network.update_node_type(default_type="netkit_router")
        ank.allocate_dns_servers(self.network)

        # Allocations  
        ank.allocate_subnets(self.network, IPNetwork("10.0.0.0/8")) 
        ank.alloc_interfaces(self.network)

        ank.alloc_tap_hosts(self.network, self.tapsn)

        if self.policy_file:
            LOG.info("Applying BGP policy from %s" % self.policy_file)
            pol_parser = ank.BgpPolicyParser(self.network)
            pol_parser.apply_policy_file(self.policy_file)
	
	if self.rpki_file:
	    LOG.info("Applying RPKI structure from %s" % self.rpki_file)
	    rpki_parser = ank.RpkiSetsParser(self.network)
	    rpki_parser.apply_rpki_file(self.rpki_file)
            
        if self.will_deploy and not self.compile_targets['netkit']:
            auto_compile = any( data.get("active") 
                    for data in config.settings['Netkit Hosts'].values())
            if auto_compile:
                LOG.info("Active Netkit deployment target, automatically compiling")
                self.compile_targets['netkit'] = True
        if self.compile_targets['netkit']:
            nk_comp = ank.NetkitCompiler(self.network, self.services)
            nk_comp.initialise()     
            nk_comp.configure()

        auto_compile = any( data.get("active") 
                for data in config.settings['Dynagen Hosts'].values())
        if auto_compile:
                LOG.info("Active Dynagen deployment target, automatically compiling")
                self.compile_targets['dynagen'] = True
        if self.compile_targets['dynagen']:
            dynagen_comp = ank.dynagenCompiler(self.network, services = self.services, 
                    igp = self.igp,
                    image = config.settings['Dynagen']['image'],
                    hypervisor_server = config.settings['Dynagen']['Hypervisor']['server'],
                    hypervisor_port = config.settings['Dynagen']['Hypervisor']['port'],
                    )
            dynagen_comp.initialise()     
            dynagen_comp.configure()

        if self.compile_targets['junosphere']:
            junos_comp = ank.JunosCompiler(self.network, self.services, self.igp, target="junosphere")
            junos_comp.initialise()
            junos_comp.configure()

        if self.compile_targets['junosphere_olive']:
            LOG.warn("Junosphere Olive not currently supported")
            #junos_comp = ank.JunosCompiler(self.network, self.services, self.igp, target="junosphere_olive")
            #junos_comp.initialise()
            #junos_comp.configure()

        if self.will_deploy and not self.compile_targets['olive']:
            auto_compile = any( data.get("active") 
                    for data in config.settings['Olive Hosts'].values())
            if auto_compile:
                self.compile_targets['olive'] = True
                LOG.info("Active Olive deployment target, automatically compiling")
        if self.compile_targets['olive']:
            olive_qemu_patched = self.compile_targets['olive_qemu_patched']
            junos_comp = ank.JunosCompiler(self.network, self.services, self.igp, target="olive",
                    olive_qemu_patched = olive_qemu_patched)
            junos_comp.initialise()
            junos_comp.configure()

        if self.will_deploy and not self.compile_targets['cbgp']:
            auto_compile = any( data.get("active") 
                    for data in config.settings['cBGP Hosts'].values())
            if auto_compile:
                self.compile_targets['cbgp'] = True
                LOG.info("Active cBGP deployment target, automatically compiling")
        if self.compile_targets['cbgp']:
            cbgp_comp = ank.CbgpCompiler(self.network, self.services)
            cbgp_comp.configure()