This function executes the RPC provided as arguments on the junos device.
    The returned data can be stored in a file.

    cmd
        The RPC to be executed

    dest
        Destination file where the RPC output is stored. Note that the file
        will be stored on the proxy minion. To push the files to the master use
        :py:func:`cp.push <salt.modules.cp.push>`.

    format : xml
        The format in which the RPC reply is received from the device

    dev_timeout : 30
        The NETCONF RPC timeout (in seconds)

    filter
        Used with the ``get-config`` RPC to get specific configuration

    terse : False
        Amount of information you want

    interface_name
      Name of the interface to query

    CLI Example:

    .. code-block:: bash

        salt 'device' junos.rpc get_config /var/log/config.txt format=text filter='<configuration><system/></configuration>'
        salt 'device' junos.rpc get-interface-information /home/user/interface.xml interface_name='lo0' terse=True
        salt 'device' junos.rpc get-chassis-inventory

def rpc(cmd=None, dest=None, **kwargs):
    '''
    This function executes the RPC provided as arguments on the junos device.
    The returned data can be stored in a file.

    cmd
        The RPC to be executed

    dest
        Destination file where the RPC output is stored. Note that the file
        will be stored on the proxy minion. To push the files to the master use
        :py:func:`cp.push <salt.modules.cp.push>`.

    format : xml
        The format in which the RPC reply is received from the device

    dev_timeout : 30
        The NETCONF RPC timeout (in seconds)

    filter
        Used with the ``get-config`` RPC to get specific configuration

    terse : False
        Amount of information you want

    interface_name
      Name of the interface to query

    CLI Example:

    .. code-block:: bash

        salt 'device' junos.rpc get_config /var/log/config.txt format=text filter='<configuration><system/></configuration>'
        salt 'device' junos.rpc get-interface-information /home/user/interface.xml interface_name='lo0' terse=True
        salt 'device' junos.rpc get-chassis-inventory
    '''

    conn = __proxy__['junos.conn']()
    ret = {}
    ret['out'] = True

    if cmd is None:
        ret['message'] = 'Please provide the rpc to execute.'
        ret['out'] = False
        return ret

    format_ = kwargs.pop('format', 'xml')
    if not format_:
        format_ = 'xml'

    op = dict()
    if '__pub_arg' in kwargs:
        if kwargs['__pub_arg']:
            if isinstance(kwargs['__pub_arg'][-1], dict):
                op.update(kwargs['__pub_arg'][-1])
    elif '__pub_schedule' in kwargs:
        for key, value in six.iteritems(kwargs):
            if not key.startswith('__pub_'):
                op[key] = value
    else:
        op.update(kwargs)

    if cmd in ['get-config', 'get_config']:
        filter_reply = None
        if 'filter' in op:
            filter_reply = etree.XML(op['filter'])
            del op['filter']

        op.update({'format': format_})
        try:
            reply = getattr(
                conn.rpc,
                cmd.replace('-',
                            '_'))(filter_reply,
                                  options=op)
        except Exception as exception:
            ret['message'] = 'RPC execution failed due to "{0}"'.format(
                exception)
            ret['out'] = False
            return ret
    else:
        if 'filter' in op:
            log.warning(
                'Filter ignored as it is only used with "get-config" rpc')
        try:
            reply = getattr(
                conn.rpc,
                cmd.replace('-',
                            '_'))({'format': format_},
                                  **op)
        except Exception as exception:
            ret['message'] = 'RPC execution failed due to "{0}"'.format(
                exception)
            ret['out'] = False
            return ret

    if format_ == 'text':
        # Earlier it was ret['message']
        ret['rpc_reply'] = reply.text
    elif format_ == 'json':
        # Earlier it was ret['message']
        ret['rpc_reply'] = reply
    else:
        # Earlier it was ret['message']
        ret['rpc_reply'] = jxmlease.parse(etree.tostring(reply))

    if dest:
        if format_ == 'text':
            write_response = reply.text
        elif format_ == 'json':
            write_response = salt.utils.json.dumps(reply, indent=1)
        else:
            write_response = etree.tostring(reply)
        with salt.utils.files.fopen(dest, 'w') as fp:
            fp.write(salt.utils.stringutils.to_str(write_response))
    return ret