def login_node(self, node_ip): try: self.vmtransport = self.vm.get_transport() dest_addr = (node_ip, 22) #edited# local_addr = (self.server_ip, 22) #edited# vmchannel = self.vmtransport.open_channel("direct-tcpip", dest_addr, local_addr) except paramiko.ChannelException: raise exceptions.HostUnkown('Name or service not known') self.connection = paramiko.SSHClient() self.connection.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: self.connection.connect(node_ip, username=self.node_user, password=self.node_passwd, sock=vmchannel) except paramiko.BadHostKeyException: raise exceptions.BadHostKeyException('Bad Host Keys') except paramiko.AuthenticationException: raise exceptions.AuthenticationFailed('Authentication Failed') except socket.error: raise exceptions.socketerror('Unable to connect') except paramiko.SSHException: raise exceptions.OtherError('Login Error') except: raise exceptions.SshError('ssh Error')
def connect(self): try: self.vm = paramiko.SSHClient() self.vm.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.vm.connect(self.server_ip, username=self.server_user, password=self.server_passwd) except paramiko.BadHostKeyException: raise exceptions.BadHostKeyException('Bad Host Keys') except paramiko.AuthenticationException: raise exceptions.AuthenticationFailed('Authentication Failed') except socket.error: raise exceptions.socketerror('Unable to connect') except paramiko.SSHException: raise exceptions.OtherError('Login Error') except: raise exceptions.SshError('ssh Error')
def connect(server_ip, user, passwd): try: vm = paramiko.SSHClient() vm.set_missing_host_key_policy(paramiko.AutoAddPolicy()) vm.connect(server_ip, username=user, password=passwd) except paramiko.BadHostKeyException: vm = 'BadHostKeyExceptions' raise exceptions.BadHostKeyException('Bad Host Keys') except paramiko.AuthenticationException: vm = 'WrongPassword' raise exceptions.AuthenticationFailed('Authentication Failed') except socket.error: vm = 'socketerror' raise exceptions.socketerror('Unable to connect') except paramiko.SSHException: vm = 'LoginError' raise exceptions.OtherError('Login Error') except: vm = 'LoginError' raise exceptions.SshError('ssh Error') return vm
def telnet_login_node(self, node_ip): try: self.vmtransport = self.vm.get_transport() dest_addr = (node_ip, 23) #edited# local_addr = (self.server_ip, 22) #edited# self.vmchannel = self.vmtransport.open_channel( "direct-tcpip", dest_addr, local_addr) except paramiko.ChannelException: raise exceptions.HostUnkown('Name or service not known') user = self.node_user.encode("utf-8") + b'\r\n' password = self.node_passwd.encode("utf-8") + b'\r\n' self.prompt_telnet = node_ip.encode("utf-8") + b'#' try: self.tn = telnetlib.Telnet() self.tn.sock = self.vmchannel self.tn.read_until(b"username: "******"password: ") self.tn.write(password) except: raise exceptions.SshError('Telnet Error')