question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Helper functions to write charms

See original GitHub issue

The more charms we write, the more helper functions/methods we end up writing.

These are just a few examples:

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:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
benhoytcommented, May 20, 2021

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 separate opshelpers or similar library with a bunch of helper functions. It wouldn’t have to be so carefully vetted as ops core.

1reaction
benhoytcommented, May 20, 2021

@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 like requests.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found