Machines
Where to instantiate
The refresh class must be instantiated as early as possible in the charm code execution.
It must be instantiated exactly once per Juju event (once per charm code execution).
However, the refresh class must be instantiated after:
-
Your CharmSpecific subclass is defined
-
Anything referenced by your CharmSpecific callbacks (i.e. pre-refresh checks,
refresh_snap
) is definedSome of the CharmSpecific callbacks will be implemented in later steps. The instantiation may need to be moved after the callbacks are implemented
For most charms, it is simplest to instantiate the refresh class in the ops.CharmBase
__init__
method.
Instantiate charm_refresh.Machines
Example charm.py
class PostgreSQLCharm(ops.CharmBase):
def __init__(self, *args):
# [...]
self.refresh = charm_refresh.Machines(
MachinesPostgreSQLRefresh( (1)
workload_name="PostgreSQL", (2)
charm_name="postgresql", (3)
)
)
# [...]
1 | Replace MachinesPostgreSQLRefresh with your subclass of charm_refresh.CharmSpecificMachines |
2 | Replace PostgreSQL with the upstream workload name.
This must be the same as the name used in 10. Update actions.yaml |
3 | Replace postgresql with the charm name in metadata.yaml |