SaltStack runners模块分析之cache模块
/usr/lib/python2.6/site-packages/salt/runners/cache.py
cache模块返回minion端缓存的数据
返回目标minion缓存的grains数据
def grains(tgt=None, expr_form=‘glob‘, **kwargs): ‘‘‘ Return cached grains of the targeted minions CLI Example: .. code-block:: bash salt-run cache.grains ‘‘‘ deprecated_minion = kwargs.get(‘minion‘, None) if tgt is None and deprecated_minion is None: log.warn("DEPRECATION WARNING: {0}".format(deprecation_warning)) tgt = ‘*‘ # targat all minions for backward compatibility elif tgt is None and isinstance(deprecated_minion, string_types): log.warn("DEPRECATION WARNING: {0}".format(deprecation_warning)) tgt = deprecated_minion elif tgt is None: return {} pillar_util = salt.utils.master.MasterPillarUtil(tgt, expr_form, use_cached_grains=True, grains_fallback=False, opts=__opts__) cached_grains = pillar_util.get_minion_grains() salt.output.display_output(cached_grains, None, __opts__) return cached_grains
$ sudo salt-run cache.grains [WARNING ] DEPRECATION WARNING: The ‘minion‘ arg will be removed from cache.py runner. Specify minion with ‘tgt‘ arg! gintama-qa-server: ---------- cpu_flags: - fpu - de - tsc - msr - pae - cx8 - sep - cmov - pat - clflush - mmx - fxsr - sse - sse2 - ss - ht - syscall - nx - lm - rep_good - aperfmperf - unfair_spinlock - pni - pclmulqdq - ssse3 - cx16 - pcid - sse4_1 - sse4_2 - x2apic - popcnt - tsc_deadline_timer - aes - hypervisor - lahf_lm - ida - arat - pln - pts - dts cpu_model: Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz cpuarch: x86_64 defaultencoding: UTF8 defaultlanguage: en_US domain: localdomain fqdn: localhost.localdomain fqdn_ip4: - 127.0.0.1 fqdn_ip6: - ::1 gpus: host: localhost hwaddr_interfaces: ---------- eth0: fa:39:64:2f:10:73 eth1: 56:30:39:48:ea:59 eth2: 66:11:fe:63:78:f9 eth3: 72:06:38:6f:5b:fa lo: 00:00:00:00:00:00 id: gintama-qa-server ip_interfaces: ---------- eth0: - 10.10.41.17 eth1: eth2: eth3: lo: - 127.0.0.1 ipv4: - 10.10.41.17 - 127.0.0.1 ipv6: - ::1 - fe80::f839:64ff:fe2f:1073 kernel: Linux
返回目标minon缓存的pillar数据
def pillar(tgt=None, expr_form=‘glob‘, **kwargs): ‘‘‘ Return cached pillars of the targeted minions CLI Example: .. code-block:: bash salt-run cache.pillar ‘‘‘ deprecated_minion = kwargs.get(‘minion‘, None) if tgt is None and deprecated_minion is None: log.warn("DEPRECATION WARNING: {0}".format(deprecation_warning)) tgt = ‘*‘ # targat all minions for backward compatibility elif tgt is None and isinstance(deprecated_minion, string_types): log.warn("DEPRECATION WARNING: {0}".format(deprecation_warning)) tgt = deprecated_minion elif tgt is None: return {} pillar_util = salt.utils.master.MasterPillarUtil(tgt, expr_form, use_cached_grains=True, grains_fallback=False, use_cached_pillar=True, pillar_fallback=False, opts=__opts__) cached_pillar = pillar_util.get_minion_pillar() salt.output.display_output(cached_pillar, None, __opts__) return cached_pillar
$ sudo salt-run cache.pillar [WARNING ] DEPRECATION WARNING: The ‘minion‘ arg will be removed from cache.py runner. Specify minion with ‘tgt‘ arg! gintama-qa-server: ---------- apache: httpd bind: ---------- listen-on: any package-name: bind9 port: 53 version: 9.9.5 company: Foo Industries git: git jialebi-qa-server: ---------- apache: httpd bind: ---------- listen-on: any package-name: bind9 port: 53 version: 9.9.5 company: Foo Industries git: git jidong-fileserver: ---------- apache: httpd bind: ---------- listen-on: any package-name: bind9 port: 53 version: 9.9.5 company: Foo Industries git: git localhost.localdomain: ---------- apache: httpd bind: ---------- listen-on: any package-name: bind9 port: 53 version: 9.9.5 company: Foo Industries git: git zg2-develp-server: ----------
def _clear_cache(tgt=None, expr_form=‘glob‘, clear_pillar=False, clear_grains=False, clear_mine=False, clear_mine_func=None): ‘‘‘ Clear the cached data/files for the targeted minions. ‘‘‘ if tgt is None: return False pillar_util = salt.utils.master.MasterPillarUtil(tgt, expr_form, use_cached_grains=True, grains_fallback=False, use_cached_pillar=True, pillar_fallback=False, opts=__opts__) return pillar_util.clear_cached_minion_data(clear_pillar=clear_pillar, clear_grains=clear_grains, clear_mine=clear_mine, clear_mine_func=clear_mine_func) def clear_pillar(tgt=None, expr_form=‘glob‘): ‘‘‘ Clear the cached pillar data of the targeted minions CLI Example: .. code-block:: bash salt-run cache.clear_pillar ‘‘‘ return _clear_cache(tgt, expr_form, clear_pillar=True) def clear_grains(tgt=None, expr_form=‘glob‘): ‘‘‘ Clear the cached grains data of the targeted minions CLI Example: .. code-block:: bash salt-run cache.clear_grains ‘‘‘ return _clear_cache(tgt, expr_form, clear_grains=True) def clear_mine(tgt=None, expr_form=‘glob‘): ‘‘‘ Clear the cached mine data of the targeted minions CLI Example: .. code-block:: bash salt-run cache.clear_mine ‘‘‘ return _clear_cache(tgt, expr_form, clear_mine=True) def clear_mine_func(tgt=None, expr_form=‘glob‘, clear_mine_func=None): ‘‘‘ Clear the cached mine function data of the targeted minions CLI Example: .. code-block:: bash salt-run cache.clear_mine_func tgt=‘*‘ clear_mine_func=‘network.interfaces‘ ‘‘‘ return _clear_cache(tgt, expr_form, clear_mine_func=clear_mine_func) def clear_all(tgt=None, expr_form=‘glob‘): ‘‘‘ Clear the cached pillar, grains, and mine data of the targeted minions CLI Example: .. code-block:: bash salt-run cache.clear_all ‘‘‘ return _clear_cache(tgt, expr_form, clear_pillar=True, clear_grains=True, clear_mine=True)
本文出自 “Linux SA John” 博客,请务必保留此出处http://john88wang.blog.51cto.com/2165294/1656350
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。