Hi all, please help, there's a class
import paramiko import time import subprocess import telnetlib class Base(object): def __init__(self, args): self.args = args def __enter__(self): self.con = self._connect() return self.con def __exit__(self, type, value, traceback): self.con.close() def run(self, *args, **kwargs): raise NotImplementedError('Abstract method not implemented.') def _connect(self, **kwargs): raise NotImplementedError('Abstract method not implemented.') class Paramiko(Base): def __init__(self, args): Base.__init__(self, args) def _connect(self): self.con = paramiko.SSHClient() self.con.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.con.connect(hostname=self.args.host, port=self.args.port, username=self.args.user, password=self.args.password) return self.con def _response(self, channel): while not channel.recv_ready(): time.sleep(0.1) stdout =" while channel.recv_ready(): stdout += channel.recv(1024) return stdout def _send_connect(self, cmd): with Base(self.args) connect as: channel = connect.invoke_shell() self._response(channel) channel.send(cmd+'\') return self._response(channel) def run(self, cmd): try: return(self._send_connect(cmd)) except paramiko.ssh_exception.AuthenticationException as e: return(e)
I call it from another class like so
Paramiko(args).run(cmd)
as you can see I Base is the base class for Paramiko, please tell me how to do so would be when I in the base class call the method __enter__ which is the call to self._connect() method worked _connect() of child class i.e. Paramiko and if it is not there then throw Abstract method not implemented. from the base.
I hope clearly wrote what I need), thanks