Skip to content

Commit 6258315

Browse files
authored
Merge pull request #71 from myii/refactor/use-libsaltcli
refactor(libsaltcli): use `libsaltcli` library to improve readability
2 parents 94cf084 + ad923ee commit 6258315

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

libvirt/libsaltcli.jinja

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=jinja
3+
4+
{#- Determine the type of command being run #}
5+
{%- if salt['config.get']('__cli') == 'salt-minion' %}
6+
{%- set cli = 'minion' %}
7+
{%- elif salt['config.get']('__cli') == 'salt-call' %}
8+
{%- if salt['config.get']('root_dir').endswith('/running_data') %}
9+
{%- set cli = 'ssh' %}
10+
{%- else %}
11+
{%- set cli = 'local' %}
12+
{%- endif %}
13+
{%- else %}
14+
{%- set cli = 'unknown' %}
15+
{%- endif %}
16+
{%- do salt['log.debug']('[libsaltcli] the salt command type has been identified to be: ' ~ cli) %}

libvirt/map.jinja

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

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

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

39-
{#- `config.get` merge option works only for `minion` or local `salt-call` #}
40-
{%- if _config['cli'] == 'salt-minion'
41-
or (_config['cli'] == 'salt-call' and not _config['root_dir'].endswith('/running_data')) %}
38+
{#- the `config.get` merge option only works for `minion` or `local` salt command types #}
39+
{%- if cli in ['minion', 'local'] %}
4240
{%- do _config.update({'merge_opt': {'merge': _config['merge_strategy']},
4341
'merge_msg': ", merge: strategy='" ~ _config['merge_strategy'] ~ "'"}) %}
42+
{#- the `config.get` merge option is not available for `ssh` or `unknown` salt command types #}
4443
{%- else %}
45-
{#- no `config.get` merge option for `salt-ssh` or `unknown` cli #}
4644
{%- if _config['merge_strategy'] %}
47-
{%- do salt['log.error']("map.jinja: the 'merge' option of 'config.get' is skipped with salt cli '"
48-
~ _config['cli'] | replace('call', 'ssh') | default('unknown', True) ~ "'")
49-
%}
45+
{%- do salt['log.error']("map.jinja: the 'merge' option of 'config.get' is skipped when the salt command type is '" ~ cli ~ "'") %}
5046
{%- endif %}
5147
{%- do _config.update({'merge_opt': {},
5248
'merge_msg': ''}) %}

0 commit comments

Comments
 (0)