自定义Func模块
自定义Func模块
(1)自定义模块步骤
(2)生成模块
[root@controller modules]# cd /usr/lib/python2.7/site-packages/func/minion/modules
执行:
[root@controller modules]# func-create-module
Module Name: mymodule
Description: tesy
Author: a
Email: a@qq.com
Leave blank to finish.
Method: cho
Method: echo
Method: echo
生成一个名为mymodule.py的文件
查看:
[root@controller modules]# vim mymodule.py
#
# Copyright 2018
# a <a@qq.com>
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import func_module
class Mymodule(func_module.FuncModule):
# Update these if need be.
version = "0.0.1"
api_version = "0.0.1"
description = "tesy"
def cho(self):
"""
TODO: Document me ...
"""
pass
def echo(self):
"""
TODO: Document me ...
"""
pass
def echo(self):
"""
TODO: Document me ...
"""
Pass
(3) 编写逻辑
如模块简单实现查看log日志信息:
[root@controller func]# cat mymodule.py
#
# Copyright 2018
# a <a@qq.com>
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import func_module
class Mymodule(func_module.FuncModule):
# Update these if need be.
version = "0.0.1"
api_version = "0.0.1"
description = "tesy"
def echo(self,vcount):
"""
TODO: Document me ...
"""
command="/usr/bin/tail -n"+str(vcount)+" /var/log/messages"
cmdref = sub_process.Popen(command,stdout=sub_process.PIPE,stderr=sub_process.PIPE,shell=Ture,close_fds=True)
data = cmdref.communicate()
return (cmdref.returncode,data[0])
pass
(4) 分发模块
[root@controller func]# cat resyncmodule.py
#!/usr/bin/python
import sys
import func.overlord.client as fc
import xmlrpclib
module = sys.argv[1]
pythonmodulepath = "/usr/lib/python2.7/site-packages/func/minion/modules/"
client = fc.Client("*")
fb = file(pythonmodulepath + module,"r").read()
data = xmlrpclib.Binary(fb)
print client.copyfile.copyfile(pythonmodulepath+module,data)
print client.command.run("service funcd restart")
[root@controller func]# python resyncmodule.py mymodule.py
Client端查看:
[root@compute modules]# ll /usr/lib/python2.7/site-packages/func/minion/modules/mymodule.py
-rw-r--r-- 1 root root 825 Jan 8 01:11 /usr/lib/python2.7/site-packages/func/minion/modules/mymodule.py
(5) 执行模块
[root@controller func]# func "*" call mymodule echo 5
微信

支付宝

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类