address issue 8
[ncclient] / ncclient / manager.py
index 8bcd423..0705b9e 100644 (file)
@@ -35,6 +35,23 @@ def connect_ssh(*args, **kwds):
 #: Same as :meth:`connect_ssh`
 connect = connect_ssh
 
+OPERATIONS = {
+    "get": operations.Get,
+    "get_config": operations.GetConfig,
+    "edit_config": operations.EditConfig,
+    "copy_config": operations.CopyConfig,
+    "validate": operations.Validate,
+    "commit": operations.Commit,
+    "discard_changes": operations.DiscardChanges,
+    "delete_config": operations.DeleteConfig,
+    "lock": operations.Lock,
+    "unlock": operations.Unlock,
+    "close_session": operations.CloseSession,
+    "kill_session": operations.KillSession,
+    "poweroff_machine": operations.PoweroffMachine,
+    "reboot_machine": operations.RebootMachine
+}
+
 class Manager(object):
 
     """API for NETCONF operations.
@@ -56,16 +73,15 @@ class Manager(object):
         return False
 
     def __getattr__(self, name):
-        try:
-            op = operations.INDEX[name]
-        except KeyError:
+        op = OPERATIONS.get(name, None)
+        if op is None:
             raise AttributeError
         else:
             return op(self.session,
                       async=self._async_mode,
-                      timeout=self.timeout,
+                      timeout=self._timeout,
                       raise_mode=self._raise_mode).request
-
+    
     def locked(self, target):
         """Returns a context manager for the *with* statement.
 
@@ -78,10 +94,11 @@ class Manager(object):
     def close(self):
         """Closes the NETCONF session. First does *<close-session>* RPC."""
         try: # try doing it clean
+            self._async_mode = False
             self.close_session()
         except Exception as e:
             logger.debug('error doing <close-session> -- %r' % e)
-        if self._session.connected: # if that didn't work...
+        if self._session.connected: # if that didn't work, this sure will :)
             self._session.close()
 
     @property