Giter Site home page Giter Site logo

serf-master's Introduction

Serf Master

Build Status Coverage Status Code Health

Serf is a very nice service discovery and orchestration framework which allows you to write scripts to react to different events across your infrastructure. However most of the examples are simple shell scripts with lots of logic embedded in them. Combine that with per host configuration around registering event handlers and it's easy to build a fiddly, hard to reason about enviroment. It doesn't have to be that way.

Serf is the framework, what you built on top of it matters. I wanted something with the following properties:

  • Testable. I should be able to unit test the entire configuration.
  • Single package. All hosts should get the same code, with the code deciding what runs where.
  • Single event handler. I'd rather deal with logic about user events or roles within my code, rather than parameters to serf.
  • Make handlers sharable. You can simply extend SerfHandler and package up your own handlers, say serf_master_haproxy.

Serf Master tries to do this, presented as a very small Python framework with no dependencies. Here's an example:

An example

Imagine a cluster with a number of database servers and web servers. The database servers have the Serf role of db and the web servers the Serf role of web. We want the web servers to react whenever a new server is added to the cluster (maybe to tell a load balancer to reload?) and we want to be able to trigger a deploy. For the database servers we want to be able to trigger a backup custom event.

#!/usr/bin/env python 
from serf_master import SerfHandler, SerfHandlerProxy

class WebHandler(SerfHandler):
    def deploy(self):
      # run commands here to do with deployment

    def member_join(self):
      # maybe rebalance the load balancer


class DatabaseHandler(SerfHandler):
    def backup(self):
      # run commands here to do with backups


if __name__ == '__main__':
    handler = SerfHandlerProxy()
    handler.register('web', WebHandler())
    handler.register('db', DatabaseHandler())
    handler.run()

The important parts are:

handler.register('web', WebHandler())

This says if the Serf role is web then use the WebHandler class for any events.

def member_join(self):

This says for the member-join serf event we should execute the code we write here.

See the unit tests for examples of now this can be tested.

Configuration

Using this with Serf is simple, just wire up all the event handlers to your script like so:

serf agent -event-handler /opt/your/script.py

Although you could restrict the events which are managed by this handler the whole point of serf-master is to move the handler definition into code and away from command line flags.

Installation

Serf Master is available on PyPi and can be installed with:

pip install serf_master

serf-master's People

Contributors

garethr avatar fmd avatar thedrow avatar tarsisazevedo avatar

Stargazers

Sean Johnson avatar Julian Pistorius avatar Ethan Li avatar Martin Bučko avatar Henry.He avatar A ghost. avatar кірілл avatar Laeeth Isharc avatar Daniel Jay Haskin avatar  avatar Alek Paunov avatar Eric avatar  avatar Simon H. Joergensen avatar Qi Gao avatar Vlada Petrović avatar Jakub Juraszek avatar  avatar Jake Hill avatar Andrew Fernandes avatar Soma Szelpal avatar Kien Nguyen-Tuan avatar  avatar  avatar Martin Hoefling avatar wwc avatar Alexey Kinev avatar 5hun Yanaura avatar Sergio Moya avatar Miguel Elias dos Santos avatar Ben Jones avatar Timothée GERMAIN avatar Fabian Topfstedt avatar Adam Eury avatar Angus H. avatar Fill Quazy avatar Charles Chan avatar Jiamo avatar  avatar  avatar Daniel López avatar Adam Barthelson avatar Sergey Zinovyev avatar amyangfei avatar Scott Hulbert avatar Michael Fairchild avatar  avatar Matthew Skelton avatar Wilson Júnior avatar Alberto Miorin avatar Alexander Dean avatar Brandon Huey avatar Josh Purvis avatar Kouhei Maeda avatar Tim Ski avatar  avatar Dylan Meissner avatar MA Jianjun avatar kinkstruction-admin avatar Vladimir Shulyak avatar Kenichi  Sasaki avatar Kentaro Kawano avatar  avatar Joshua Santiago avatar Isaac Boehman avatar Jeff Schroeder avatar Aaron Bell avatar Bruce Morrison avatar Tomotaka Ito avatar Ryota Arai avatar yimeng avatar Seoester avatar David Pelaez avatar Jameel Al-Aziz avatar  avatar Michael Mayr avatar Derek avatar John Albietz avatar Craig Patten avatar Anthony Scalisi avatar Cosmin L. Neagu avatar Naohisa Orita avatar Matthieu Simonin avatar Grey Lathrop avatar Seth House avatar saidimu apale avatar  avatar Dimitrij Klesev avatar Tobias Bradtke avatar Brian Clements avatar Simon van der Veldt avatar Matt Croydon avatar Adrian Silva avatar Jason Emerick avatar Gavin James avatar Jason Novinger avatar Dan Ryan avatar Chavez avatar Jaime Gil de Sagredo Luna avatar Jonathan Dietz avatar

Watchers

 avatar Stig Kleppe-Jørgensen avatar Fill Quazy avatar Julian Pistorius avatar James Cloos avatar Roger Giuffrè avatar  avatar jitendra kumar avatar Matthieu Simonin avatar space avatar  avatar

serf-master's Issues

Q: How to use handler_test.py ?

There is a subdir with handler_test.py, that doesnt install to my ~/.local/lib/....,

but anyway, the main question is how to use it? Testing the functions of handler using running agent is difficult... Some more manual please..

Thank you
Jarom

The tarball of PyPI has no LICENSE and README.md files

The tarball has no LICENSE and README.md files.

https://pypi.python.org/packages/source/s/serf_master/serf_master-0.3.tar.gz#md5=82819e9d02f333861d3231a8e2c05dcc

$ tar tvf serf_master-0.3.tar.gz 
drwxrwxr-x garethr/garethr   0 2014-03-18 07:10 serf_master-0.3/
-rw-rw-r-- garethr/garethr 520 2014-03-18 07:10 serf_master-0.3/PKG-INFO
drwxrwxr-x garethr/garethr   0 2014-03-18 07:10 serf_master-0.3/serf_master/
-rwxrwxr-x garethr/garethr 1302 2014-03-18 07:02 serf_master-0.3/serf_master/__init__.py
-rw-rw-r-- garethr/garethr   59 2014-03-18 07:10 serf_master-0.3/setup.cfg
-rw-rw-r-- garethr/garethr  773 2014-03-18 07:09 serf_master-0.3/setup.py
drwxrwxr-x garethr/garethr    0 2014-03-18 07:10 serf_master-0.3/serf_master.egg-info/
-rw-rw-r-- garethr/garethr  520 2014-03-18 07:10 serf_master-0.3/serf_master.egg-info/PKG-INFO
-rw-rw-r-- garethr/garethr   12 2014-03-18 07:10 serf_master-0.3/serf_master.egg-info/top_level.txt
-rw-rw-r-- garethr/garethr    1 2014-03-18 07:10 serf_master-0.3/serf_master.egg-info/dependency_links.txt
-rw-rw-r-- garethr/garethr    1 2013-12-23 20:14 serf_master-0.3/serf_master.egg-info/not-zip-safe
-rw-rw-r-- garethr/garethr  206 2014-03-18 07:10 serf_master-0.3/serf_master.egg-info/SOURCES.txt

I clone from github and execute "python setup.py sdist", but this problem did not reproduce.

$ tar tvf dist/serf_master-0.3.tar.gz
drwxr-xr-x mkouhei/mkouhei 0 2014-08-06 17:41 serf_master-0.3/
drwxr-xr-x mkouhei/mkouhei 0 2014-08-06 17:41 serf_master-0.3/serf_master.egg-info/
-rw-r--r-- mkouhei/mkouhei 12 2014-08-06 17:41 serf_master-0.3/serf_master.egg-info/top_level.txt
-rw-r--r-- mkouhei/mkouhei  1 2014-08-06 17:41 serf_master-0.3/serf_master.egg-info/dependency_links.txt
-rw-r--r-- mkouhei/mkouhei 334 2014-08-06 17:41 serf_master-0.3/serf_master.egg-info/SOURCES.txt
-rw-r--r-- mkouhei/mkouhei 520 2014-08-06 17:41 serf_master-0.3/serf_master.egg-info/PKG-INFO
-rw-r--r-- mkouhei/mkouhei   1 2014-08-06 17:41 serf_master-0.3/serf_master.egg-info/not-zip-safe
-rw-r--r-- mkouhei/mkouhei  61 2014-08-06 17:16 serf_master-0.3/.coverage.rc
-rw-r--r-- mkouhei/mkouhei  32 2014-08-06 17:16 serf_master-0.3/.gitignore
-rw-r--r-- mkouhei/mkouhei 773 2014-08-06 17:16 serf_master-0.3/setup.py
-rw-r--r-- mkouhei/mkouhei 3326 2014-08-06 17:16 serf_master-0.3/README.md
-rw-r--r-- mkouhei/mkouhei  167 2014-08-06 17:16 serf_master-0.3/.travis.yml
-rw-r--r-- mkouhei/mkouhei   84 2014-08-06 17:41 serf_master-0.3/setup.cfg
drwxr-xr-x mkouhei/mkouhei    0 2014-08-06 17:41 serf_master-0.3/serf_master/
-rwxr-xr-x mkouhei/mkouhei 1291 2014-08-06 17:16 serf_master-0.3/serf_master/__init__.py
drwxr-xr-x mkouhei/mkouhei    0 2014-08-06 17:41 serf_master-0.3/serf_master/tests/
-rw-r--r-- mkouhei/mkouhei 3953 2014-08-06 17:16 serf_master-0.3/serf_master/tests/handler_test.py
-rw-r--r-- mkouhei/mkouhei    0 2014-08-06 17:16 serf_master-0.3/serf_master/tests/__init__.py
-rw-r--r-- mkouhei/mkouhei  520 2014-08-06 17:41 serf_master-0.3/PKG-INFO
-rw-r--r-- mkouhei/mkouhei 1082 2014-08-06 17:16 serf_master-0.3/LICENSE

Would you re-publish tarball for PyPI?

Best regards,

Install doesn't find setup.py

pip install doesn't work:
IOError: [Errno 2] No such file or directory: '/tmp/pip-build-root/serf-master/setup.py'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.