本文整理匯總了Python中twisted.conch.endpoints.SSHCommandClientEndpoint.existingConnection方法的典型用法代碼示例。如果您正苦於以下問題:Python SSHCommandClientEndpoint.existingConnection方法的具體用法?Python SSHCommandClientEndpoint.existingConnection怎麽用?Python SSHCommandClientEndpoint.existingConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.conch.endpoints.SSHCommandClientEndpoint
的用法示例。
在下文中一共展示了SSHCommandClientEndpoint.existingConnection方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create
# 需要導入模塊: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 別名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import existingConnection [as 別名]
def create(self):
"""
Create and return a new L{SSHCommandClientEndpoint} using the
C{existingConnection} constructor.
"""
factory = Factory()
factory.protocol = Protocol
connected = self.endpoint.connect(factory)
# Please, let me in. This kinda sucks.
channelLookup = self.realm.channelLookup.copy()
try:
self.realm.channelLookup[b'session'] = WorkingExecSession
server, client, pump = self.connectedServerAndClient(
self.factory, self.reactor.tcpClients[0][2])
finally:
self.realm.channelLookup.clear()
self.realm.channelLookup.update(channelLookup)
self._server = server
self._client = client
self._pump = pump
protocol = self.successResultOf(connected)
connection = protocol.transport.conn
return SSHCommandClientEndpoint.existingConnection(
connection, b"/bin/ls -l")
示例2: spawnProcess
# 需要導入模塊: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 別名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import existingConnection [as 別名]
def spawnProcess(self, protocol, command):
factory = Factory()
factory.protocol = lambda: _CommandProtocol(protocol)
e = SSHCommandClientEndpoint.existingConnection(
self.master_proto.transport.conn, command)
d = e.connect(factory)
return d.addCallback(self._commandStarted)
示例3: executeNewCommand
# 需要導入模塊: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 別名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import existingConnection [as 別名]
def executeNewCommand(self, line):
factory = Factory()
factory.protocol = MyProtocol
e = SSHCommandClientEndpoint.existingConnection(self.ssh_conn,
line.strip())
d = e.connect(factory)
d.addCallback(self.protoStarted)
示例4: exec_command
# 需要導入模塊: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 別名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import existingConnection [as 別名]
def exec_command(self, command):
conn = self.transport.conn
factory = protocol.Factory()
factory.protocol = SingleCommandProtocol
e = SSHCommandClientEndpoint.existingConnection(conn, command)
d = e.connect(factory)
d.addCallback(lambda p: p.finished)
return d
示例5: _spawnProcess
# 需要導入模塊: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 別名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import existingConnection [as 別名]
def _spawnProcess(self, protocol, command):
vvvv('ACTUALLY SPAWN: %r' % (command,))
factory = Factory()
factory.protocol = lambda: _CommandProtocol(protocol)
e = SSHCommandClientEndpoint.existingConnection(
self.master_proto.transport.conn,
command)
d = e.connect(factory)
vvvv('STARTING')
return d.addCallbacks(self._commandStarted, self._commandFailedToStart)
示例6: perform_run
# 需要導入模塊: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 別名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import existingConnection [as 別名]
def perform_run(dispatcher, intent):
context.bind(
message_type="flocker.provision.ssh:run",
command=intent.log_command_filter(intent.command),
).write()
endpoint = SSHCommandClientEndpoint.existingConnection(
connection, intent.command)
d = Deferred()
connectProtocol(endpoint, CommandProtocol(
deferred=d, context=context))
return d
示例7: gotConnection
# 需要導入模塊: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 別名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import existingConnection [as 別名]
def gotConnection(proto):
conn = proto.transport.conn
for i in range(50):
factory = Factory()
factory.protocol = PrinterProtocol
factory.done = Deferred()
done.append(factory.done)
e = SSHCommandClientEndpoint.existingConnection(
conn, b"/bin/echo %d" % (i,))
yield e.connect(factory)
示例8: fork
# 需要導入模塊: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 別名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import existingConnection [as 別名]
def fork(self, command, args=(), env={}, path=None, timeout=3600):
if not self.connection:
log.msg("Connection to %s not yet ready" % (
self.hostname,))
return defer.maybeDeferred(lambda: (None, "SSH not ready", 255))
if env:
env = ' '.join('%s=%s' % (k, v) for k, v in env.items()) + ' '
else:
env = ''
if args:
args = ' ' + ' '.join(args)
else:
args = ''
e = SSHCommandClientEndpoint.existingConnection(self.connection,
(env + command + args).encode())
factory = protocol.Factory()
factory.protocol = SSHCommandProtocol
factory.done = defer.Deferred()
def finished(result):
stdout, stderr, code = result
return (stdout.read(), stderr.read(), code)
factory.done.addCallback(finished)
def connected(connection):
# Be nice if Conch exposed this better...
connection.transport.extReceived = connection.extReceived
return factory.done
return e.connect(factory).addCallback(connected)