New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support python dict in sysctl_create #15
Conversation
Add support for directly passing a python dict rather than a YAML formatted string to sysctl_create to make it easier for charms to set sane defaults without hopping via YAML first.
da4b2d3
to
f963305
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought on the dict detection and possibly making it more flexible.
log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict), | ||
level=ERROR) | ||
return | ||
if type(sysctl_dict) is not dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would probably be more flexible if it used:
if isinstance(syctl_dict, dict):
as it would allow dict like objects to also be used. If you wanted to be really flexible, then you could use:
if isinstance(sysctl_dict, collections.abc.Mapping):
Then it would allow any object that supports the dictionary specific methods (e.g. getattr, iter, etc.) to be used.
log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict), | ||
level=ERROR) | ||
return | ||
if type(sysctl_dict) is not dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might consider using if not isinstance(sysctl_dict, collections.Mapping):
instead, on the off chance that the charm wants to pass in, e.g., an OrderedDict
instead. Not really a blocker, though, since the order wouldn't be preserved with the existing code, either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, collections.Mapping
is Py2 compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
importing collections.Mapping raises a warning under Py3.7, and should be collections.abc.Mapping. We might need a conditional import.
Add support for directly passing a python dict rather than a
YAML formatted string to sysctl_create to make it easier for
charms to set sane defaults without hopping via YAML first.