cloud_app.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:starwatts-boto 作者: defab-sw 项目源码 文件源码
def through(self, host, user='root'):
        """
        Defines a proxy command to rebound on the host.
        This method is actually unsafe to use and will cause an SSH Banner Error. This library can't work through a
        proxy

        :param string host: Either a valid name stored in ~/.ssh/config or a valid IP address.
        :param string user: A valid user for the host. Default : 'root'.

        :return: This instance. Allows to chain methods.
        :rtype: CloudApp
        """
        ssh_conf_file = os.path.expanduser("~/.ssh/config")
        try:
            ssh_conf = paramiko.SSHConfig()
            with open(ssh_conf_file) as f:
                ssh_conf.parse(f)
            if host in ssh_conf.get_hostnames():
                host_conf = ssh_conf.lookup(host)
                user = host_conf.get('user', 'root')
                host = host_conf.get('hostname')
            else:
                print("Could not find host {} in {}. Using raw hostname.".format(host, ssh_conf_file))
        except FileNotFoundError as e:
            print("Could not load {} : {}. Using raw hostname.".format(ssh_conf_file, e))

        # "ssh -W %h:%p {}@{}" doesn't create an entry in the logs. "ssh {}@{} nc %h %p"
        # Actually connects to name (causing an entry in the logs)
        print("ssh {}@{} nc {} 22".format(user, host, self.instance.private_ip_address))
        self.ssh_sock = paramiko.ProxyCommand("ssh {}@{} nc {} 22".format(user, host, self.instance.private_ip_address))
        return self
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号