Giter VIP home page Giter VIP logo

operator's Introduction

Operator Framework for Charms

This framework is not yet stable and is subject to change, but is available for early testing.

Getting Started

Start by creating a charm directory with at least the following files:

  • src/charm.py (must be executable and use Python 3.6+)
  • hooks/install (or hooks/start for K8s charms) sym-linked to ../src/charm.py
  • metadata.yaml

Then install the framework into the lib/ directory using:

mkdir lib/
pip install -t lib/ https://github.com/canonical/operator

Your src/charm.py is the entry point for your charm logic. At a minimum, it needs to define a subclass of CharmBase and pass that into the framework's main function:

import sys
sys.path.insert.append('lib')

from ops.charm import CharmBase
from ops.main import main

class MyCharm(CharmBase):
    pass


if __name__ == "__main__":
    main(MyCharm)

This charm does nothing, though, so you'll typically want to observe some Juju events, such as start:

class MyCharm(CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        self.framework.observe(self.on.start, self.on_start)

     def on_start(self, event):
        # Handle the event here.

Every standard event in Juju may be observed that way, and you can also easily define your own events in your custom types.

Once your charm is ready, deploy it as normal with:

juju deploy .

You can sync subsequent changes from the framework by running the pip command again with --upgrade.

operator's People

Contributors

dshcherb avatar johnsca avatar niemeyer avatar jameinel avatar

Watchers

James Cloos avatar  avatar

Forkers

timclicks

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.