more doc updates
[ncclient] / ncclient / operations / session.py
index d954c88..0afa307 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-'Session-related NETCONF operations'
+"Session-related NETCONF operations"
 
-from copy import deepcopy
+from ncclient.xml_ import *
 
 from rpc import RPC
 
 class CloseSession(RPC):
 
-    # TESTED
-
-    "*<close-session>* RPC. The connection to NETCONF server is also closed."
-
-    SPEC = { 'tag': 'close-session' }
-
-    def _delivsery_hook(self):
-        self.session.close()
+    "`close-session` RPC. The connection to NETCONF server is also closed."
 
     def request(self):
-        ":seealso: :ref:`return`"
-        return self._request(CloseSession.SPEC)
+        "Request graceful termination of the NETCONF session, and also close the transport."
+        try:
+            return self._request(new_ele("close-session"))
+        finally:
+            self.session.close()
 
 
 class KillSession(RPC):
 
-    "*<kill-session>* RPC."
-
-    SPEC = {
-        'tag': 'kill-session',
-        'subtree': []
-    }
+    "`kill-session` RPC."
 
     def request(self, session_id):
-        """
-        :arg session_id: *session-id* of NETCONF session to kill
-        :type session_id: `string`
+        """Force the termination of a NETCONF session (not the current one!)
 
-        :seealso: :ref:`return`
+        *session_id* is the session identifier of the NETCONF session to be terminated as a string
         """
-        spec = deepcopy(KillSession.SPEC)
-        if not isinstance(session_id, basestring): # make sure
-            session_id = str(session_id)
-        spec['subtree'].append({
-            'tag': 'session-id',
-            'text': session_id
-        })
-        return self._request(spec)
+        node = new_ele("kill-session")
+        sub_ele(node, "session-id").text = session_id
+        return self._request(node)