Added a new generic dispatcher operation
[ncclient] / ncclient / operations / retrieve.py
index 9d3d728..041340e 100644 (file)
@@ -20,8 +20,7 @@ import util
 
 class GetReply(RPCReply):
 
-    """Adds attributes for the *data* element to `RPCReply`. This pertains to the `Get` and
-    `GetConfig` operations."""
+    """Adds attributes for the *data* element to `RPCReply`."""
 
     def _parsing_hook(self, root):
         self._data = None
@@ -51,12 +50,14 @@ class Get(RPC):
     "The *get* RPC."
 
     REPLY_CLS = GetReply
+    "See :class:`GetReply`."
 
     def request(self, filter=None):
         """Retrieve running configuration and device state information.
 
-        :param filter: portions of the device configuration to retrieve (by default entire configuration is retrieved)
-        :type filter: :ref:`filter_params`
+        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)
+
+        :seealso: :ref:`filter_params`
         """
         node = new_ele("get")
         if filter is not None:
@@ -69,17 +70,41 @@ class GetConfig(RPC):
     "The *get-config* RPC."
 
     REPLY_CLS = GetReply
+    "See :class:`GetReply`."
 
     def request(self, source, filter=None):
         """Retrieve all or part of a specified configuration.
 
-        :param source: name of the configuration datastore being queried
-        :type source: string
+        *source* name of the configuration datastore being queried
+
+        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)
 
-        :param filter: portions of the device configuration to retrieve (by default entire configuration is retrieved)
-        :type filter: :ref:`filter_params`"""
+        :seealso: :ref:`filter_params`"""
         node = new_ele("get-config")
         node.append(util.datastore_or_url("source", source, self._assert))
         if filter is not None:
             node.append(util.build_filter(filter))
+        return self._request(node)
+
+class Dispatch(RPC):
+    """Generic retrieving wrapper. Eg. dispatch('clear-arp-table') or dispatch element  
+    like :
+    xsd_fetch = new_ele('get-xnm-information')
+    sub_ele(xsd_fetch, 'type').text="xml-schema"
+    sub_ele(xsd_fetch, 'namespace').text="junos-configuration
+    dispatch(xsd_fetch)    
+    to fetch entire xsd sxhema file from Juniper
+    """
+    
+    REPLY_CLS = GetReply
+    
+    def request(self, rpc_command, source=None, filter=None):
+        if ET.iselement(rpc_command):
+            node = rpc_command
+        else:
+            node = new_ele(rpc_command)
+        if source is not None:
+            node.append(util.datastore_or_url("source", source, self._assert))
+        if filter is not None:
+            node.append(util.build_filter(filter))
         return self._request(node)
\ No newline at end of file