本文整理汇总了Python中twisted.conch.endpoints.SSHCommandClientEndpoint.newConnection方法的典型用法代码示例。如果您正苦于以下问题:Python SSHCommandClientEndpoint.newConnection方法的具体用法?Python SSHCommandClientEndpoint.newConnection怎么用?Python SSHCommandClientEndpoint.newConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.conch.endpoints.SSHCommandClientEndpoint
的用法示例。
在下文中一共展示了SSHCommandClientEndpoint.newConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_endpoint
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def _get_endpoint(self):
""" Creates a generic endpoint connection that doesn't finish
"""
return SSHCommandClientEndpoint.newConnection(
reactor, b'/bin/cat', self.username, self.hostname,
port=self.port, keys=self.keys, password=self.password,
knownHosts = self.knownHosts)
示例2: test_mismatchedHostKey
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def test_mismatchedHostKey(self):
"""
If the SSH public key presented by the SSH server does not match the
previously remembered key, as reported by the L{KnownHostsFile}
instance use to construct the endpoint, for that server, the
L{Deferred} returned by L{SSHCommandClientEndpoint.connect} fires with
a L{Failure} wrapping L{HostKeyChanged}.
"""
differentKey = Key.fromString(privateDSA_openssh).public()
knownHosts = KnownHostsFile(self.mktemp())
knownHosts.addHostKey(self.serverAddress.host, differentKey)
knownHosts.addHostKey(self.hostname, differentKey)
# The UI may answer true to any questions asked of it; they should
# make no difference, since a *mismatched* key is not even optionally
# allowed to complete a connection.
ui = FixedResponseUI(True)
endpoint = SSHCommandClientEndpoint.newConnection(
self.reactor, b"/bin/ls -l", b"dummy user",
self.hostname, self.port, password=b"dummy password",
knownHosts=knownHosts, ui=ui)
factory = Factory()
factory.protocol = Protocol
connected = endpoint.connect(factory)
server, client, pump = self.connectedServerAndClient(
self.factory, self.reactor.tcpClients[0][2])
f = self.failureResultOf(connected)
f.trap(HostKeyChanged)
示例3: test_connectionCancelledBeforeSecure
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def test_connectionCancelledBeforeSecure(self):
"""
If the connection is cancelled before the SSH transport layer has
finished key exchange (ie, gotten to the point where we may attempt to
authenticate), the L{Deferred} returned by
L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
L{CancelledError} and the connection is aborted.
"""
endpoint = SSHCommandClientEndpoint.newConnection(
self.reactor, b"/bin/ls -l", b"dummy user",
self.hostname, self.port, knownHosts=self.knownHosts,
ui=FixedResponseUI(False))
factory = Factory()
factory.protocol = Protocol
d = endpoint.connect(factory)
transport = AbortableFakeTransport(None, isServer=False)
factory = self.reactor.tcpClients[0][2]
client = factory.buildProtocol(None)
client.makeConnection(transport)
d.cancel()
self.failureResultOf(d).trap(CancelledError)
self.assertTrue(transport.aborted)
# Make sure the connection closing doesn't result in unexpected
# behavior when due to cancellation:
client.connectionLost(Failure(ConnectionDone()))
示例4: main
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def main(reactor):
ep = SSHCommandClientEndpoint.newConnection(
reactor, b'/bin/cat',
details['USER'],
details['HOST'],
port=details['PORT'],
password=details['PASSWORD'],
agentEndpoint=None,
knownHosts=None)
factory = Factory()
factory.protocol = MyProtocol
d = ep.connect(factory)
def gotConnection(proto):
# stdio interface
stdio_proto = StdinProto(proto.transport.conn)
stdio.StandardIO(stdio_proto)
# factory = Factory()
# factory.protocol = MyProtocol
# e = SSHCommandClientEndpoint.existingConnection(conn, b"/bin/echo hey")
# return e.connect(factory).addCallback(lambda proto: proto.finished)
return stdio_proto.finished
return d.addCallback(gotConnection)
示例5: connect
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def connect(sdata, command, username, host, port=22, key_file=None, password=None):
"""
Connect to an SSH host (as it happens, persistently).
"""
sdata.set_conn_state('connecting')
try:
keys = [Key.fromFile(key_file)] if key_file else None
except exceptions.IOError as e:
print('### key load error:', str(e))
push_failure_message(str(e), sdata)
return
endpoint = SSHCommandClientEndpoint.newConnection(
reactor, command, username, host, port=int(port),
keys=keys, password=password, ui=None,
knownHosts=PermissiveKnownHosts())
factory = Factory()
factory.protocol = LineProtocol
factory.sdata = sdata
d = endpoint.connect(factory)
# Very small race condition between here and the replacement
# in connectionMade() above, but I've never managed to hit it.
def disconnect():
sdata.log('Disconnecting while still attempting to connect, by request')
d.cancel()
sdata.transport_drop_cb = disconnect
d.addErrback(lambda reason: push_failure_message(reason, sdata))
return d
示例6: execute
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def execute(self):
"""Execute the CLI command"""
cmd = " ".join(self.cmd)
LOGGER.debug('Executing {0}'.format(cmd))
endpoint = SSHCommandClientEndpoint.newConnection(reactor,
b"{0}".format(cmd), self.config.get('username'),
self.config.get('host'),
port=self.config.get('port', 22),
password=self.config.get('passsword'),
agentEndpoint=self.agent_endpoint,
keys=self.keys,
knownHosts=self.known_hosts)
factory = protocol.Factory()
factory.protocol = AsteriskRemoteProtocol
def _nominal(param):
self.exitcode = 0
self.output = param.output
self.err = self.output
LOGGER.debug('Remote Asterisk process completed successfully')
return self
def _error(param):
self.exitcode = -1
self.output = param.value.output
self.err = self.output
LOGGER.warning('Remote Asterisk process failed: {0}'.format(self.err))
return Failure(self)
deferred = endpoint.connect(factory)
deferred.addCallback(lambda proto: proto.finished)
deferred.addCallbacks(_nominal, _error)
return deferred
示例7: test_passwordAuthenticationFailure
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def test_passwordAuthenticationFailure(self):
"""
If the SSH server rejects the password presented during authentication,
the L{Deferred} returned by L{SSHCommandClientEndpoint.connect} fires
with a L{Failure} wrapping L{AuthenticationFailed}.
"""
endpoint = SSHCommandClientEndpoint.newConnection(
self.reactor, b"/bin/ls -l", b"dummy user",
self.hostname, self.port, password=b"dummy password",
knownHosts=self.knownHosts, ui=FixedResponseUI(False))
factory = Factory()
factory.protocol = Protocol
connected = endpoint.connect(factory)
server, client, pump = self.connectedServerAndClient(
self.factory, self.reactor.tcpClients[0][2])
# For security, the server delays password authentication failure
# response. Advance the simulation clock so the client sees the
# failure.
self.reactor.advance(server.service.passwordDelay)
# Let the failure response traverse the "network"
pump.flush()
f = self.failureResultOf(connected)
f.trap(AuthenticationFailed)
# XXX Should assert something specific about the arguments of the
# exception
self.assertClientTransportState(client, False)
示例8: test_publicKeyAuthenticationFailure
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def test_publicKeyAuthenticationFailure(self):
"""
If the SSH server rejects the key pair presented during authentication,
the L{Deferred} returned by L{SSHCommandClientEndpoint.connect} fires
with a L{Failure} wrapping L{AuthenticationFailed}.
"""
badKey = Key.fromString(privateRSA_openssh)
self.setupKeyChecker(self.portal, {self.user: privateDSA_openssh})
endpoint = SSHCommandClientEndpoint.newConnection(
self.reactor, b"/bin/ls -l", self.user,
self.hostname, self.port, keys=[badKey],
knownHosts=self.knownHosts, ui=FixedResponseUI(False))
factory = Factory()
factory.protocol = Protocol
connected = endpoint.connect(factory)
server, client, pump = self.connectedServerAndClient(
self.factory, self.reactor.tcpClients[0][2])
f = self.failureResultOf(connected)
f.trap(AuthenticationFailed)
# XXX Should assert something specific about the arguments of the
# exception
# Nothing useful can be done with the connection at this point, so the
# endpoint should close it.
self.assertTrue(client.transport.disconnecting)
示例9: test_interface
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def test_interface(self):
"""
L{SSHCommandClientEndpoint} instances provide L{IStreamClientEndpoint}.
"""
endpoint = SSHCommandClientEndpoint.newConnection(
self.reactor, b"dummy command", b"dummy user",
self.hostname, self.port)
self.assertTrue(verifyObject(IStreamClientEndpoint, endpoint))
示例10: create
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def create(self):
"""
Create and return a new L{SSHCommandClientEndpoint} using the
C{newConnection} constructor.
"""
return SSHCommandClientEndpoint.newConnection(
self.reactor, b"/bin/ls -l", self.user, self.hostname, self.port,
password=self.password, knownHosts=self.knownHosts,
ui=FixedResponseUI(False))
示例11: _endpoint_for_command
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def _endpoint_for_command(self, command):
return SSHCommandClientEndpoint.newConnection(
self.reactor, command, self.username, self.host,
port=self.port,
password=self.password,
keys=self.keys,
agentEndpoint=self.agent,
knownHosts=self.knownHosts,
ui=self.ui
)
示例12: connectionMade
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def connectionMade(self):
script_dir = os.getcwd()
rel_path = "hostkeys"
abs_file_path = os.path.join(script_dir, rel_path)
knownHosts = KnownHostsFile.fromPath(abs_file_path)
self.point = SSHCommandClientEndpoint.newConnection(reactor, 'cmd', 'user', '127.0.0.1', port=5122,
password='password', knownHosts=PermissiveKnownHosts())
self.sshSide = FzSSHClient()
self.sshSide.tcpSide = self
connectProtocol(self.point, self.sshSide)
示例13: _connect
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def _connect(self, params):
ep = SSHCommandClientEndpoint.newConnection(
reactor,
b'/bin/cat',
params['username'],
params['hostname'],
port=params['port'],
password=params['password'],
agentEndpoint=None,
knownHosts=EveryoneIsAKnownHostsFile())
factory = Factory()
factory.protocol = _PersistentProtocol
return ep.connect(factory).addCallback(self._connected)
示例14: _connect
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def _connect(self, host, port, user, password, private_key_file):
keys = [Key.fromFile(private_key_file)]
ep = SSHCommandClientEndpoint.newConnection(
reactor,
b'/bin/cat',
user,
host,
port=port,
password=password,
keys=keys,
agentEndpoint=None,
knownHosts=EveryoneIsAKnownHostsFile())
factory = Factory()
factory.protocol = _PersistentProtocol
return ep.connect(factory).addCallback(self._connected)
示例15: test_connectionCancelledBeforeConnected
# 需要导入模块: from twisted.conch.endpoints import SSHCommandClientEndpoint [as 别名]
# 或者: from twisted.conch.endpoints.SSHCommandClientEndpoint import newConnection [as 别名]
def test_connectionCancelledBeforeConnected(self):
"""
If the connection is cancelled before it finishes connecting, the
connection attempt is stopped.
"""
endpoint = SSHCommandClientEndpoint.newConnection(
self.reactor, b"/bin/ls -l", b"dummy user",
self.hostname, self.port, knownHosts=self.knownHosts,
ui=FixedResponseUI(False))
factory = Factory()
factory.protocol = Protocol
d = endpoint.connect(factory)
d.cancel()
self.failureResultOf(d).trap(ConnectingCancelledError)
self.assertTrue(self.reactor.connectors[0].stoppedConnecting)