fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fab-user] Can fabric be used this way?


From: address@hidden
Subject: [Fab-user] Can fabric be used this way?
Date: Wed, 5 Jun 2013 08:58:45 -0700 (PDT)

Fabric makes it really easy to run commands on another server and it seems it's intended purpose it to write code independently of the server it will be run on. Then you can point that code at the server you want at invocation time.

I'm trying to create a tool to monitor the health of my application. It will check the status of various email accounts and database tables which has nothing to do with fabric but I want it to also check server connectivity like: Can server A connect to server B, can server B connect to servers C & D and the database on server E. These things can be verified from the command line and fabric seems like it would be a perfect fit.

However I seem to have trouble getting fabric to do this for me. Obviously I don't need, in fact do not want, to specify the servers on the command line, I need to do different things on each server. I want that knowledge, what gets done on each server, to be in the monitor code.

So I can do something like this:

    from __future__ import with_statement
    from fabric.api import local, settings, abort, run, cd, hosts, hide
    from fabric.contrib.console import confirm
    from fabric.api import env

    @hosts('server1')
    def part1():
        with hide('output'):
            stuff = run(... stuff I want done on server 1 ... )

    @hosts('server0')
    def part2():
        with hide('output'):
            stuff = run(... stuff I want done on server 0 ...)

And I can run either part from the command without specifying the server:

    fab -f testfab.py part1
    fab -f testfab.py part2

But I want one command that can be launched from a cron job and can collect the statuses of various tests and produce one summary email, also I want to do stuff that doesn't need fabric. So, if I add a runall function to this program:

    def runall():
        checkemail()
        checkdb()
        part1()
        part2()
        sendemail()

And try to run 

    fab -f testfab.py runall

I get 

    "No hosts found. Please specify (single) host string for connection:"

I've also tried env.hosts = ['server1'] within the various functions that need to talk instead of the @hosts() mechanism and that didn't work either.

The last thing I tried was specifying an unnecessary server in front of runall() assuming it would be overwritten by the server specification of the other functions such as

    @hosts('server0')
    def runall():
        ....

It just makes part1() and part2() both run on server0

Ideally I wish I could just pass the server to the run function along with the command to be run, or a setserver() function I could call at the start of each function that will be doing fabric stuff. But fabric is not designed that way.

Can fabric accommodate what I'm trying to do?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]