예제 #1
0
 def database(self):
     """Write route entry to database"""
     try:
         DatabaseOps.db_update_asa(vrf=self.vrf,
                                   prefix=self.prefix,
                                   protocol=self.protocol,
                                   admin_distance=self.admin_dis[0],
                                   metric=", ".join(self.metric),
                                   nexthops=", ".join(self.next_hop),
                                   interfaces=", ".join(self.interface),
                                   tag=None,
                                   age=", ".join(self.route_age))
     except IndexError:
         pass
예제 #2
0
    def database(self):

        for vrf, values_vrf in self._routing.items():
            for prefix, val_prefix in values_vrf.items():
                routes_attributes = []
                for attributes in val_prefix:
                    for attribute, value in attributes.items():
                        routes_attributes.append(value)

                # Get the length of the route_attributes list. Each will be a fixed length. Combine next hops,
                # interface, metrics and tags. This is so we dont have to modify DB rows/columns.

                if len(routes_attributes) == 5:

                    # Check for tag in route entry, no tag assign None to variable
                    try:
                        tag = attributes[8]
                    except KeyError:
                        tag = None

                    try:
                        DatabaseOps.db_update_asa(vrf, prefix, routes_attributes[0], routes_attributes[1],
                                                  routes_attributes[2], routes_attributes[3], routes_attributes[4],
                                                  tag)
                    except (IndexError, TypeError) as error:
                        print(error)
                        pass

                if len(routes_attributes) == 8:

                    # Check for tag in route entry, no tag assign None to variable
                    try:
                        tag = attributes[8]
                    except KeyError:
                        tag = None

                    try:
                        next_hops = routes_attributes[2] + ", " + routes_attributes[5]
                        route_metrics = routes_attributes[4] + ", " + routes_attributes[7]
                        interfaces = routes_attributes[3] + ", " + routes_attributes[6]
                        DatabaseOps.db_update_asa(vrf, prefix, routes_attributes[0], routes_attributes[1],
                                                  next_hops, interfaces, route_metrics, tag)
                    except (IndexError, TypeError, NameError) as error:
                        pass