operator icon indicating copy to clipboard operation
operator copied to clipboard

Helper library of common operations

Open stub42 opened this issue 5 years ago • 3 comments

There are many common operations that charms need to perform on the deployed machine to setup and maintain the deployed software. Many of these have accumulated in the charm-helpers library. It would be good if a coherent version of these helpers was either provided as part of the operator framework, or in a blessed module charmers are encouraged to include.

Operations such as:

  • create a directory securely, setting ownership and permissions
  • write a file securely, setting ownership and permissions
  • systemd service control (start, stop, enable, disable, status)
  • render a template (per #228)
  • create an OS user
  • create an OS group
  • add an OS user to an OS group
  • generate a secure password
  • generate a hash of a file (for detecting changes)
  • change ownership and/or permissions, recursively
  • get the amount of system RAM
  • manage OS resource limits (generally to bump them up)
  • detect if the host machine is a container (eg. ntpd should not be run in a container)
  • install a certificate as a trusted certificate authority (/usr/local/share/ca-certificates/...)

(the above list from skimming charmhelpers/core/host.py)

Also functionality to install apt and snap packages, per apt and snap charms.reactive layers.

stub42 avatar May 12 '20 11:05 stub42

I understand that these methods are there, I'm more curious to know how many charms are actually using them. There are things like https://pypi.org/project/psutil/ as well that we should look at.

jameinel avatar May 27 '20 12:05 jameinel

We will address this list and take a decision in each case of how the functionality will be handled.

facundobatista avatar May 27 '20 12:05 facundobatista

This is now being worked on as a series of tightly scoped charm libraries by @rbarry82.

jnsgruk avatar Sep 28 '21 16:09 jnsgruk

@jnsgruk It seems to me libraries are the way to do this, agreed? Either small charm-lib libraries or larger PyPI libs (or even 3rd party libraries like John M mentioned like psutil). Do you have a link to where @rbarry82's libraries ended up?

benhoyt avatar Nov 28 '22 23:11 benhoyt

They ended up in a charm named operator-libs-linux - we've actually added a docs page that tracks these libraries: https://juju.is/docs/sdk/library-index#heading--libraries-that-provide-tools-for-machine-charms

I think for now this is safe to close - the Operator Framework itself isn't the place for these things, and charm libs can be used to satisfy the same need.

jnsgruk avatar Nov 29 '22 08:11 jnsgruk