• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python endpoints.SSHCommandClientEndpoint类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twisted.conch.endpoints.SSHCommandClientEndpoint的典型用法代码示例。如果您正苦于以下问题:Python SSHCommandClientEndpoint类的具体用法?Python SSHCommandClientEndpoint怎么用?Python SSHCommandClientEndpoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SSHCommandClientEndpoint类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: create

    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")
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:29,代码来源:test_endpoints.py


示例2: main

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)
开发者ID:moldit,项目名称:mold,代码行数:28,代码来源:ssh2.py


示例3: spawnProcess

 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)
开发者ID:moldit,项目名称:mold,代码行数:7,代码来源:ssh.py


示例4: connect

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
开发者ID:cisco,项目名称:xr-telemetry-m2m-web,代码行数:33,代码来源:ssh.py


示例5: test_mismatchedHostKey

    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)
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:32,代码来源:test_endpoints.py


示例6: execute

    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
开发者ID:colinsung,项目名称:testsuite,代码行数:34,代码来源:asterisk.py


示例7: test_connectionCancelledBeforeSecure

    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()))
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:28,代码来源:test_endpoints.py


示例8: test_passwordAuthenticationFailure

    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)
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:32,代码来源:test_endpoints.py


示例9: _get_endpoint

 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)
开发者ID:calston,项目名称:tensor,代码行数:7,代码来源:ssh.py


示例10: test_publicKeyAuthenticationFailure

    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)
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:29,代码来源:test_endpoints.py


示例11: executeNewCommand

    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)
开发者ID:moldit,项目名称:mold,代码行数:8,代码来源:ssh2.py


示例12: test_interface

 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))
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:8,代码来源:test_endpoints.py


示例13: exec_command

    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
开发者ID:GaretJax,项目名称:ipd,代码行数:9,代码来源:ssh.py


示例14: _endpoint_for_command

 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
     )
开发者ID:gcgirish-radisys,项目名称:voltha,代码行数:10,代码来源:rcmd.py


示例15: connectionMade

 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)
开发者ID:matanmaz,项目名称:SshTelnetProxy,代码行数:10,代码来源:TcpSshConverter.py


示例16: _spawnProcess

 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)
开发者ID:iffy,项目名称:ansible,代码行数:10,代码来源:tx.py


示例17: perform_run

 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
开发者ID:wangbinxiang,项目名称:flocker,代码行数:11,代码来源:_conch.py


示例18: gotConnection

    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)
开发者ID:wellbehavedsoftware,项目名称:wbs-graphite,代码行数:12,代码来源:echoclient_shared_ssh.py


示例19: _connect

 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)
开发者ID:moldit,项目名称:mold,代码行数:13,代码来源:ssh.py


示例20: _connect

 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)
开发者ID:iffy,项目名称:ansible,代码行数:15,代码来源:tx.py



注:本文中的twisted.conch.endpoints.SSHCommandClientEndpoint类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python interfaces.ISession类代码示例发布时间:2022-05-27
下一篇:
Python knownhosts.KnownHostsFile类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap