core API

The dirt.core module contains all of dirt’s internal functions.

dirt.core.create

Routine used to create the skeleton directory structure for a new project

dirt.core.dbi

dirt’s interface to the CouchDB database. All db interactions happen through a shared instance of the DirtCouchDB class.

class dirt.core.dbi.DirtCouchDB(host, dbname)

wrapper for couchdb that provides some additional dirt-specific functions.

disable_node(fqdn)

set a node’s enabled flag to false

get_nodes()

query db to get node data

get_tasks()

a wrapper for couchdb changes which should never die

push_results(results, id, node_id, gateway)

update task document with results

save(doc)

save a document in the db

dirt.core.dbi.check_requirements(db, id, node)

check if system requirements defined in the task document are satisfied by this node. some reinvention of the query language is worth it for not eval()-ing stuff from the database.

dirt.core.server

The main dirt server function

dirt.core.load_balance

Load-balancing between nodes is achieved with Python generators that yield the next node on which to execute something.

dirt.core.load_balance.load(db, margin=0.9, wait=20)

round-robin using up to n cpus depending on current load

dirt.core.load_balance.round_robin(db)

generates documents of nodes available for execution in a simple round-robin fashion. re-gets the node list from the db each time around.

dirt.core.log

dirt.core.log creates a singleton yelling.Log instance dirt.core.log.log, used for log output throughout dirt.

singleton logger object

dirt.core.yelling

Logging is done with the yelling module, available at https://github.com/mastbaum/yelling.

All logging should happen through dirt.core.log.log, which is a yelling Log object:

class dirt.core.yelling.Log(filename, service_name=None, hoststamp=True, timestamp=True, console=True)

stores all the options for yelling.log, useful for frequent logging without the boatload of options

write(message)

write to log file

Other available yelling functions include:

class dirt.core.yelling.Log(filename, service_name=None, hoststamp=True, timestamp=True, console=True)

stores all the options for yelling.log, useful for frequent logging without the boatload of options

write(message)

write to log file

dirt.core.yelling.email(recipients, subject, message, sender=None)

sends a good, old-fashioned email via smtp

dirt.core.yelling.http_post(url, params)

post some key-value pairs to a url with an http post

dirt.core.yelling.log(filename, message, service_name=None, hoststamp=True, timestamp=True, console=True)

writes a message to a log file. optionally, write a time and hostname stamp like syslog. if you want to customize that, just put it in message.

dirt.core.yelling.sms(phone, carrier, subject, message, sender=None)

sends an sms message to a phone via email. this is a little dicey since carriers may change their domains at any time.

dirt.core.yelling.sms_carriers()

returns a list of known sms carriers