Currently, salt is mainly used in Linux OS and Windows client (Windows client is not used in windows, but it should be ......), Recently, I noticed that a small official module mentioned proxy Minion, which is also mentioned in the group. I want to see what actually exists.
Any device can be hosted by salt
The appearance of salt proxy minion allows network management devices or dumb devices (such as SMS gateway) to be centrally managed by salt, and the actual management module or communication interface is compiled by the user, for more information, see proxy minion on the salt official website.
New features in development
Note that proxy Minion is a new feature introduced in 2014.1.x. It is still in the development stage and can only be used for testing purposes.
Test Environment preparation
My PC environment:
After preparing the basic environment, you need to download a small program (rest server, simulating the management interface of the network management device) used by the official salt developer to test proxy minion from GitHub ), the name is salt-proxy-rest.
This program may depend on two Python libraries: bottle and requests (which are actually components required by web server ......), Install it.
Usepython rest.pyRun this program as a web management interface for the network management device:
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/40/00/wKioL1PNwe-DFXmzAADvoe1QHMw550.jpg "Title =" web.png "alt =" wKioL1PNwe-DFXmzAADvoe1QHMw550.jpg "/>
Try to run!
Now, the preparation is complete. In the current environment, salt-master and salt-Minion run stably, and a network management device providing rest interfaces is working independently. What we need to do is to pull it into the salt camp.
Minion ID is docker, and the content of pillar top. SLS is configured as follows:
[email protected]:/srv/pillar# cat top.slsbase: docker: - proxyminion
The proxyminion. SLS content is the description of the corresponding network management device:
[email protected]:/srv/pillar# cat proxyminion.slsproxy: rest_sample: proxytype: rest_sample url: http://127.0.0.1:8080/ id: proxy_docker
It should be noted that proxytype must be pre-defined in salt/proxy, while other parameters are the data required for communication between the network management device, which is not necessarily the same.
After defining the pillar data, you need to add the corresponding proxy conn class and grains data for it. Here, when you use the official sample, you will be lazy:
[email protected]:/srv/pillar# cat /usr/lib/python2.7/dist-packages/salt/proxy/rest_sample.py# -*- coding: utf-8 -*-‘‘‘This is a simple proxy-minion designed to connect to and communicate withthe bottle-based web service contained in salt/tests/rest.py.Note this example needs the ‘requests‘ library.Requests is not a hard dependency for Salt‘‘‘……
Rest assured that this sample code is available by default in 2014.1.7. Next, try test. Ping!
[email protected]:/srv/pillar# salt ‘*‘ test.ping -vExecuting job with jid 20140720110315049478-------------------------------------------docker: Truerest_sample-localhost: True
Hey, wait. Why is there a key? Why test. Ping? That's right! This is proxyminion, and the salt has configured the test. ping method to be compatible with the proxy minion by default. You only need to write the corresponding Ping module, you can use the general test. Ping to detect it! (The Ping code in this example is as follows)
def ping(self): ‘‘‘ Is the REST server up? ‘‘‘ r = requests.get(self.url+‘ping‘) try: if r.status_code == 200: return True else: return False except Exception: return False
Rest_sample also provides many functions, such as service_status, modify the corresponding module code to make it compatible with proxy minion (the code path is/usr/lib/python2.7/dist-packages/salt/modules/service. PY ):
def status(name, sig=None): ‘‘‘ Return the status for a service, returns the PID or an empty string if the service is running or not, pass a signature to use to find the service via ps CLI Example: .. code-block:: bash salt ‘*‘ service.status <service name> [service signature] ‘‘‘ #wjx add, denote it to work!! #if ‘proxyobject‘ in __opts__: # return __opts[‘proxyobject‘].service_status(sig if sig else name) return __salt__[‘status.pid‘](sig if sig else name)
Now let's look at the service status managed by proxy minion:
[email protected]:/srv/pillar# salt ‘*‘ service.status apacherest_sample-localhost: ---------- comment: stopped ret: Truedocker: False
Fully compatible with normal Minion !! The rest_sample itself also configures grain data. The code is located in/usr/lib/python2.7/dist-packages/salt/grains/rest_sample.py. You can directly run the following command to see it:
[email protected]:/srv/pillar# salt ‘rest_sample-localhost‘ grains.itemsrest_sample-localhost: housecat: Are you kidding? kernel: 0.0000001 location: In this darn virtual machine. Let me out! os: RestExampleOS os_family: proxy
Awesome !! In this way, even if a basic salt proxy Minion is configured, the class definition code of proxy Minion is located in/usr/lib/python2.7/dist-packages/salt/minion. py. If you are interested, check it out.
Possible bugs
During testing on the local machine, Minion docker reported an error when trying to fork a proxyminion process, saying that the _ running parameter is not configured and passed after code is added (that is, it is located in the minion. py code)
class ProxyMinion(Minion):‘‘‘This class instantiates a ‘proxy‘ minion--a minion that does not manipulatethe host it runs on, but instead manipulates a device that cannot run a minion.‘‘‘def __init__(self, opts, timeout=60, safe=True): # pylint: disable=W0231 ‘‘‘ Pass in the options dict ‘‘‘ #wjx add, maybe a bug self._running = None # Warn if ZMQ < 3.2 if HAS_ZMQ and (not(hasattr(zmq, ‘zmq_version_info‘)) or zmq.zmq_version_info() < (3, 2)): ……
Proxy minion
Proxy minion makes it possible for salt to manage the configuration of network management devices. However, to fully manage a proxytype proxyminion, you may need to write many additional modules to support its operation.
In the complex network environment of a large company, you can write corresponding SNMP management modules or corresponding management modules for ovs, and then use salt for unified hosting, after all, salt has a complete configuration management system!
This article is from the "Love blog" blog. For more information, contact the author!
Proxy Minion for new features test of saltstack