-
Notifications
You must be signed in to change notification settings - Fork 41
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
refactor(libsaltcli): use libsaltcli
library to improve readability
#71
refactor(libsaltcli): use libsaltcli
library to improve readability
#71
Conversation
If this works out, I'll update the PR in the |
It would be simple to manage |
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 clarify map.jinja
.
Thanks.
Sorry for not using it I was falsely convinced that |
* To distinguish between: - `salt-minion` - `salt-call` - `salt-ssh` * Invoked like `map.jinja`: - `{%- from tplroot ~ "/libsaltcli.jinja" import cli with context %}` * Based upon work done in PRs: saltstack-formulas#102, saltstack-formulas#114 & saltstack-formulas#115 * Finalised from saltstack-formulas/libvirt-formula#71 * Required by saltstack-formulas#186
🎉 This PR is included in version 3.7.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
@baby-gnu I found out that there is an
So I reckon we should change the test on this line accordingly:
Would you like to test it at your end first? -{%- if salt['config.get']('root_dir').endswith('/running_data') %}
+{%- if opts.get('__master_opts__', {}).get('__cli')) == 'salt-ssh' %} Looking at the docs, I've also found that we can use https://docs.saltstack.com/en/latest/ref/states/vars.html#opts
So we could use the following instead: -{%- if salt['config.get']('root_dir').endswith('/running_data') %}
+{%- if salt['config.get']('__master_opts__', {}).get('__cli')) == 'salt-ssh' %} Not sure if there's any benefit to doing that, though. |
Thanks @myii for the feedback, it works fine. Both choices require internal implementation knowledge but the second is more explicit about So # -*- coding: utf-8 -*-
# vim: ft=jinja
{#- Determine the type of command being run #}
{%- if salt['config.get']('__cli') == 'salt-minion' %}
{%- set cli = 'minion' %}
{%- elif salt['config.get']('__master_opts__', {}).get('__cli') == 'salt-ssh' %}
{%- set cli = 'ssh' %}
{%- elif salt['config.get']('__cli') == 'salt-call' %}
{%- set cli = 'local' %}
{%- else %}
{%- set cli = 'unknown' %}
{%- endif %}
{%- do salt['log.debug']('[libsaltcli] the salt command type has been identified to be: ' ~ cli) %} Which could be optimized. |
## [3.7.2](v3.7.1...v3.7.2) (2020-03-26) ### Code Refactoring * **libsaltcli:** use `ssh` matching improvement (`__master_opts__`) ([c800fd1](c800fd1)), closes [/github.com//pull/71#issuecomment-604427395](https://github.com//github.com/saltstack-formulas/libvirt-formula/pull/71/issues/issuecomment-604427395)
PR progress checklist (to be filled in by reviewers)
What type of PR is this?
Primary type
[build]
Changes related to the build system[chore]
Changes to the build process or auxiliary tools and libraries such as documentation generation[ci]
Changes to the continuous integration configuration[feat]
A new feature[fix]
A bug fix[perf]
A code change that improves performance[refactor]
A code change that neither fixes a bug nor adds a feature[revert]
A change used to revert a previous commit[style]
Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)Secondary type
[docs]
Documentation changes[test]
Adding missing or correcting existing testsDoes this PR introduce a
BREAKING CHANGE
?No.
Related issues and/or pull requests
libsaltcli
): add lib to check type of Salt command being used template-formula#131Describe the changes you're proposing
@baby-gnu I've tested this out with
salt-ssh
and it appears to be working fine. It takes away some of the complexity frommap.jinja
and it also allows us to use this library anywhere else we need it.Pillar / config required to test the proposed changes
Debug log showing how the proposed changes work
Documentation checklist
README
(e.g.Available states
).pillar.example
.Testing checklist
state_top
).Additional context