Ejemplo n.º 1
0
    def show_arp(cls, client_obj, show_arp=None):
        _ = show_arp
        parser = "raw/horizontalTable"

        endpoint = "get arp"
        expect_prompt = ["--More--", ">"]

        # Execute the command on the NSXManager
        raw_payload = client_obj.connection. \
            request(endpoint, expect_prompt).response_data

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

        raw_payload = data_parser.marshal_raw_data(raw_payload,
                                                   'Hardware Addr',
                                                   'HardwareAddr')

        # Get the parsed data
        pydict = data_parser.get_parsed_data(raw_payload, skip_tail=2)

        # Close the expect connection object
        client_obj.connection.close()

        return show_arp_schema.ShowArpSchema(pydict)
Ejemplo n.º 2
0
    def get_ping_output(cls,
                        client_obj,
                        ip=None,
                        hostname=None,
                        get_ping_output=None):
        _ = get_ping_output
        if ip is not None:
            endpoint = "ping " + ip
        elif hostname is not None:
            endpoint = "ping " + hostname
        else:
            raise ValueError("Received empty hostname/IP")

        expect_prompt = ["--More--", ">"]

        # 'Ctrl + C' required to terminate the ping execution
        control_key = 'c'

        # Sleeping for 5 seconds to collect sizable ping responses
        sleep = 5

        raw_payload = client_obj.connection.request(endpoint, expect_prompt,
                                                    control_key,
                                                    sleep).response_data

        # Close the expect connection object
        client_obj.connection.close()

        # Get the parser
        parser = "raw/pingHost"
        data_parser = utilities.get_data_parser(parser)

        pydict = data_parser.get_parsed_data(raw_payload)

        return pydict
Ejemplo n.º 3
0
    def show_ip_route(cls, client_obj, **kwargs):
        """
        nsxmanager> show ip route
        default via 10.112.11.253 dev mgmt  metric 203
        10.112.10.0/23 via 10.112.11.253 dev mgmt
        10.112.10.0/23 dev mgmt  proto kernel  scope link  src 10.112.11.27
          metric 203
        """

        endpoint = "show ip route"
        expect_prompt = ['bytes *', '>']

        if 'cidr' in kwargs:
            if kwargs['cidr']:
                endpoint = endpoint + " " + kwargs['cidr']
            else:
                raise ValueError("Received empty cidr")

        raw_payload = client_obj.connection.request(
            endpoint, expect_prompt).response_data

        # Close the expect connection object
        client_obj.connection.close()

        # Get the parser
        parser = "raw/showIpRoute"
        data_parser = utilities.get_data_parser(parser)

        return data_parser.get_parsed_data(raw_payload)
Ejemplo n.º 4
0
    def show_ip_route(cls, client_obj, **kwargs):
        """
        nsxmanager> show ip route
        default via 10.112.11.253 dev mgmt  metric 203
        10.112.10.0/23 via 10.112.11.253 dev mgmt
        10.112.10.0/23 dev mgmt  proto kernel  scope link  src 10.112.11.27
          metric 203
        """

        endpoint = "show ip route"
        expect_prompt = ['bytes *', '>']

        if 'cidr' in kwargs:
            if kwargs['cidr']:
                endpoint = endpoint + " " + kwargs['cidr']
            else:
                raise ValueError("Received empty cidr")

        raw_payload = client_obj.connection.request(
            endpoint, expect_prompt).response_data

        # Close the expect connection object
        client_obj.connection.close()

        # Get the parser
        parser = "raw/showIpRoute"
        data_parser = utilities.get_data_parser(parser)

        return data_parser.get_parsed_data(raw_payload)
Ejemplo n.º 5
0
    def get_ntp_associations(cls, client_obj, **kwargs):
        """
        vdnet-nsxmanager(config)# show ntp associations
             remote           local      st poll reach  delay   offset    disp
        =======================================================================
        *LOCAL(0)        127.0.0.1        3   64    1 0.00000  0.000000 2.81735
        =scrootdc02.vmwa 10.110.31.231    2   64    1 0.21999 -8.864582 2.81874
        """

        endpoint = "show ntp associations"
        expect_prompt = ['bytes *', '>']

        raw_payload = client_obj.connection.request(
            endpoint, expect_prompt).response_data

        # Get the parser
        parser = "raw/horizontalTable"
        data_parser = utilities.get_data_parser(parser)

        # Horizontal table parser doesn't support any particular line deletion
        # in the table. Removing  first two lines and creating a new header
        header_keys = \
            ['remote', 'local', 'st', 'poll', 'reach', 'delay', 'offset',
             'disp']

        raw_payload_with_header = \
            data_parser.insert_header_to_raw_data(
                raw_payload, header_keys=header_keys, skip_head=2)

        pydict = data_parser.get_parsed_data(
            raw_payload_with_header, skip_head=2, skip_tail=1)

        # Close the expect connection object
        client_obj.connection.close()
        return show_ntp_associations_schema.ShowNtpAssociationsSchema(pydict)
Ejemplo n.º 6
0
    def get_ping_output(cls, client_obj, ip=None, hostname=None,
                        get_ping_output=None):
        _ = get_ping_output
        if ip is not None:
            endpoint = "ping " + ip
        elif hostname is not None:
            endpoint = "ping " + hostname
        else:
            raise ValueError("Received empty hostname/IP")

        expect_prompt = ["--More--", ">"]

        # 'Ctrl + C' required to terminate the ping execution
        control_key = 'c'

        # Sleeping for 5 seconds to collect sizable ping responses
        sleep = 5

        raw_payload = client_obj.connection.request(
            endpoint, expect_prompt, control_key, sleep).response_data

        # Close the expect connection object
        client_obj.connection.close()

        # Get the parser
        parser = "raw/pingHost"
        data_parser = utilities.get_data_parser(parser)

        pydict = data_parser.get_parsed_data(raw_payload)

        return pydict
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo n.º 10
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
Ejemplo n.º 11
0
    def read_system_memory(cls, client_obj, **kwargs):
        client_obj.connection.login_to_st_en_terminal(expect=['#'])

        endpoint = "cat /proc/meminfo"
        parser = "raw/systemMeminfo"
        expect_prompt = ['bytes*', '#']

        raw_payload = client_obj.connection.request(endpoint, expect_prompt)\
            .response_data

        data_parser = utilities.get_data_parser(parser)
        client_obj.connection.close()
        return data_parser.get_parsed_data(raw_payload)
Ejemplo n.º 12
0
    def read_system_memory(cls, client_obj, **kwargs):
        client_obj.connection.login_to_st_en_terminal(expect=['#'])

        endpoint = "cat /proc/meminfo"
        parser = "raw/systemMeminfo"
        expect_prompt = ['bytes*', '#']

        raw_payload = client_obj.connection.request(endpoint, expect_prompt)\
            .response_data

        data_parser = utilities.get_data_parser(parser)
        client_obj.connection.close()
        return data_parser.get_parsed_data(raw_payload)
Ejemplo n.º 13
0
    def get_ip_bgp_neighbors(cls,
                             client_object,
                             ip_address=None,
                             get_ip_bgp_neighbors=None):
        """
        NSXEdge> show ip bgp neighbors 192.168.50.2

        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

        NSXEdge>
        """
        if ip_address is None:
            raise ValueError("IP address must be a valid value. "
                             "Provided: %r" % ip_address)

        endpoint = "show ip bgp neighbors " + ip_address
        PARSER = "raw/showBgpNeighbors"

        # Execute the command on the Edge VM
        raw_payload = client_object.connection. \
            request(endpoint, EXPECT_PROMPT).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=":")

        # Close the expect connection object
        client_object.connection.close()

        get_ip_bgp_neighbors_schema_object = get_ip_bgp_neighbors_schema. \
            GetIPBGPNeighborsSchema(pydict)
        return get_ip_bgp_neighbors_schema_object
Ejemplo n.º 14
0
    def get_cluster_startupnodes(cls, client_object, **kwargs):
        cmd = "get control-cluster startup-nodes"
        expect = ['bytes*', '>']
        raw_data = client_object.connection.request(cmd, expect).response_data

        header_keys = ['controller_ip']
        data_parser = utilities.get_data_parser(cls.HORIZONTAL_PARSER_TYPE)
        mod_raw_data = data_parser.insert_header_to_raw_data(
            raw_data, header_keys=header_keys)

        mapped_pydicts = utilities.parse_data_map_attributes(
            mod_raw_data, cls.HORIZONTAL_PARSER_TYPE, attribute_map=None)

        return cluster_node_schema.ClusterStartupNodesSchema(mapped_pydicts)
Ejemplo n.º 15
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
Ejemplo n.º 16
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
Ejemplo n.º 17
0
    def get_process_monitor(cls, client_obj, **kwargs):
        endpoint = "show process monitor"
        expect_prompt = ["#", ">", "\'"]
        ctrl_key = 'C'
        wait = 2

        raw_payload = client_obj.connection.request(
            endpoint, expect_prompt, ctrl_key, wait).response_data

        parser = "raw/showProcessMonitor"
        data_parser = utilities.get_data_parser(parser)

        pydict = data_parser.get_parsed_data(raw_payload)

        return show_process_monitor_schema.ShowProcessMonitorSchema(pydict)
Ejemplo n.º 18
0
    def get_ip_bgp_neighbors(cls, client_object, ip_address=None,
                             get_ip_bgp_neighbors=None):
        """
        NSXEdge> show ip bgp neighbors 192.168.50.2

        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

        NSXEdge>
        """
        if ip_address is None:
            raise ValueError("IP address must be a valid value. "
                             "Provided: %r" % ip_address)

        endpoint = "show ip bgp neighbors " + ip_address
        PARSER = "raw/showBgpNeighbors"

        # Execute the command on the Edge VM
        raw_payload = client_object.connection. \
            request(endpoint, EXPECT_PROMPT).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=":")

        # Close the expect connection object
        client_object.connection.close()

        get_ip_bgp_neighbors_schema_object = get_ip_bgp_neighbors_schema. \
            GetIPBGPNeighborsSchema(pydict)
        return get_ip_bgp_neighbors_schema_object
Ejemplo n.º 19
0
    def get_process_monitor(cls, client_obj, **kwargs):
        endpoint = "show process monitor"
        expect_prompt = ["#", ">", "\'"]
        ctrl_key = 'C'
        wait = 2

        raw_payload = client_obj.connection.request(endpoint, expect_prompt,
                                                    ctrl_key,
                                                    wait).response_data

        parser = "raw/showProcessMonitor"
        data_parser = utilities.get_data_parser(parser)

        pydict = data_parser.get_parsed_data(raw_payload)

        return show_process_monitor_schema.ShowProcessMonitorSchema(pydict)
Ejemplo n.º 20
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
Ejemplo n.º 21
0
    def get_cluster_managers(cls, client_object, **kwargs):
        cmd = "get managers"
        expect = ['bytes*', '>']
        raw_data = client_object.connection.request(cmd, expect).response_data

        mod_raw_data = raw_data.replace(':', ' ')
        header_keys = ['ip', 'port', 'thumbprint']
        data_parser = utilities.get_data_parser(cls.HORIZONTAL_PARSER_TYPE)
        mod_raw_data = data_parser.insert_header_to_raw_data(
            mod_raw_data, header_keys=header_keys)

        mapped_pydicts = utilities.parse_data_map_attributes(
            mod_raw_data,
            cls.HORIZONTAL_PARSER_TYPE,
            attribute_map=None,
            skip_tail=1)

        return cluster_node_schema.ClusterManagerNodesSchema(mapped_pydicts)
Ejemplo n.º 22
0
    def show_ip_sockets(cls, client_obj, **kwargs):
        parser = "raw/horizontalTable"

        endpoint = "show ip sockets"
        expect_prompt = ["--More--", ">"]

        # Execute the command on the NSXManager
        raw_payload = client_obj.connection. \
            request(endpoint, expect_prompt).response_data

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

        # Get the parsed data
        pydict = data_parser.get_parsed_data(raw_payload, skip_tail=2)

        # Close the expect connection object
        client_obj.connection.close()

        return show_ip_sockets_schema.ShowIPSocketsSchema(pydict)
Ejemplo n.º 23
0
    def show_ip_sockets(cls, client_obj, **kwargs):
        parser = "raw/horizontalTable"

        endpoint = "show ip sockets"
        expect_prompt = ["--More--", ">"]

        # Execute the command on the NSXManager
        raw_payload = client_obj.connection. \
            request(endpoint, expect_prompt).response_data

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

        # Get the parsed data
        pydict = data_parser.get_parsed_data(raw_payload, skip_tail=2)

        # Close the expect connection object
        client_obj.connection.close()

        return show_ip_sockets_schema.ShowIPSocketsSchema(pydict)
Ejemplo n.º 24
0
    def get_dir_list(cls, client_obj, get_dir_list=None):
        """ Sample output of 'dir' CLI
        nsx-manager> dir
        Directory of filestore:/

       -rwx      126626     Dec 04 2014 07:30:05 UTC  tech.tzg
       -rwx      127268     Dec 04 2014 07:33:17 UTC  tech02.tzg
       -rwx      152582     Dec 04 2014 09:33:24 UTC  tech_support.tgz
       -rwx      162002     Dec 04 2014 10:27:17 UTC  tech_support_logs.tgz
       -rwx           0     Dec 04 2014 07:10:13 UTC  text.file

        """
        _ = get_dir_list
        endpoint = "get files"
        expect_prompt = ["--More--", ">"]

        raw_payload = client_obj.connection.request(endpoint, expect_prompt)\
            .response_data

        # Get the parser
        parser = "raw/horizontalTable"
        data_parser = utilities.get_data_parser(parser)

        # Creating header as CLI returns list without column name
        header_keys = \
            ['permissions', 'size', 'month', 'date', 'year', 'time', 'TZ',
             'file_name']

        raw_payload_with_header = \
            data_parser.insert_header_to_raw_data(
                raw_payload, header_keys=header_keys, skip_head=2)

        pydict = data_parser.get_parsed_data(raw_payload_with_header,
                                             header_keys=header_keys,
                                             skip_head=2,
                                             skip_tail=1)

        # Close the expect connection object
        client_obj.connection.close()

        return dir_schema.DirSchema(pydict)
Ejemplo n.º 25
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
Ejemplo n.º 26
0
    def get_dir_list(cls, client_obj, get_dir_list=None):
        """ Sample output of 'dir' CLI
        nsx-manager> dir
        Directory of filestore:/

       -rwx      126626     Dec 04 2014 07:30:05 UTC  tech.tzg
       -rwx      127268     Dec 04 2014 07:33:17 UTC  tech02.tzg
       -rwx      152582     Dec 04 2014 09:33:24 UTC  tech_support.tgz
       -rwx      162002     Dec 04 2014 10:27:17 UTC  tech_support_logs.tgz
       -rwx           0     Dec 04 2014 07:10:13 UTC  text.file

        """
        _ = get_dir_list
        endpoint = "get files"
        expect_prompt = ["--More--", ">"]

        raw_payload = client_obj.connection.request(endpoint, expect_prompt)\
            .response_data

        # Get the parser
        parser = "raw/horizontalTable"
        data_parser = utilities.get_data_parser(parser)

        # Creating header as CLI returns list without column name
        header_keys = \
            ['permissions', 'size', 'month', 'date', 'year', 'time', 'TZ',
             'file_name']

        raw_payload_with_header = \
            data_parser.insert_header_to_raw_data(
                raw_payload, header_keys=header_keys, skip_head=2)

        pydict = data_parser.get_parsed_data(
            raw_payload_with_header, header_keys=header_keys, skip_head=2,
            skip_tail=1)

        # Close the expect connection object
        client_obj.connection.close()

        return dir_schema.DirSchema(pydict)
Ejemplo n.º 27
0
    def get_ntp_associations(cls, client_obj, **kwargs):
        """
        vdnet-nsxmanager(config)# show ntp associations
             remote           local      st poll reach  delay   offset    disp
        =======================================================================
        *LOCAL(0)        127.0.0.1        3   64    1 0.00000  0.000000 2.81735
        =scrootdc02.vmwa 10.110.31.231    2   64    1 0.21999 -8.864582 2.81874
        """

        endpoint = "show ntp associations"
        expect_prompt = ['bytes *', '>']

        raw_payload = client_obj.connection.request(
            endpoint, expect_prompt).response_data

        # Get the parser
        parser = "raw/horizontalTable"
        data_parser = utilities.get_data_parser(parser)

        # Horizontal table parser doesn't support any particular line deletion
        # in the table. Removing  first two lines and creating a new header
        header_keys = \
            ['remote', 'local', 'st', 'poll', 'reach', 'delay', 'offset',
             'disp']

        raw_payload_with_header = \
            data_parser.insert_header_to_raw_data(
                raw_payload, header_keys=header_keys, skip_head=2)

        pydict = data_parser.get_parsed_data(raw_payload_with_header,
                                             skip_head=2,
                                             skip_tail=1)

        # Close the expect connection object
        client_obj.connection.close()
        return show_ntp_associations_schema.ShowNtpAssociationsSchema(pydict)
Ejemplo n.º 28
0
    def show_arp(cls, client_obj, show_arp=None):
        _ = show_arp
        parser = "raw/horizontalTable"

        endpoint = "get arp"
        expect_prompt = ["--More--", ">"]

        # Execute the command on the NSXManager
        raw_payload = client_obj.connection. \
            request(endpoint, expect_prompt).response_data

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

        raw_payload = data_parser.marshal_raw_data(
            raw_payload, 'Hardware Addr', 'HardwareAddr')

        # Get the parsed data
        pydict = data_parser.get_parsed_data(raw_payload, skip_tail=2)

        # Close the expect connection object
        client_obj.connection.close()

        return show_arp_schema.ShowArpSchema(pydict)
Ejemplo n.º 29
0
    def get_ip_route(cls, client_object, route_filter=None, prefix=None,
                     get_ip_route=None):
        """
        NSXEdge> show ip route

        Codes: O - OSPF derived, i - IS-IS derived, B - BGP derived,
        C - connected, S - static, L1 - IS-IS level-1, L2 - IS-IS level-2,
        IA - OSPF inter area, E1 - OSPF external type 1, E2 - OSPF external type 2,  # noqa
        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

        Total number of routes: 4

        C       10.110.60.0/22       [0/0]         via 10.110.63.114
        C       169.0.0.0/28         [0/0]         via 169.0.0.2
        C       169.255.255.240/28   [0/0]         via 169.255.255.241
        C       192.168.3.0/24       [0/0]         via 192.168.3.1
        NSXEdge>
        """

        PARSER = "raw/horizontalTable"
        VALID_ROUTE_FILTERS = ['bgp', 'connected', 'static']

        get_ip_route_command = ["show ip route"]

        if route_filter is None:
            skip_head = 6
        elif route_filter not in VALID_ROUTE_FILTERS:
            raise ValueError("Invalid route filter: %r. Valid values are : %r"
                             % (route_filter, VALID_ROUTE_FILTERS))
        else:
            skip_head = 4
            get_ip_route_command.append(route_filter)
            if prefix:
                get_ip_route_command.append(prefix)

        endpoint = " ".join(get_ip_route_command)
        # Execute the command on the Edge VM
        raw_payload = client_object.connection. \
            request(endpoint, EXPECT_PROMPT).response_data

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

        # Specify the Header keys that we want to insert to the output
        header_keys = ['Code', 'Network', 'AdminDist_Metric', 'Via', 'NextHop']

        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)

        # Close the expect connection object
        client_object.connection.close()

        get_ip_route_schema_object = get_ip_route_schema. \
            GetIPRouteSchema(pydict)
        if route_filter and prefix:
            return get_ip_route_schema_object.table[0]
        return get_ip_route_schema_object
Ejemplo n.º 30
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
Ejemplo n.º 31
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
Ejemplo n.º 32
0
    def get_ip(cls, client_object, table_name=None, get_ip=None):
        """
        Sample Output of command show ip forwarding:

        Codes: C - connected, R - remote,
        > - selected route, * - FIB route
        R>* 0.0.0.0/0 via 10.24.31.253, vNic_3
        C>* 10.24.28.0/22 is directly connected, vNic_3
        C>* 20.20.20.0/24 is directly connected, vNic_2
        C>* 50.50.50.0/24 is directly connected, vNic_0


        #Sample Output of command show ip bgp:
        NSXEdge> 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     ?
        """

        BGP_TABLE = 'bgp'
        FORWARDING_TABLE = 'forwarding'
        PARSER = "raw/horizontalTable"
        VALID_TABLES = [FORWARDING_TABLE, BGP_TABLE]

        get_ip_command = "show ip %s"
        header_keys = None
        skip_head = None

        header_skip_dict = {
            'forwarding': {
                'header_keys': ['Code', 'Network', 'Via', 'NextHop', 'VnicName'],  # noqa
                'skip_head': 2
            },
            'bgp': {
                'header_keys': ['Scode', 'Network', 'NextHop', 'Metric', 'LocPrf', 'Weight', 'Origin'],  # noqa
                'skip_head': 3
            }
        }

        if table_name not in VALID_TABLES:
            raise ValueError("Invalid table name: %r. Valid values are : %r"
                             % (table_name, VALID_TABLES))

        endpoint = get_ip_command % table_name
        header_keys = header_skip_dict[table_name]['header_keys']

        # No. of Header lines to be skipped from output
        skip_head = header_skip_dict[table_name]['skip_head']

        # Execute the command on the Edge VM
        raw_payload = client_object.connection. \
            request(endpoint, EXPECT_PROMPT).response_data

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

        if table_name == FORWARDING_TABLE:
            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)

        # Close the expect connection object
        client_object.connection.close()

        if table_name == FORWARDING_TABLE:
            get_ip_schema_object = get_ip_forwarding_schema. \
                GetIPForwardingSchema(pydict)
        elif table_name == BGP_TABLE:
            get_ip_schema_object = get_ip_bgp_schema.GetIPBGPSchema(pydict)
        return get_ip_schema_object
Ejemplo n.º 33
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
Ejemplo n.º 34
0
    def get_ip_route(cls,
                     client_object,
                     route_filter=None,
                     prefix=None,
                     get_ip_route=None):
        """
        NSXEdge> show ip route

        Codes: O - OSPF derived, i - IS-IS derived, B - BGP derived,
        C - connected, S - static, L1 - IS-IS level-1, L2 - IS-IS level-2,
        IA - OSPF inter area, E1 - OSPF external type 1, E2 - OSPF external type 2,  # noqa
        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

        Total number of routes: 4

        C       10.110.60.0/22       [0/0]         via 10.110.63.114
        C       169.0.0.0/28         [0/0]         via 169.0.0.2
        C       169.255.255.240/28   [0/0]         via 169.255.255.241
        C       192.168.3.0/24       [0/0]         via 192.168.3.1
        NSXEdge>
        """

        PARSER = "raw/horizontalTable"
        VALID_ROUTE_FILTERS = ['bgp', 'connected', 'static']

        get_ip_route_command = ["show ip route"]

        if route_filter is None:
            skip_head = 6
        elif route_filter not in VALID_ROUTE_FILTERS:
            raise ValueError(
                "Invalid route filter: %r. Valid values are : %r" %
                (route_filter, VALID_ROUTE_FILTERS))
        else:
            skip_head = 4
            get_ip_route_command.append(route_filter)
            if prefix:
                get_ip_route_command.append(prefix)

        endpoint = " ".join(get_ip_route_command)
        # Execute the command on the Edge VM
        raw_payload = client_object.connection. \
            request(endpoint, EXPECT_PROMPT).response_data

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

        # Specify the Header keys that we want to insert to the output
        header_keys = ['Code', 'Network', 'AdminDist_Metric', 'Via', 'NextHop']

        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)

        # Close the expect connection object
        client_object.connection.close()

        get_ip_route_schema_object = get_ip_route_schema. \
            GetIPRouteSchema(pydict)
        if route_filter and prefix:
            return get_ip_route_schema_object.table[0]
        return get_ip_route_schema_object
Ejemplo n.º 35
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
Ejemplo n.º 36
0
    def get_ip(cls, client_object, table_name=None, get_ip=None):
        """
        Sample Output of command show ip forwarding:

        Codes: C - connected, R - remote,
        > - selected route, * - FIB route
        R>* 0.0.0.0/0 via 10.24.31.253, vNic_3
        C>* 10.24.28.0/22 is directly connected, vNic_3
        C>* 20.20.20.0/24 is directly connected, vNic_2
        C>* 50.50.50.0/24 is directly connected, vNic_0


        #Sample Output of command show ip bgp:
        NSXEdge> 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     ?
        """

        BGP_TABLE = 'bgp'
        FORWARDING_TABLE = 'forwarding'
        PARSER = "raw/horizontalTable"
        VALID_TABLES = [FORWARDING_TABLE, BGP_TABLE]

        get_ip_command = "show ip %s"
        header_keys = None
        skip_head = None

        header_skip_dict = {
            'forwarding': {
                'header_keys':
                ['Code', 'Network', 'Via', 'NextHop', 'VnicName'],  # noqa
                'skip_head': 2
            },
            'bgp': {
                'header_keys': [
                    'Scode', 'Network', 'NextHop', 'Metric', 'LocPrf',
                    'Weight', 'Origin'
                ],  # noqa
                'skip_head':
                3
            }
        }

        if table_name not in VALID_TABLES:
            raise ValueError("Invalid table name: %r. Valid values are : %r" %
                             (table_name, VALID_TABLES))

        endpoint = get_ip_command % table_name
        header_keys = header_skip_dict[table_name]['header_keys']

        # No. of Header lines to be skipped from output
        skip_head = header_skip_dict[table_name]['skip_head']

        # Execute the command on the Edge VM
        raw_payload = client_object.connection. \
            request(endpoint, EXPECT_PROMPT).response_data

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

        if table_name == FORWARDING_TABLE:
            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)

        # Close the expect connection object
        client_object.connection.close()

        if table_name == FORWARDING_TABLE:
            get_ip_schema_object = get_ip_forwarding_schema. \
                GetIPForwardingSchema(pydict)
        elif table_name == BGP_TABLE:
            get_ip_schema_object = get_ip_bgp_schema.GetIPBGPSchema(pydict)
        return get_ip_schema_object