#: 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.
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.
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