Skip to content
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

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions libvirt/libsaltcli.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- 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']('__cli') == 'salt-call' %}
{%- if salt['config.get']('root_dir').endswith('/running_data') %}
{%- set cli = 'ssh' %}
{%- else %}
{%- set cli = 'local' %}
{%- endif %}
{%- else %}
{%- set cli = 'unknown' %}
{%- endif %}
{%- do salt['log.debug']('[libsaltcli] the salt command type has been identified to be: ' ~ cli) %}
16 changes: 6 additions & 10 deletions libvirt/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/libsaltcli.jinja" import cli with context %}

{#- Where to lookup parameters source files #}
{%- set map_sources_dir = tplroot | path_join('parameters') %}
Expand Down Expand Up @@ -31,22 +32,17 @@
{#- load configuration values used in `config.get` merging strategies #}
{%- set _config = {'stack': default_settings.get('values', {}),
'merge_strategy': salt['config.get'](tplroot ~ ':strategy', None),
'merge_lists': salt['config.get'](tplroot ~ ':merge_lists', False),
'cli': salt['config.get']('__cli'),
'root_dir': salt['config.get']('root_dir')
'merge_lists': salt['config.get'](tplroot ~ ':merge_lists', False)
} %}

{#- `config.get` merge option works only for `minion` or local `salt-call` #}
{%- if _config['cli'] == 'salt-minion'
or (_config['cli'] == 'salt-call' and not _config['root_dir'].endswith('/running_data')) %}
{#- the `config.get` merge option only works for `minion` or `local` salt command types #}
{%- if cli in ['minion', 'local'] %}
{%- do _config.update({'merge_opt': {'merge': _config['merge_strategy']},
'merge_msg': ", merge: strategy='" ~ _config['merge_strategy'] ~ "'"}) %}
{#- the `config.get` merge option is not available for `ssh` or `unknown` salt command types #}
{%- else %}
{#- no `config.get` merge option for `salt-ssh` or `unknown` cli #}
{%- if _config['merge_strategy'] %}
{%- do salt['log.error']("map.jinja: the 'merge' option of 'config.get' is skipped with salt cli '"
~ _config['cli'] | replace('call', 'ssh') | default('unknown', True) ~ "'")
%}
{%- do salt['log.error']("map.jinja: the 'merge' option of 'config.get' is skipped when the salt command type is '" ~ cli ~ "'") %}
{%- endif %}
{%- do _config.update({'merge_opt': {},
'merge_msg': ''}) %}
Expand Down