def rpc(cmd=None, dest=None, format='xml', *args, **kwargs):
 conn = __proxy__['junos.conn']()
 ret = dict()
 ret['out'] = True
 op = dict()
 if ('__pub_arg' in kwargs):
  if isinstance(kwargs['__pub_arg'][(-1)], dict):
   op.update(kwargs['__pub_arg'][(-1)])
 else:
  op.update(kwargs)
 if ((dest is None) and (format != 'xml')):
  log.warning('Format ignored as it is only used for output which is dumped in the file.')
 write_response = ''
 try:
  if (cmd in ['get-config', 'get_config']):
   filter_reply = None
   if ('filter' in op):
    filter_reply = etree.XML(op['filter'])
   xml_reply = getattr(conn.rpc, cmd.replace('-', '_'))(filter_reply, options=op)
   ret['message'] = jxmlease.parse(etree.tostring(xml_reply))
   write_response = etree.tostring(xml_reply)
   if ((dest is not None) and (format != 'xml')):
    op.update({'format': format})
    rpc_reply = getattr(conn.rpc, cmd.replace('-', '_'))(filter_reply, options=op)
    if (format == 'json'):
     write_response = json.dumps(rpc_reply, indent=1)
    else:
     write_response = rpc_reply.text
  else:
   xml_reply = getattr(conn.rpc, cmd.replace('-', '_'))(**op)
   ret['message'] = jxmlease.parse(etree.tostring(xml_reply))
   write_response = etree.tostring(xml_reply)
   if ((dest is not None) and (format != 'xml')):
    rpc_reply = getattr(conn.rpc, cmd.replace('-', '_'))({'format': format}, **op)
    if (format == 'json'):
     write_response = json.dumps(rpc_reply, indent=1)
    else:
     write_response = rpc_reply.text
 except Exception as exception:
  ret['message'] = 'Execution failed due to "{0}"'.format(exception)
  ret['out'] = False
 if (dest is not None):
  with fopen(dest, 'w') as fp:
   fp.write(write_response)
 return ret

def rpc ( cmd = None , dest = None , format = 'xml' , * args , ** kwargs ) : conn = __proxy__ [ 'junos.conn' ] ( ) ret = dict ( ) ret [ 'out' ] = True op = dict ( ) if ( '__pub_arg' in kwargs ) : if isinstance ( kwargs [ '__pub_arg' ] [ ( - 1 ) ] , dict ) : op . update ( kwargs [ '__pub_arg' ] [ ( - 1 ) ] ) else : op . update ( kwargs ) if ( ( dest is None ) and ( format != 'xml' ) ) : log . warning ( 'Format ignored as it is only used for output which is dumped in the file.' ) write_response = '' try : if ( cmd in [ 'get-config' , 'get_config' ] ) : filter_reply = None if ( 'filter' in op ) : filter_reply = etree . XML ( op [ 'filter' ] ) xml_reply = getattr ( conn . rpc , cmd . replace ( '-' , '_' ) ) ( filter_reply , options = op ) ret [ 'message' ] = jxmlease . parse ( etree . tostring ( xml_reply ) ) write_response = etree . tostring ( xml_reply ) if ( ( dest is not None ) and ( format != 'xml' ) ) : op . update ( { 'format' : format } ) rpc_reply = getattr ( conn . rpc , cmd . replace ( '-' , '_' ) ) ( filter_reply , options = op ) if ( format == 'json' ) : write_response = json . dumps ( rpc_reply , indent = 1 ) else : write_response = rpc_reply . text else : xml_reply = getattr ( conn . rpc , cmd . replace ( '-' , '_' ) ) ( ** op ) ret [ 'message' ] = jxmlease . parse ( etree . tostring ( xml_reply ) ) write_response = etree . tostring ( xml_reply ) if ( ( dest is not None ) and ( format != 'xml' ) ) : rpc_reply = getattr ( conn . rpc , cmd . replace ( '-' , '_' ) ) ( { 'format' : format } , ** op ) if ( format == 'json' ) : write_response = json . dumps ( rpc_reply , indent = 1 ) else : write_response = rpc_reply . text except Exception as exception : ret [ 'message' ] = 'Execution failed due to "{0}"' . format ( exception ) ret [ 'out' ] = False if ( dest is not None ) : with fopen ( dest , 'w' ) as fp : fp . write ( write_response ) return ret
executes the given rpc .