def database(self) -> None: """Write route attributes to database""" try: DataBaseOps.db_update_nexus(vdc=self.vdc, 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
def database(self): # Unpack routing dictionary for vdc, values_vdc in self._vdcroutes.items(): for i in values_vdc: for vrf, route_contents in i.items(): for prefix, val_prefix in route_contents.items(): routes_attributes = [] for attributes in val_prefix: for attribute, value in attributes.items(): # Save routing attributes to list in preperation for DB write routes_attributes.append(value) # Get the length of the list. Each will be a fixed length. Combine next hops, interfaces, # metrics and tags. This is so we dont have to modify DB rows/columns. if len(routes_attributes) == 6: DataBaseOps.db_update_nexus(vdc, vrf, prefix, routes_attributes[0], routes_attributes[1], routes_attributes[3], routes_attributes[4], routes_attributes[5], routes_attributes[2]) if len(routes_attributes) == 9: next_hops = routes_attributes[3] + ", " + routes_attributes[6] route_metrics = routes_attributes[5] + ", " + routes_attributes[8] interfaces = routes_attributes[4] + ", " + routes_attributes[7] DataBaseOps.db_update_nexus(vdc, vrf, prefix, routes_attributes[0], routes_attributes[1], next_hops, interfaces, route_metrics, routes_attributes[2]) if len(routes_attributes) == 12: next_hops = routes_attributes[3] + ", " + routes_attributes[6] + routes_attributes[9] route_metrics = routes_attributes[5] + ", " + routes_attributes[8] + routes_attributes[11] interfaces = routes_attributes[4] + ", " + routes_attributes[7] + routes_attributes[10] DataBaseOps.db_update_nexus(vdc, vrf, prefix, routes_attributes[0],routes_attributes[1], next_hops, interfaces, route_metrics, routes_attributes[2])