本文整理汇总了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)