Using Python Fabric without the command-line tool (fab)

后端 未结 5 998
旧时难觅i
旧时难觅i 2021-02-01 06:19

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 i

5条回答
  •  既然无缘
    2021-02-01 06:52

    I ended up doing this:

    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')
    

    Which produces:

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

提交回复
热议问题