Helper functions to write charms
See original GitHub issueThe more charms we write, the more helper functions/methods we end up writing.
These are just a few examples:
- Function to generate passwords in the cassandra lib charm.
- Method to generate passwords in the mysql charm.
- Method to get the unit IP address
This code will end up being replicated across many charms and potentially in insecure ways.
Should something like ops.utils
be the right place for all this kind of helper functions?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Charm Helpers Documentation — Charm Helpers 0.20.10 ...
The charmhelpers Python library is an extensive collection of functions and classes for simplifying the development of Juju Charms.
Read more >openstack/charms.ceph - GitHub
Helper functions for the ceph charms. This library has shared functionality that is used in the ceph-mon, ceph-osd and ceph charms. Anything that...
Read more >openstack/charms.ceph: Helpers for writing Ceph OpenStack ...
Helper functions for the ceph charms. This library has shared functionality that is used in the ceph-mon, ceph-osd and ceph charms.
Read more >How to create custom helper functions in Laravel
1) Inside the app directory of the project root, create a folder named Helpers (Just to separate and structure the code). 2) Inside...
Read more >Helper Functions - Components - Ember Guides
To implement the helper, we write a JavaScript function that takes its arguments as an array. This is because helpers can also receive...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That said, even though I don’t think a lot of these functions will end up in
ops
itself, there’s nothing stopping you (or us) from making a separateopshelpers
or similar library with a bunch of helper functions. It wouldn’t have to be so carefully vetted asops
core.@Abuelodelanada Thanks for the suggestions. I’m not a big fan of adding generic tools like “generate password”. I don’t think we should be adding things that aren’t specific to charming to the operator framework. It’s fine to use your favourite password generation library from PyPI, or just write the one-liner generation function that satisfies your needs like you’ve done.
As far as fetching the unit’s IP address, doesn’t this depend on the network configuration and relations involved? Again, you can use the tools like
get_binding()
to do what your specific charm needs (like you’ve done). But I’d be happy to hear a more specific proposal for what you have in mind here, so we can discuss specifics.@sed-i Can you provide a more specific explanation for what each of those functions is intended to do, perhaps with pseudo-code and a context example? Then we could discuss them on their specific merits. The only one I think we’d definitely not add is
fetch_url
– this is a minefield, and there are so many ways of fetching URL, so many options etc, that that’s definitely best left for a library likerequests
.