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

    Usage:

    .. code-block:: bash

        salt 'device' junos.call_rpc 'get_config' '<configuration><system/></configuration>' terse=True

        salt 'device' junos.call_rpc 'get-chassis-inventory' dest=/home/user/rpc_information.txt


    Options:
      * cmd: the rpc to be executed
      * args: other arguments as taken by rpc call of PyEZ
      * kwargs: keyworded arguments taken by rpc call of PyEZ
    '''
    conn = __proxy__['junos.conn']()
    ret = dict()
    ret['out'] = True

    op = dict()
    if '__pub_arg' in kwargs and isinstance(kwargs['__pub_arg'][-1], dict):
        op.update(kwargs['__pub_arg'][-1])
    else:
        op.update(kwargs)

    for k, v in op.iteritems():
        op[k] = str(v)
    op['format'] = 'json'

    try:
        if cmd in ['get-config', 'get_config']:
            filter_reply = None
            if len(args) > 0:
                filter_reply = etree.XML(args[0])
            ret['message'] = getattr(conn.rpc, cmd.replace('-', '_'))(filter_reply, options=op)
        else:
            ret['message'] = getattr(conn.rpc, cmd.replace('-', '_'))(op)

    except Exception as exception:

        ret['message'] = 'Execution failed due to "{0}"'.format(exception)
        ret['out'] = False

    if 'dest' in op:
        f = open(op['dest'], 'w')
        f.write(ret['message'])
        f.close()

    return ret
dataset/ETHPy150Open saltstack/salt/salt/modules/junos.py/call_rpc/original