鄙人的minion id是docker,對應(yīng)的pillar的top.sls內(nèi)容配置為:
root@docker:/srv/pillar# cat top.sls base: docker: - proxyminion
而proxyminion.sls內(nèi)容則是對應(yīng)網(wǎng)管設(shè)備的描述:
root@docker:/srv/pillar# cat proxyminion.sls proxy: rest_sample: proxytype: rest_sample url: http://127.0.0.1:8080/ id: proxy_docker
這里需要注意的是,proxytype必須是在salt/proxy下已經(jīng)預(yù)先定義好的,而其他的一些參數(shù)則是自己網(wǎng)管設(shè)備通信需要的一些數(shù)據(jù),不一定相同。
定義好pillar數(shù)據(jù)之后,需要為之添加對應(yīng)的proxy conn class和grains數(shù)據(jù),這里鄙人使用官方sample,就偷個懶:
root@docker:/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 with the 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 ''' ……
放心,2014.1.7版本已經(jīng)默認有這個sample代碼。 接下來,直接test.ping試試吧!
root@docker:/srv/pillar# salt '*' test.ping -v Executing job with jid 20140720110315049478 ------------------------------------------- docker: True rest_sample-localhost: True
誒,等一下,為什么多出來個key?為什么還能test.ping通?沒錯!這個就是ProxyMinion,而salt默認已經(jīng)配置了test.ping方法兼容proxy minion了,只要寫好對應(yīng)的ping模塊,就可以使用常規(guī)的test.ping來探測?。ū纠膒ing代碼如下)
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還提供很多function,比如鄙人測試的一個service_status,修改對應(yīng)的模塊代碼即可使之兼容proxy minion(代碼路徑為/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 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)
那么這時候再看看當前proxy minion管理的服務(wù)狀態(tài)咋樣了:
root@docker:/srv/pillar# salt '*' service.status apache rest_sample-localhost: ---------- comment: stopped ret: True docker: False
完全和普通minion兼容?。est_sample本身還配置了grain數(shù)據(jù),代碼位于/usr/lib/python2.7/dist-packages/salt/grains/rest_sample.py,直接敲命令看看:
root@docker:/srv/pillar# salt 'rest_sample-localhost' grains.items rest_sample-localhost: housecat: Are you kidding? kernel: 0.0000001 location: In this darn virtual machine. Let me out! os: RestExampleOS os_family: proxy
Awesome??!這樣一來,一個基本的salt proxy minion就算是配置完成,Proxy Minion 的類定義代碼位于/usr/lib/python2.7/dist-packages/salt/minion.py,有興趣可以看看。
鄙人在本機測試時,Minion Docker在嘗試fork出一個ProxyMinion過程中間報錯,說_running參數(shù)沒有配置,在添加代碼后通過(即位于minion.py代碼里)
class ProxyMinion(Minion): ''' This class instantiates a 'proxy' minion--a minion that does not manipulate the 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使得salt針對網(wǎng)管設(shè)備的配置管理成為可能,不過想要實現(xiàn)一個ProxyType的ProxyMinion的完全管理,可能需要編寫很多額外的module去支持它的運行。
在大公司復(fù)雜的網(wǎng)絡(luò)環(huán)境下,完全可以針對此編寫對應(yīng)SNMP管理模塊或者針對OVS編寫對應(yīng)的管理模塊,爾后通過salt統(tǒng)一托管,畢竟Salt有一套完善的配置管理體系??!
原文地址:Saltstack 新特性測試之proxy minion, 感謝原作者分享。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com