自定义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
自定义Func模块的更多相关文章
- 创建自定义 HTTP 模块
本主题中描述的自定义 HTTP 模块阐释了 HTTP 模块的基本功能.在响应下面两个事件时调用该模块:BeginRequest 事件和 EndRequest 事件.这使该模块可以在处理页请求之前和之后 ...
- 自定义HttpFilter模块完善
自定义HttpFilter模块完善 背景 在12月由于要针对项目做用户操作日志,但不想在每个方法里去增加代码,写入用户日志.因为这样具体的方法违背职责单一的原则,若后期日志内容格式发生变更,或其他 ...
- Dojo初探之2:设置dojoConfig详解,dojoConfig参数详解+Dojo中预置自定义AMD模块的四种方式(基于dojo1.11.2)
Dojo中想要加载自定义的AMD模块,需要先设置好这个模块对应的路径,模块的路径就是这个模块的唯一标识符. 一.dojoConfig参数设置详解 var dojoConfig = { baseUrl: ...
- 创建和注册自定义 HTTP 模块
本演练演示自定义 HTTP 模块的基本功能. 对于每个请求,都需要调用 HTTP 模块以响应 BeginRequest 和 EndRequest 事件. 因此,该模块在处理请求之前和之后运行. 如果 ...
- linux环境下 python环境import找不到自定义的模块
linux环境下 python环境import找不到自定义的模块 问题现象: Linux环境中自定义的模块swport,import swport 出错.swport模块在/root/sw/目录下. ...
- 演练:创建和注册自定义 HTTP 模块
本演练演示自定义 HTTP 模块的基本功能. 对于每个请求,都需要调用 HTTP 模块以响应 BeginRequest 和 EndRequest 事件. 因此,该模块在处理请求之前和之后运行. 如果 ...
- JS高阶---闭包应用(自定义JS模块)
[自定义JS模块] [闭包案例] (1)案例1 对应的模块文件 (2)案例2---使用匿名函数 对应的模块文件 案例2分析:因为内部函数引用了外部函数的变量,且存在嵌套关系,所以是闭包,分析结构图如下 ...
- Ionic4.x 中自定义公共模块
1.创建公共模块以及组件 ionic g module module/slide ionic g component module/slide 2.公共模块 slide.module.ts 中暴露对应 ...
- openERP笔记,自定义开发模块
##目标 OpenERP模块基本结构 使用模块添加额外的字段(Date Required和Rush Order) 扩展视图, 让OpenERP能够显示新的字段 修改用于OpenERP工作流的可用状态 ...
随机推荐
- Modelsim独立仿真Vivado Clocking Wizard IP Core
工欲善其事,必先利其器.在使用Vivado自带的仿真软件仿真的时候,相对于更优秀的仿真工具Modelsim,效率低了很多,为了更高效的开发,我尝试着用Vivado级联Modelsim仿真,但是级联后还 ...
- js测试地址
很多时候,想写js测试代码,比如在学习的时候.看书敲代码,每次打开VS还是很麻烦的.特别是需要加载一些库的时候. 此时有个工具可以解决: https://jsfiddle.net/ 也是在别人的博客里 ...
- 使用elk转存储日志
ELK指的是由Elastic公司提供的三个开源组件Elasticsearch.Logstash和Kibana. Logstash:开源的服务器端数据处理管道,能够同时 从多个来源采集数据.转换数据,然 ...
- 格式化 输出 while ,else ASCII码 ,字节转换 ,逻辑运算
python (占位符) % (求余数) 示例 name = input("请输入你的名字") age =int(input("请输入你的年龄")) hei ...
- CommonJS,AMD,RequireJS的区别
RequireJS实现了AMD的API. CommonJS是使用exports对象来定义模块的一种方法,它定义了模块的内容.简单地实现一个CommonJS的定义就像下面这样: // someModul ...
- Python爬虫笔记(一):爬虫基本入门
最近在做一个项目,这个项目需要使用网络爬虫从特定网站上爬取数据,于是乎,我打算写一个爬虫系列的文章,与大家分享如何编写一个爬虫.这是这个项目的第一篇文章,这次就简单介绍一下Python爬虫,后面根据项 ...
- HDU2825 Wireless Password
Description Liyuan lives in a old apartment. One day, he suddenly found that there was a wireless ne ...
- Codeforces 626F Group Projects(滚动数组+差分dp)
F. Group Projects time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- BZOJ 2823: [AHOI2012]信号塔
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2823 随机增量法.不断加点维护圆,主要是三点共圆那里打得烦(其实也就是个两中垂线求交点+联立方 ...
- UVa 725 简单枚举+整数转换为字符串
Division Write a program that finds and displays all pairs of 5-digit numbers that between them use ...