Esempio n. 1
0
    def get_edge_version(self,
                         server_dict,
                         edge_ha_index="0",
                         get_edge_version=None):
        pylogger.info("Getting Edge Version using Centralized API")
        edge_ha_index = edge_ha_index['edge_ha_index']
        url_endpoint = "/edges/" + self.id + "/appliances/" + edge_ha_index + "?action=execute"
        self.set_create_endpoint(url_endpoint)
        self.connection.api_header = '/api/4.0'
        self.schema_class = 'edge_centralized_api_cli_schema.EdgeCentralizedApiCliSchema'

        pylogger.debug("URl EndPoint : %s ", url_endpoint)

        py_dict = {'cmdstr': 'show version'}

        schema_obj = EdgeCentralizedApiCliSchema(py_dict)

        result_obj = self.create(schema_obj)

        temp_reponse_data = result_obj[0].response_data
        pylogger.debug("Response Data from API: %s ", temp_reponse_data)

        lines = temp_reponse_data.splitlines()
        server_dict = dict()

        server_dict['name'] = lines[0].split(":")[-1].strip()
        server_dict['version'] = lines[1].split(":")[-1].strip()
        server_dict['kernel'] = lines[3].split(":")[-1].strip()
        return server_dict
Esempio n. 2
0
    def get_ip_bgp(self, server_dict, edge_ha_index="0", get_ip_bgp=None):
        """
        Sample Output of command show ip bgp:

        Status codes: s - suppressed, d - damped, > - best, i - internal
        Origin codes: i - IGP, e - EGP, ? - incomplete

             Network             Next Hop        Metric  LocPrf  Weight  Origin
        >  100.64.1.0/31       169.0.0.1          0     100   32768     ?
        >  192.168.40.0/24     192.168.50.2       0     100      60     i
        >  192.168.50.0/24     192.168.50.2       0     100      60     i
        >  192.168.60.0/24     169.0.0.1          0     100   32768     ?
        >  192.168.70.0/24     169.0.0.1          0     100   32768     ?
        """

        PARSER = "raw/horizontalTable"
        pylogger.info("Getting Edge IP BGP using Centralized API")
        edge_ha_index = edge_ha_index['edge_ha_index']
        url_endpoint = "/edges/%s/appliances/%s?action=execute" % (
            self.id, edge_ha_index)
        self.set_create_endpoint(url_endpoint)
        self.connection.api_header = '/api/4.0'
        self.schema_class = 'edge_centralized_api_cli_schema.EdgeCentralizedApiCliSchema'

        pylogger.debug("URl EndPoint : %s ", url_endpoint)

        py_dict = {'cmdstr': 'show ip bgp'}

        schema_obj = EdgeCentralizedApiCliSchema(py_dict)

        result_obj = self.create(schema_obj)

        header_keys = [
            'Scode', 'Network', 'NextHop', 'Metric', 'LocPrf', 'Weight',
            'Origin'
        ]

        # No. of Header lines to be skipped from output
        skip_head = 4

        raw_payload = result_obj[0].response_data

        pylogger.debug("Response Data from API: %s ", raw_payload)

        # Get the parser
        data_parser = utilities.get_data_parser(PARSER)

        # Specify the Header keys that we want to insert to the output
        mod_raw_data = data_parser.insert_header_to_raw_data(
            raw_payload, header_keys=header_keys, skip_head=skip_head)
        # Get the parsed data
        pydict = data_parser.get_parsed_data(mod_raw_data,
                                             header_keys=header_keys,
                                             skip_head=skip_head,
                                             expect_empty_fields=False)

        pylogger.debug("get_ip_bgp returned pydict: %s", pydict)

        return pydict
Esempio n. 3
0
    def get_ip_bgp_neighbors(self,
                             server_dict,
                             edge_ha_index="0",
                             get_ip_bgp_neighbors=None):
        """
        CLI output for show ip bgp neighbors

        BGP neighbor is 192.168.50.2,   remote AS 200,
        BGP state = Established, up
        Hold time is 180, Keep alive interval is 60 seconds
        Neighbor capabilities:
                 Route refresh: advertised and received
                 Address family IPv4 Unicast:advertised and received
                 Graceful restart Capability:none
                         Restart remain time: 0
        Received 95 messages, Sent 99 messages
        Default minimum time between advertisement runs is 30 seconds
        For Address family IPv4 Unicast:advertised and received
                 Index 1 Identifier 0x5fc5f6ec
                 Route refresh request:received 0 sent 0
                 Prefixes received 2 sent 2 advertised 2
        Connections established 3, dropped 62
        Local host: 192.168.50.1, Local port: 179
        Remote host: 192.168.50.2, Remote port: 47813
        """

        PARSER = "raw/showBgpNeighbors"
        pylogger.info("Getting Edge IP BGP Neighbors using Centralized API")
        edge_ha_index = edge_ha_index['edge_ha_index']
        url_endpoint = "/edges/%s/appliances/%s?action=execute" % (
            self.id, edge_ha_index)
        self.set_create_endpoint(url_endpoint)
        self.connection.api_header = '/api/4.0'
        self.schema_class = 'edge_centralized_api_cli_schema.EdgeCentralizedApiCliSchema'

        pylogger.debug("URl EndPoint : %s ", url_endpoint)

        endpoint = "show ip bgp neighbors"
        pylogger.debug("Command to be executed: %s", endpoint)

        py_dict = {'cmdstr': endpoint}

        schema_obj = EdgeCentralizedApiCliSchema(py_dict)
        result_obj = self.create(schema_obj)

        # Execute the command on the Edge VM
        raw_payload = result_obj[0].response_data

        # Get the parser
        data_parser = utilities.get_data_parser(PARSER)

        # Get the parsed data
        pydict = data_parser.get_parsed_data(raw_payload, delimiter=":")
        pylogger.debug("get_ip_bgp_neighbors returned pydict: %s", pydict)

        return pydict
Esempio n. 4
0
    def get_ip_ospf_neighbor(self,
                             server_dict,
                             edge_ha_index="0",
                             get_ip_ospf_neighbor=None):
        """
        Sample Command output:
          Neigbhor ID         Priority    Address             Dead Time   State
          2.2.2.2             128         192.168.1.50        38          Full/BDR
        """
        PARSER = "raw/horizontalTable"
        pylogger.info("Getting Edge IP OSPF Neighbor using Centralized API")
        edge_ha_index = edge_ha_index['edge_ha_index']
        url_endpoint = "/edges/%s/appliances/%s?action=execute" \
                       % (self.id, edge_ha_index)
        self.set_create_endpoint(url_endpoint)
        self.connection.api_header = '/api/4.0'
        self.schema_class = \
            'edge_centralized_api_cli_schema.EdgeCentralizedApiCliSchema'

        pylogger.debug("URl EndPoint : %s ", url_endpoint)

        py_dict = {'cmdstr': 'show ip ospf neighbor'}

        schema_obj = EdgeCentralizedApiCliSchema(py_dict)
        result_obj = self.create(schema_obj)
        raw_payload = result_obj[0].response_data
        pylogger.debug("Response Data from API: %s ", raw_payload)

        # Get the parser
        data_parser = utilities.get_data_parser(PARSER)

        # Insert the Header
        skip_head = 1
        header_keys = [
            'neigbhor_id', 'priority', 'address', 'dead_time', 'state'
        ]  # noqa

        mod_raw_data = data_parser.insert_header_to_raw_data(
            raw_payload, header_keys=header_keys, skip_head=skip_head)

        # Get the parsed data
        pydict = data_parser.get_parsed_data(mod_raw_data,
                                             header_keys=header_keys,
                                             skip_head=skip_head,
                                             expect_empty_fields=False)

        pylogger.debug("Get IP OSPF Neighbor returned pydict: %s", pydict)

        return pydict
Esempio n. 5
0
    def get_ip_forwarding(self,
                          server_dict,
                          edge_ha_index="0",
                          get_ip_forwarding=None):
        pylogger.info("Getting Edge IP Forwarding using Centralized API")
        edge_ha_index = edge_ha_index['edge_ha_index']
        url_endpoint = "/edges/" + self.id + "/appliances/" + edge_ha_index + "?action=execute"
        self.set_create_endpoint(url_endpoint)
        self.connection.api_header = '/api/4.0'
        self.schema_class = 'edge_centralized_api_cli_schema.EdgeCentralizedApiCliSchema'

        pylogger.debug("URl EndPoint : %s ", url_endpoint)

        py_dict = {'cmdstr': 'show ip forwarding'}

        schema_obj = EdgeCentralizedApiCliSchema(py_dict)

        result_obj = self.create(schema_obj)

        PARSER = "raw/horizontalTable"
        header_keys = ['Code', 'Network', 'Via', 'NextHop', 'VnicName']  # noqa

        # No. of Header lines to be skipped from output
        skip_head = 2

        raw_payload = result_obj[0].response_data

        pylogger.debug("Response Data from API: %s ", raw_payload)

        # Get the parser
        data_parser = utilities.get_data_parser(PARSER)

        raw_payload = data_parser.marshal_raw_data(raw_payload,
                                                   'is directly connected,',
                                                   'isdirectlyconnected NULL')

        # Specify the Header keys that we want to insert to the output
        mod_raw_data = data_parser.insert_header_to_raw_data(
            raw_payload, header_keys=header_keys, skip_head=skip_head)

        # Get the parsed data
        pydict = data_parser.get_parsed_data(mod_raw_data,
                                             header_keys=header_keys,
                                             skip_head=skip_head,
                                             expect_empty_fields=False)

        return pydict
Esempio n. 6
0
    def get_ip_ospf_database(self,
                             server_dict,
                             edge_ha_index="0",
                             area_id=None,
                             search_filter=None,
                             get_ip_ospf_database=None):
        """
        Sample Command output:
                     Router Link States (Area  0.0.0.0)

        Link ID           ADV Router        Age           Seq Num        Checksum
        1.1.1.1           1.1.1.1           1686          0x8000002e    0x0000ca16
        2.2.2.2           2.2.2.2           1686          0x80000002    0x0000c83d

                     Network Link States (Area  0.0.0.0)

        Link ID           ADV Router        Age           Seq Num        Checksum
        192.168.1.51      1.1.1.1           1691          0x80000001    0x00001d8f

                     Opaque Area Link States (Area  0.0.0.0)

        Link ID           ADV Router        Age           Seq Num        Checksum
        1.0.0.1           1.1.1.1           551           0x8000002e    0x00002957
        1.0.0.2           1.1.1.1           488           0x8000002e    0x0000be1a
        1.0.0.3           2.2.2.2           1691          0x80000001    0x0000689a

                     Type-7 AS External Link States (Area  0.0.0.51)

        Link ID           ADV Router        Age           Seq Num        Checksum
        10.110.60.0       1.1.1.1           492           0x8000002e    0x000017d8
        172.168.1.0       1.1.1.1           492           0x8000002e    0x0000b496
        192.168.1.0       1.1.1.1           492           0x8000002e    0x0000af87

                     Opaque Area Link States (Area  0.0.0.51)

        Link ID           ADV Router        Age           Seq Num        Checksum
        1.0.0.1           1.1.1.1           551           0x8000002e    0x0000ceab
        1.0.0.2           1.1.1.1           488           0x8000002e    0x0000646e

                     AS External Link States

        Link ID           ADV Router        Age           Seq Num        Checksum
        10.10.10.0        2.2.2.2           1691          0x80000001    0x00003d6f
        10.110.60.0       1.1.1.1           492           0x8000002e    0x000015da
        172.168.1.0       1.1.1.1           492           0x8000002e    0x0000b298
        192.168.1.0       1.1.1.1           492           0x8000002e    0x0000ad89
        192.168.1.0       2.2.2.2           1691          0x80000001    0x0000e976
        """
        PARSER = "raw/horizontalTable"
        pylogger.info("Getting Edge IP OSPF Database using Centralized API")
        edge_ha_index = edge_ha_index['edge_ha_index']
        url_endpoint = "/edges/%s/appliances/%s?action=execute" \
                       % (self.id, edge_ha_index)
        self.set_create_endpoint(url_endpoint)
        self.connection.api_header = '/api/4.0'
        self.schema_class = \
            'edge_centralized_api_cli_schema.EdgeCentralizedApiCliSchema'

        pylogger.debug("URl EndPoint : %s ", url_endpoint)

        py_dict = {'cmdstr': 'show ip ospf database'}

        schema_obj = EdgeCentralizedApiCliSchema(py_dict)
        result_obj = self.create(schema_obj)

        search_values = [
            'Summary_NLS', 'RLS', 'NLS', 'OALS', 'Summary_ASB', 'Type7_AS',
            'AS_ExternalLink'
        ]
        search_filter = area_id['search_filter']
        pylogger.debug("Search Filter: %s ", search_filter)

        if search_filter not in search_values:
            raise ValueError(
                "Invalid search_filter name: %r. Valid searchfilter values are : %r"
                % (search_filter, search_values))

        area_id = area_id['area_id']
        pylogger.debug("Area ID: %s ", area_id)

        raw_payload = result_obj[0].response_data

        pylogger.debug("Response Data from API: %s ", raw_payload)

        search_dict = {
            'Summary_NLS': 'Summary Network Link States',
            'RLS': 'Router Link States',
            'NLS': 'Network Link States',
            'OALS': 'Opaque Area Link States',
            'Summary_ASB': 'Summary ASB Link States',
            'Type7_AS': 'Type-7 AS External Link States',
            'AS_ExternalLink': 'AS External Link States'
        }

        search_string = search_dict[
            search_filter] + " (Area  0.0.0." + area_id + ")"
        include_lines = []

        if raw_payload.__contains__(search_string):
            lines = raw_payload.strip().split("\n")

            for i, line in enumerate(lines):
                if line.find(search_string) != -1:
                    i += 1

                    while lines[i].find("Link States") == -1:
                        include_lines.append(lines[i])
                        i += 1

                        if i == len(lines):
                            break

            include_lines = '\n'.join(include_lines)
            raw_payload = include_lines

        # Get the parser
        data_parser = utilities.get_data_parser(PARSER)

        # Specify the Header keys that we want to insert to the output
        skip_head = 1
        header_keys = ['link_id', 'adv_router', 'age', 'seq_num', 'checksum']
        mod_raw_data = data_parser.insert_header_to_raw_data(
            raw_payload, header_keys=header_keys, skip_head=skip_head)

        # Get the parsed data
        pydict = data_parser.get_parsed_data(mod_raw_data,
                                             header_keys=header_keys,
                                             skip_head=skip_head,
                                             expect_empty_fields=False)

        pylogger.debug("Get IP OSPF Database returned pydict: %s", pydict)

        return pydict
Esempio n. 7
0
    def get_ip_route(self, server_dict, edge_ha_index="0", get_ip_route=None):
        pylogger.info("Getting Edge IP Route using Centralized API")
        edge_ha_index = edge_ha_index['edge_ha_index']
        url_endpoint = "/edges/" + self.id + "/appliances/" + edge_ha_index + "?action=execute"
        self.set_create_endpoint(url_endpoint)
        self.connection.api_header = '/api/4.0'
        self.schema_class = 'edge_centralized_api_cli_schema.EdgeCentralizedApiCliSchema'

        pylogger.debug("URl EndPoint : %s ", url_endpoint)

        py_dict = {'cmdstr': 'show ip route'}

        schema_obj = EdgeCentralizedApiCliSchema(py_dict)

        result_obj = self.create(schema_obj)

        PARSER = "raw/horizontalTable"
        header_keys = ['Code', 'Network', 'AdminDist_Metric', 'Via', 'NextHop']

        # No. of Header lines to be skipped from output
        skip_head = 6

        raw_payload = result_obj[0].response_data

        pylogger.debug("Response Data from API: %s ", raw_payload)

        #---------------------------------------------------------------
        # If the raw_payload contains OSPF data we have modify the header
        # and insert NUL element at the second place to parse the data properly
        #
        #
        # C       3.3.3.0/24           [0/0]         via 3.3.3.1
        # O   E2  4.4.4.0/24           [110/0]       via 10.10.10.2   ----> this addition requires below change # noqa
        # C       10.10.10.0/24        [0/0]         via 10.10.10.1
        # O       10.10.10.0/24        [0/0]         via 10.10.10.1
        #
        # After parsing the output will be, Inserting NULL into the second field
        #
        # C   NULL 3.3.3.0/24           [0/0]         via 3.3.3.1
        # O   E2   4.4.4.0/24           [110/0]       via 10.10.10.2
        # C   NULL 10.10.10.0/24        [0/0]         via 10.10.10.1
        # O   NULL 10.10.10.0/24        [0/0]         via 10.10.10.1
        #
        #---------------------------------------------------------------
        if raw_payload.__contains__("O"):
            include_lines = []
            header_keys = [
                'Code', 'OSPF_ExternalType', 'Network', 'AdminDist_Metric',
                'Via', 'NextHop'
            ]
            lines = raw_payload.strip().split("\n")

            for line in lines[:skip_head]:
                include_lines.append(line)

            for line in lines[skip_head:]:
                if (line.strip() != ""):
                    templine = line.split()
                    pattern = '[A-Z]+'
                    matched = re.match(pattern, templine[1])
                    if not matched:
                        templine.insert(1, "NULL")
                    templine = " ".join(templine)
                    print templine
                    include_lines.append(templine)
                else:
                    include_lines.append(line)

            include_lines = '\n'.join(include_lines)
            raw_payload = include_lines

        # Get the parser
        data_parser = utilities.get_data_parser(PARSER)

        mod_raw_data = data_parser.insert_header_to_raw_data(
            raw_payload, header_keys=header_keys, skip_head=skip_head)

        # Get the parsed data
        pydict = data_parser.get_parsed_data(mod_raw_data,
                                             header_keys=header_keys,
                                             skip_head=skip_head,
                                             expect_empty_fields=False)

        return pydict