设为首页 收藏本站
查看: 1073|回复: 0

[经验分享] saltstack官方文档——File Server Client API

[复制链接]

尚未签到

发表于 2015-11-26 10:56:36 | 显示全部楼层 |阅读模式
  转自:http://docs.saltstack.com/ref/file_server/file_roots.html
  

File Server Configuration
  
  The Salt file server is a high performance file server written in ZeroMQ. It manages large files quickly and with little overhead, and has been optimized to handle small files in an extremely efficient manner.
  The Salt file server is an environment aware file server. This means that files can be allocated within many root directories and accessed by specifying both the file path and the environment to search. The individual environments can span across
multiple directory roots to create overlays and to allow for files to be organized in many flexible ways.

ENVIRONMENTS
  The Salt file server defaults to the mandatory base environment. This environment MUST be defined and isused to download files when no environment is specified.
  Environments allow for files and sls data to be logically separated, but environments are not isolated from eachother. This allows for logical isolation of environments by the engineer using Salt, but also allows for informationto be used in multiple environments.

DIRECTORY OVERLAY
  The environment setting is a list of directories to publish files from. These directories are searched in order to find the specified file and the first file found is returned.
  This means that directory data is prioritized based on the order in which they are listed. In the case of thisfile_roots configuration:

file_roots:
base:
- /srv/salt/base
- /srv/salt/failover

  If a file's URI is salt://httpd/httpd.conf, it will first search for the file at /srv/salt/base/httpd/httpd.conf.
If the file is found there it will be returned. If the file is not found there, then/srv/salt/failover/httpd/httpd.conf will be used for the source.
  This allows for directories to be overlaid and prioritized based on the order they are defined in the configuration.

LOCAL FILE SERVER

New in version 0.9.8.
  The file server can be rerouted to run from the minion. This is primarily to enable running Salt states without a Salt master. To use the local file server interface, copy the file server data to the minion and set the file_roots option on the minion
to point to the directories copied from the master. Once the minion file_roots option has been set, change the file_client option
to local to make sure that the local file server interface is used.


  


  转自:http://docs.saltstack.com/ref/file_server/index.html

Salt File Server
  
  
  Salt comes with a simple file server suitable for distributing files to the Salt minions. The file server is a stateless ZeroMQ server that is built into the Salt master.
  The main intent of the Salt file server is to present files for use in the Salt state system. With this said, the Salt file server can be used for any general file transfer from the master to the minions.

THE CP MODULE
  The cp module is the home of minion side file server operations. The cp module is used by the Salt state system, salt-cp and can be used to distribute files presented by the Salt file server.

Environments
  Since the file server is made to work with the Salt state system, it supports environments. The environments are defined in the master config file and when referencing an environment the file specified will be based on the root directory of the
environment.

get_file
  The cp.get_file function can be used on the minion to download a file from the master, the syntax looks like this:

# salt '*' cp.get_file salt://vimrc /etc/vimrc

  This will instruct all Salt minions to download the vimrc file and copy it to /etc/vimrc
  Template rendering can be enabled on both the source and destination file names like so:

# salt '*' cp.get_file "salt://{{grains.os}}/vimrc" /etc/vimrc template=jinja

  This example would instruct all Salt minions to download the vimrc from a directory with the same name as their OS grain and copy it to /etc/vimrc
  For larger files, the cp.get_file module also supports gzip compression. Because gzip is CPU-intensive, this should only be used in scenarios where the compression ratio is very high (e.g. pretty-printed JSON or YAML files).
  Use the gzip named argument to enable it. Valid values are 1..9, where 1 is the lightest compression and 9 the heaviest. 1 uses the least CPU on the master (and minion), 9 uses the most.

# salt '*' cp.get_file salt://vimrc /etc/vimrc gzip=5

  Finally, note that by default cp.get_file does not create new destination directories if they do not exist. To change this, use the makedirs argument:

# salt '*' cp.get_file salt://vimrc /etc/vim/vimrc makedirs=True

  In this example, /etc/vim/ would be created if it didn't already exist.

get_dir
  The cp.get_dir function can be used on the minion to download an entire directory from the master. The syntax is very similar to get_file:

# salt '*' cp.get_dir salt://etc/apache2 /etc

  cp.get_dir supports template rendering and gzip compression arguments just like get_file:

# salt '*' cp.get_dir salt://etc/{{pillar.webserver}} /etc gzip=5 template=jinja


FILE SERVER CLIENT API
  A client API is available which allows for modules and applications to be written which make use of the Salt file server.
  The file server uses the same authentication and encryption used by the rest of the Salt system for network communication.

FileClient Class
  The FileClient class is used to set up the communication from the minion to the master. When creating a FileClient object the minion configuration needs to be passed in. When using the FileClient from within a minion module the built in __opts__ data
can be passed:

import salt.minion
def get_file(path, dest, env='base'):
'''
    Used to get a single file from the Salt master
    CLI Example:
    salt '*' cp.get_file salt://vimrc /etc/vimrc
    '''
# Create the FileClient object
client = salt.minion.FileClient(__opts__)
# Call get_file
return client.get_file(path, dest, False, env)

  Using the FileClient class outside of a minion module where the __opts__ data is not available, it needs to be generated:

import salt.minion
import salt.config
def get_file(path, dest, env='base'):
'''
    Used to get a single file from the Salt master
    '''
# Get the configuration data
opts = salt.config.minion_config('/etc/salt/minion')
# Create the FileClient object
client = salt.minion.FileClient(opts)
# Call get_file
return client.get_file(path, dest, False, env)


  


  


  


  


  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-143809-1-1.html 上篇帖子: saltstack官方文档——Salt Syndic 下篇帖子: 自动化运维工具---saltstack
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表