オープンソースなシステム管理フレームワークFunc第4回KLab勉強会(株)paperboy&co.宮下 剛輔http://mizzy.org/2008/03/28
自己紹介(株)paperboy&co. (ペパボ)で働いてますレンタルサーバ のロリポップ!の会社です技術責任者というポジションで色々やってますシステムアーキテクト的なこととかシステム障害調査とかウェブアプリケーションやAPIの開発とか部署宛の郵便物を部員に配ったりとかドクターペッパー大好きです
Funcとは?
Funcとは?FedoraUnified Network Controllerシステム管理フレームワークと勝手に呼んでますシステム管理用のプログラムを開発するためのフレームワークgihyo.jpで連載中ですYou Can Do Almost Anything With Itフレームワークなので「具体的な何かができる」というものではない逆にいえば何でもできます
Funcとは?複数のサーバに対して,何らかの処理を一括でまとめて実行して結果が取得できる「何らかの処理」の部分は,モジュールで拡張できる「何らかの処理」はコマンドラインから実行して単に結果を表示,ということもできるし,Python API でプログラマブルに処理することもできる
サンプルその1# func target.example.org call hardwareinfo# func "*.example.org"call yumupdate# func "*" call moduleyouwrotemethodname1234 5678 firetruck acmelabs hike!
サンプルその2import func.overlord.client as fc results = fc.Client("*").service.status("httpd")for (host, rc) inresults.iteritems():if rc != 0:       fc.Client(host).service.start("httpd")
同じことをFuncなしでやろうとすると?対象となるホスト情報はどうやって管理する?対象ホストとどうやって通信して処理を実行する?SSH?HTTP?セキュリティはどうやって確保する?実行結果の取得とパースはどうする?といったことを考えないといけません
Funcを使うと?対象となるホスト情報はどうやって管理する?Funcが情報持ってます対象ホストとどうやって通信して処理を実行する?SSH?HTTP?XMLRPC over HTTPS利用者は意識しなくて良いセキュリティはどうやって確保する?SSL証明書による相互認証実行結果の取得とパースはどうする?Pythonの内部データ形式で結果取得
Funcのシステム構成certmasterモジュールの実行実行結果の取得minon(funcd)minon(funcd)minon(funcd)
Funcが目指すもの超わかりやすい超シンプルに使えるメンテと設定が最小限Kick ass
でも対応はRedHat系LinuxのみFC6以降、EL4以降起動スクリプトがRedHat 依存モジュールがRedHat依存といっても、ピュアPythonなので、他のOSやディストリビューションへの対応はそれほど難しくなさそう今後に期待
funcコマンド
管理対象minion一覧表示# func “*”list_minions['https://func02.example.org:51234', 'https://func01.example.org:51234']func02.example.orgfunc01.example.org
利用可能モジュール一覧表示# func "func01*" call systemlist_moduleson https://func01.example.org:51234 running system list_modules ()['certmaster', 'command', 'copyfile', 'filetracker', 'func_module', 'hardware','jobs', 'mount', 'nagios-check','netapp.snap', 'netapp.vol', 'netapp.vol.clone', 'networktest', 'process', 'reboot', 'rpms', 'service', 'smart', 'snmp', 'sysctl', 'test', 'yumcmd']
モジュールメソッドの表示# func "func01*" call service list_methodson https://func01.example.org:51234 running service list_methods ()['status', 'reload', 'get_running', 'stop', 'start', 'inventory', 'get_enabled', 'restart', 'module_description', 'module_version', 'module_api_version', 'list_methods']
モジュール説明の表示# func "func01*" call servicemodule_descriptionon https://func01.example.org:51234 running service module_description ()Allows for service control via func.
ntpdの起動# func "func01*" call servicestartntpdon https://func01.example.org:51234 running service start (ntpd)0
ntpdのステータス確認# func "func01*" call servicestatusntpdon https://func01.example.org:51234 running service status (ntpd)0
ntpdのステータス確認(停止してる場合)# func "func01*" call servicestatusntpdon https://func01.example.org:51234 running service status (ntpd)3
Python APIを利用したプログラミング
基本的なコードimport func.overlord.client as fcresults = fc.Client("*").module.method(args)for ( host, result ) in results.iteritems():# 何か処理
virtモジュールの利用例results = fc.Client("*").virt.state()for ( host, vms ) in results.iteritems():  if vms[0] == 'REMOTE_ERROR':continuefor vm in vms:    ( domain, state ) = vm.split(' ')if state == 'shutdown':      fc.Client(host).virt.create(domain)
smartモジュールの利用例info = fc.Client("*").smart.info()for(host,details) in info.iteritems():  if type(details) != list:print"%s had an error : %s" % (host,str(details))    break  (rc, list_of_output) = details  if rc != 0:print"Host %s may have problems" % hostprint"\n".join(list_of_output[3:])
デフォルトで使えるモジュールcommandcopyfilefiletrackerhardwarejobsmountnagios-checknetapp.optionsnetapp.snapnetapp.volnetapp.vol.clonenetworktestprocessrebootrpmsservicesmartsnmpsysctltestyumcmd
モジュールの拡張
モジュールのパスレイアウト$PYTHONPATH/func/minion/modules/mymodule.py(func “*”callmymodulemethod) $PYTHONPATH/func/minion/modules/foo/__init__.pybar.py(func “*”callfoo.barmethod)
モジュールコードimport func_moduleclassTest(func_module.FuncModule):  version = "11.11.11"  api_version = "0.0.1"  description = "Just a very simple example module"defadd(self, num1, num2):returnnum1 + num2defexception(self):raiseexceptions.Exception("khhhhhhaaaaaan!!!!!!")
func-create-module# func-create-moduleModule Name: exampleDescription: An example module.Author: Gosuke MiyashitaEmail: gosukenator@gmail.comLeave blank to finish.Method: mymethodMethod:Your module is ready to be hacked on. Wrote out to example.py.
func-create-moduleで生成された雛型import func_moduleclass Example(func_module.FuncModule):# Update these if need be.    version = "0.0.1"api_version = "0.0.1"    description = "An example module."defmymethod(self):"""        TODO: Document me ...        """pass
モジュールの配布やりかたわかりません><copyfile使えばいい?
Funcの課題
Funcの課題様々なOSへの対応PuppetのようなOSの違いを吸収するための仕組みが必要モジュールの充実モジュール自体も色んなOSへの対応が必要Func上で動作するアプリケーションの充実func-inventoryぐらいしか今はないホスト管理のバリエーションDBとかYAMLとかLDAPとか
Q&A

Open Source System Administration Framework - Func