Skip to content

Juju Operator Framework Charm Interface for MySQL & MariaDB Relations

License

Notifications You must be signed in to change notification settings

canonical/ops-lib-mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Juju Operator Framework Charm Interface for MySQL & MariaDB Relations

PyPI version PyPI Supported Python Versions GitHub license GitHub Actions (Tests)

To use this interface in your Juju Operator Framework charm, instruct charmcraft to embed it into your built Operator Framework charm by adding ops-lib-mysql to your requirements.txt file:

ops
ops-lib-mysql

Your charm needs to declare its use of the interface in its metadata.yaml file:

requires:
  db:
    interface: mysql
    limit: 1  # Most charms only handle a single MySQL Application.

Your charm needs to bootstrap it and handle events:

from opslib.mysql import MySQLClient, MySQLRelationEvent


class MyCharm(ops.charm.CharmBase):
    _state = ops.framework.StoredState()

    def __init__(self, *args):
        super().__init__(*args)
        self._state.set_default(
            db_available=False, db_conn_str=None, db_host=None, db_port=None, db_name=None,
            db_user=None, db_password=None, db_root_password=None,
        )
        self.db = MySQLClient(self, 'db')  # 'db' relation in metadata.yaml
        self.framework.observe(self.db.on.database_changed, self._on_database_changed)

    def _on_database_changed(self, event: MySQLRelationEvent):
        self._state.db_available = event.is_available  # Boolean flag
        self._state.db_conn_str = event.connection_string  # host={host} port={port} ...
        self._state.db_host = event.host
        self._state.db_port = event.port
        self._state.db_name = event.database
        self._state.db_user = event.user
        self._state.db_password = event.password
        self._state.db_root_password = event.root_password

About

Juju Operator Framework Charm Interface for MySQL & MariaDB Relations

Resources

License

Stars

Watchers

Forks

Packages

No packages published