Add file server docs

This commit is contained in:
Thomas S Hatch 2011-07-07 22:20:02 -06:00
parent 37c60fb16a
commit d4b99425b0
2 changed files with 95 additions and 0 deletions

View File

@ -73,6 +73,7 @@ Writing your own customizations on top of Salt
ref/runners
ref/renderers
ref/python-api
ref/file_server/index
* **Modules:**
:doc:`Writing modules <ref/modules/index>`
@ -87,6 +88,8 @@ Writing your own customizations on top of Salt
| :doc:`Renderers <ref/renderers>`
* **Python API:**
:doc:`Python API <ref/python-api>`
* **File Server:**
:doc:`File Server <ref/file_server/index>`
Getting Involved
================

View File

@ -0,0 +1,92 @@
================
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 the 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:
.. code-block:: bash
# 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
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:
.. code-block:: python
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:
.. code-block:: python
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)