예제 #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 __init__(self, host=None, username=None, password=None, **enable):

        """Initialize instance attributes. Credentials
        _host
        _username
        _password
        routes = maintains parse route data in dictionary format
        prefix = maintains current prefix in the loop
        _vdcroutes = parent dictionary, routes are value
        initialize_class_methods() = initializes class methods
        """

        self._host = host
        self._username = username
        self._password = password
        self.netmiko_connection = None
        self.routes = collections.defaultdict(list)
        self._vdcroutes = collections.defaultdict(list)
        self.cdp_lldp_neighbors = {}
        self.prefix = None

        try:
            self.enable = enable["enable"]
        except KeyError:
            self.enable = None

        self.create_db = DataBaseOps.RoutingDatabase()
        self.initialize_class_methods()  # Initiate class methods
        self.database()
예제 #3
0
    def __init__(self, host=None, username=None, password=None, **enable):

        """Initialize instance attributes. Credentials
        _host
        _username
        _password
        routes = maintains nested parse route data,VRF, route particulars
        _routing = Parent to routes dictionary, maintans VDC Key
        prefix = maintains current prefix in the loop
        protocol = maintains routing protocol until the next line provides the next protocol
        initialize_class_methods() = initializes class methods
        """

        self._host = host
        self._username = username
        self._password = password
        self.netmiko_connection = None
        self.routes = collections.defaultdict(list)
        self._routing = {}
        self.prefix = None
        self.protocol = None

        try:
            self.enable = enable["enable"]
        except TypeError:
            self.enable = None

        self.create_db = DatabaseOps.RoutingDatabase()
        self.initialize_class_methods()
        self.database()
예제 #4
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
예제 #5
0
    def database(self):
        """Unpacks routes from dictionary and write the to our database since our route attribute are prediible lengths,
        we can easily combine and write if needed"""

        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():
                        # 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, interface, metrics
                # and tags. This is so we dont have to modify DB rows/columns.

                if len(routes_attributes) == 5:
                    DatabaseOps.db_update_ios_xe(vrf, prefix, routes_attributes[0], routes_attributes[1],
                                                 routes_attributes[2], routes_attributes[3], routes_attributes[4],
                                                 tag="None")

                if len(routes_attributes) == 8:
                    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_ios_xe(vrf, prefix, routes_attributes[0], routes_attributes[1], next_hops,
                                                 interfaces, route_metrics, routes_attributes[2])

                if len(routes_attributes) == 11:
                    next_hops = routes_attributes[2] + ", " + routes_attributes[5] + ", " + routes_attributes[8]
                    route_metrics = routes_attributes[4] + ", " + routes_attributes[7] + ", " + routes_attributes[10]
                    interfaces = routes_attributes[3] + ", " + routes_attributes[6] + ", " + routes_attributes[9]

                    DatabaseOps.db_update_ios_xe(vrf, prefix, routes_attributes[0], routes_attributes[1],
                                                 next_hops, interfaces, route_metrics, routes_attributes[2],)
예제 #6
0
    def __init__(self, host, username, password, enable=None):

        self.host = host
        self.username = username
        self.password = password
        self.enable = enable
        self.netmiko_connection = None
        self.prefix = None
        self.protocol = None
        self.vrf = None

        self.admin_dis = []
        self.metric = []
        self.next_hop = []
        self.route_age = []
        self.interface = []

        self.create_db = DatabaseOps.RoutingDatabase()
        self.device_login()
        self._parse_global_routing_entries()
예제 #7
0
    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])