Beispiel #1
0
 def parse(self):
     if len(self.config_dict) != 0:
         bgp_conf = self.config_dict
         res = "hostname bgpd\npassword zebra\nrouter bgp "
         res = res + str(bgp_conf.get(
             "as_num")) + "\nbgp router-id " + self.router_id + "\n"
         res += "bgp log-neighbor-changes\n"
         if 'network' in bgp_conf:
             for ele in bgp_conf.get("network"):
                 res = res + "network " + ele + "\n"
         if 'ebgp_neighbors' in bgp_conf:
             for ele in bgp_conf.get("ebgp_neighbors"):
                 res = res + "neighbor " + ele.get(
                     "neighbor_ip") + " remote-as " + str(
                         ele.get("neighbor_as")) + "\n"
         if 'ibgp_neighbors' in bgp_conf:
             for ele in bgp_conf.get("ibgp_neighbors"):
                 res = res + "neighbor " + ele + " remote-as " + str(
                     bgp_conf.get("as_num")
                 ) + "\nneighbor " + ele + " next-hop-self\n"
         if 'others' in bgp_conf:
             for ele in bgp_conf.get("others"):
                 res = res + ele + "\n"
         with open(self.bgp_config_file, 'w') as f:
             f.write(res)
         self.is_configured = True
         logger.info('BGP configuration has been parsed.')
    def parse_and_apply_default_config(cls, router_id):
        """parse the default configuration"""
        res = "hostname ospfd\npassword zebra\nrouter ospf\nospf router-id " + \
              router_id + "\nlog-adjacency-changes\nnetwork 0.0.0.0/0 area 0\n"
        with open(cls.ospf_config_file, 'w') as f:
            f.write(res)
        logger.info('OSPF default configuration has been parsed.')

        if cls.execute_cmd_api.execute('ospfd -d'):
            logger.info('Default OSPF thread has been turned on.')
        else:
            logger.error('Fail to start default OSPF thread.')
 def parse(self):
     if len(self.config_dict) > 0:
         ospf_conf = self.config_dict
         res = "hostname ospfd\npassword zebra\nrouter ospf\nospf router-id " + self.router_id + "\nlog-adjacency-changes\n"
         for ele in ospf_conf.get("networks"):
             res = res + "network " + ele.get("network") + " area " + str(
                 ele.get("area")) + "\n"
         for ele in ospf_conf.get("others"):
             res = res + ele + "\n"
         with open(self.ospf_config_file, 'w') as f:
             f.write(res)
         self.is_configured = True
         logger.info('OSPF configuration has been parsed.')
Beispiel #4
0
    def parse(self):
        if len(self.config_dict) > 0:
            res = "hostname zebra\npassword zebra\n"
            for static_info in self.config_dict:
                if len(static_info) > 0:
                    next_hop_or_src_port = static_info.get('next_hop')
                    for dst_prefix in static_info.get('dst_prefix'):
                        cmd = 'ip route {0} {1}'.format(
                            dst_prefix, next_hop_or_src_port)
                        res = res + cmd + '\n'
                        self.is_configured = True

            with open(self.zebra_config_file, 'a') as f:
                f.write(res)
            logger.info('Static Route configuration has been parsed.')
Beispiel #5
0
 def parse(self):
     if len(self.config_dict) > 0:
         rip_conf = self.config_dict
         res = "hostname zebra\npassword zebra\nrouter rip\n"
         # get rip version (default: version 2)
         rip_version = rip_conf.get("version", 2)
         res += 'version ' + str(rip_version) + '\n'
         # configure the network of rip
         if "networks" in rip_conf:
             for network in rip_conf.get("networks"):
                 res += "network " + network + "\n"
         # configure other rip configuration
         if 'others' in rip_conf:
             for other_config in rip_conf.get('others'):
                 res += other_config + '\n'
         # save the configuration
         with open(self.rip_config_file, 'w') as f:
             f.write(res)
         self.is_configured = True
         logger.info('RIP configuration has been parsed.')
Beispiel #6
0
 def apply(self):
     if self.execute_cmd_api.execute('zebra -d'):
         logger.info('Static Route thread has been turned on.')
     else:
         logger.error('Fail to start Zebra for Static Route thread.')
 def apply(self):
     if self.execute_cmd_api.execute('ospfd -d'):
         logger.info('OSPF thread has been turned on.')
     else:
         logger.error('Fail to start OSPF thread.')
Beispiel #8
0
 def apply(self):
     if self.execute_cmd_api.execute('ripd -d'):
         logger.info('RIP thread has been turned on.')
     else:
         logger.error('Fail to start RIP thread.')