request

        High-level api: sends message through NetConf session and returns with
        a reply. Exception is thrown out either the reply is in wrong
        format or timout. Users can modify timeout value (in seconds) by
        passing parameter timeout. Users may want to set a larger timeout when
        making a large query.

        Parameters
        ----------

        msg : `str`
            Any message need to be sent out in XML format. The message can be
            in wrong format if it is a negative test case. Because ncclient
            tracks same message-id in both rpc and rpc-reply, missing
            message-id in your rpc may cause exception when receiving
            rpc-reply. Most other wrong format rpc's can be sent without
            exception.
        timeout : `int`, optional
            An optional keyed argument to set timeout value in seconds. Its
            default value is 30 seconds.

        Returns
        -------

        str
            The reply from the device in string. If something goes wrong, an
            exception will be raised.


        Raises
        ------

        Exception
            If NetConf is not connected, or there is a timeout when receiving
            reply.


        Code Example::

            >>> from pyats.topology import loader
            >>> testbed = loader.load('/users/xxx/xxx/asr_20_22.yaml')
            >>> device = testbed.devices['asr22']
            >>> device.connect(alias='nc', via='netconf')
            >>> netconf_request = """
            ...     <rpc message-id="101"
            ...      xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
            ...     <get>
            ...     <filter>
            ...     <native xmlns="http://cisco.com/ns/yang/ned/ios">
            ...     <version>
            ...     </version>
            ...     </native>
            ...     </filter>
            ...     </get>
            ...     </rpc>
            ...     """
            >>> reply = device.nc.request(netconf_request)
            >>>

        Expected Results::

            >>> print(reply)
            <?xml version="1.0" encoding="UTF-8"?>
            <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
            message-id="101"><data>
            <native xmlns="http://cisco.com/ns/yang/ned/ios">
            <version>16.3</version></native></data></rpc-reply>
            >>>

def request(self, msg, timeout=30):
        '''request

        High-level api: sends message through NetConf session and returns with
        a reply. Exception is thrown out either the reply is in wrong
        format or timout. Users can modify timeout value (in seconds) by
        passing parameter timeout. Users may want to set a larger timeout when
        making a large query.

        Parameters
        ----------

        msg : `str`
            Any message need to be sent out in XML format. The message can be
            in wrong format if it is a negative test case. Because ncclient
            tracks same message-id in both rpc and rpc-reply, missing
            message-id in your rpc may cause exception when receiving
            rpc-reply. Most other wrong format rpc's can be sent without
            exception.
        timeout : `int`, optional
            An optional keyed argument to set timeout value in seconds. Its
            default value is 30 seconds.

        Returns
        -------

        str
            The reply from the device in string. If something goes wrong, an
            exception will be raised.


        Raises
        ------

        Exception
            If NetConf is not connected, or there is a timeout when receiving
            reply.


        Code Example::

            >>> from pyats.topology import loader
            >>> testbed = loader.load('/users/xxx/xxx/asr_20_22.yaml')
            >>> device = testbed.devices['asr22']
            >>> device.connect(alias='nc', via='netconf')
            >>> netconf_request = """
            ...     <rpc message-id="101"
            ...      xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
            ...     <get>
            ...     <filter>
            ...     <native xmlns="http://cisco.com/ns/yang/ned/ios">
            ...     <version>
            ...     </version>
            ...     </native>
            ...     </filter>
            ...     </get>
            ...     </rpc>
            ...     """
            >>> reply = device.nc.request(netconf_request)
            >>>

        Expected Results::

            >>> print(reply)
            <?xml version="1.0" encoding="UTF-8"?>
            <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
            message-id="101"><data>
            <native xmlns="http://cisco.com/ns/yang/ned/ios">
            <version>16.3</version></native></data></rpc-reply>
            >>>
        '''

        rpc = RawRPC(session = self.session,
                     device_handler = self._device_handler,
                     timeout = timeout,
                     raise_mode = operations.rpc.RaiseMode.NONE)

        # identify message-id
        m = re.search(r'message-id="([A-Za-z0-9_\-:# ]*)"', msg)
        if m:
            rpc._id = m.group(1)
            rpc._listener.register(rpc._id, rpc)
            logger.debug('Found message-id="%s" in your rpc, which is good.', rpc._id)
        else:
            logger.warning('Cannot find message-id in your rpc. You may '
                           'expect an exception when receiving rpc-reply '
                           'due to missing message-id.')

        return rpc._request(msg).xml