GithubHelp home page GithubHelp logo

oldhammade / runbook.py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from unquietcode/runbook.py

0.0 1.0 0.0 45 KB

a tool for defining repeatable processes in code

License: Apache License 2.0

Python 100.00%

runbook.py's Introduction

runbook.py (v0.2)

pip3 install runbook

Inspired by this blog post by Dan Slimmon.

Define your own run-book in a class extending from Runbook. Every method that doesn't begin with an underscore is read in as a step to be completed, in order. The step name will be built from the method name, and the description is taken either from the method's own docstring or from any data returned from invoking the method.

from runbook import Runbook


class CustomRunbook(Runbook):
   
    def first_step(self):
        """
        Do ABC now.
        """
    
    def second_step():
        """
        Do EFG then wait 1 hour.
        """

    def third_step():
        task = "reboot"
        return f"perform a {task}"
    
    @staticmethod
    def last_step():
        """Everything ok?"""

Every Runbook object comes with a default main method that you can use to execute the script.

if __name__ == '__main__':
    CustomRunbook.main()

The run-book object can also be instantiated and run directly.

book = CustomRunbook(file_path="path/to/file")
book.run()

You should avoid using the step names run and main, which are already defined. If you need to override these methods to define custom behavior then that is fine.

As steps are completed, the results are written out to a log file. You can set a custom log file path by passing an argument to main, as in:

python3 my_runbook.py output.log

When reusing the same log file, already completed steps will be skipped. Any new steps found in the Runbook and not already in the log will be processed as normal, with results appended to the end of the file.

License

Licensed under the Apache Software License 2.0 (ASL 2.0).

runbook.py's People

Contributors

unquietcode avatar

Watchers

James Cloos avatar

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.