在不使用命令行工具(fab)的情况下使用Python Fabric [英] Using Python Fabric without the command-line tool (fab)

查看:166
本文介绍了在不使用命令行工具(fab)的情况下使用Python Fabric的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Altough Fabric文档是一种无需fab命令行工具和/或任务即可使用库进行SSH访问的方法,我似乎无法管理一种实现方法.

Altough Fabric documentations refers to a way of using the library for SSH access without requiring the fab command-line tool and/or tasks, I can't seem to manage a way to do it.

我想通过仅执行' python example.py ':

env.hosts = [ "example.com" ]
def ps():
    run("ps")
ps()

谢谢.

推荐答案

我最终这样做:

from fabric.api import env
from fabric.api import run

class FabricSupport:
    def __init__ (self):
        pass

    def run(self, host, port, command):
        env.host_string = "%s:%s" % (host, port)
        run(command)

myfab = FabricSupport()

myfab.run('example.com', 22, 'uname')

哪个会产生:

[example.com:22] run: uname
[example.com:22] out: Linux

这篇关于在不使用命令行工具(fab)的情况下使用Python Fabric的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆