こんにちは、クラス間でオブジェクトを渡す方法を知りたいです。スクリプトを使用して、最初にサーバーにログインします。クライアント サーバーの隣にあり、ルーターとスイッチではありません。スクリプトは次のとおりです。ファイル名は connect.py です。
import expect
class domain_connect:
def __init__(self,usr='user',pwd='password',d1='192.168.1.3',dclient='192.168.2.3'):
self._usr =us
self._pwd =pwd
self._d1 =d1
self._dclient =dclient
def djump(self):
child=pexpect.spawn('ssh -o StrictHostKeyChecking=no -l ' +self._usr+" "+self._d1)
child.expect('assword:')
child.sendline(self._pwd)
child.expect(':~>')
##Connect to client server
child.sendline(self._dclient)
child.expect('assword:')
child.sendline(self._pwd)
child.expect('accept:')
child.sendline(' ')
child.expect(':~>')
return child
class ce_connect:
def __init__(self, child, ip, usr, pwd, enpwd):
self._child = child
self._ip = ip
self._usr = usr
self._pwd = pwd
self._enpwd = pwd
def cjump(self):
##Connecting to router
child.sendline('ssh -o StrictHostKeyChecking=no -l '+self._usr+' '+self._ip)
return self._child
使用するスクリプトは次のとおりです。
import connect
child = connect.domain_connect()
child = child.djump() ## At this point I'm good toward the client server
子オブジェクトを ce_connect クラスに渡すために次のことをしようとしていました
child2 = connect.ce_connect(child, '192.78.1.20', 'username', 'password', 'password2')
child2 = child2.cjump()
エラーが発生します:
AttributeError: 'spawn' object has no attribute 'djump'