自定义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模块的更多相关文章

  1. 创建自定义 HTTP 模块

    本主题中描述的自定义 HTTP 模块阐释了 HTTP 模块的基本功能.在响应下面两个事件时调用该模块:BeginRequest 事件和 EndRequest 事件.这使该模块可以在处理页请求之前和之后 ...

  2. 自定义HttpFilter模块完善

    自定义HttpFilter模块完善   背景 在12月由于要针对项目做用户操作日志,但不想在每个方法里去增加代码,写入用户日志.因为这样具体的方法违背职责单一的原则,若后期日志内容格式发生变更,或其他 ...

  3. Dojo初探之2:设置dojoConfig详解,dojoConfig参数详解+Dojo中预置自定义AMD模块的四种方式(基于dojo1.11.2)

    Dojo中想要加载自定义的AMD模块,需要先设置好这个模块对应的路径,模块的路径就是这个模块的唯一标识符. 一.dojoConfig参数设置详解 var dojoConfig = { baseUrl: ...

  4. 创建和注册自定义 HTTP 模块

    本演练演示自定义 HTTP 模块的基本功能. 对于每个请求,都需要调用 HTTP 模块以响应 BeginRequest 和 EndRequest 事件. 因此,该模块在处理请求之前和之后运行. 如果 ...

  5. linux环境下 python环境import找不到自定义的模块

    linux环境下 python环境import找不到自定义的模块 问题现象: Linux环境中自定义的模块swport,import swport 出错.swport模块在/root/sw/目录下. ...

  6. 演练:创建和注册自定义 HTTP 模块

    本演练演示自定义 HTTP 模块的基本功能. 对于每个请求,都需要调用 HTTP 模块以响应 BeginRequest 和 EndRequest 事件. 因此,该模块在处理请求之前和之后运行. 如果 ...

  7. JS高阶---闭包应用(自定义JS模块)

    [自定义JS模块] [闭包案例] (1)案例1 对应的模块文件 (2)案例2---使用匿名函数 对应的模块文件 案例2分析:因为内部函数引用了外部函数的变量,且存在嵌套关系,所以是闭包,分析结构图如下 ...

  8. Ionic4.x 中自定义公共模块

    1.创建公共模块以及组件 ionic g module module/slide ionic g component module/slide 2.公共模块 slide.module.ts 中暴露对应 ...

  9. openERP笔记,自定义开发模块

    ##目标 OpenERP模块基本结构 使用模块添加额外的字段(Date Required和Rush Order) 扩展视图, 让OpenERP能够显示新的字段 修改用于OpenERP工作流的可用状态 ...

随机推荐

  1. 有具体名称的匿名函数var bar = function foo(){}

    http://kangax.github.io/nfe/ 命名的函数表达式 函数表达式实际上可以经常看到.Web开发中的一个常见模式是基于某种特性测试来"分叉"函数定义,从而获得最 ...

  2. IdentityServer(11)- 使用Hybrid Flow并添加API访问控制

    关于Hybrid Flow 和 implicit flow 我在前一篇文章使用OpenID Connect添加用户认证中提到了implicit flow,那么它们是什么呢,它和Hybrid Flow有 ...

  3. Java学习笔记【持续更新】

    一个简单的java程序如下: class Sakura { public static void main(String[] arges) { system.out.println("Hel ...

  4. bzoj:1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏

    Description 奶牛们又在玩一种无聊的数字游戏.输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果.在游戏的开始,每头牛都会得到一个数N(1<=N<=1,000,000).此时奶 ...

  5. BZOJ 1968: [Ahoi2005]COMMON 约数研究(新生必做的水题)

    1968: [Ahoi2005]COMMON 约数研究 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 2351  Solved: 1797 [Submi ...

  6. Trees on the level(指针法和非指针法构造二叉树)

    Trees on the level Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. 部署Asp.net Core 项目发生502.5 或者500 没有其他提示信息

    最近将公司原来.NetCore 1.6的项目升级到.net Core 2.0首先发生 502.5的错误,包括IIS日志,Windows应用程序日志都没有记录问题始终解决不了,首先看看官网给出的解决方案 ...

  8. Docker+Jenkins持续集成环境(3)集成PMD、FindBugs、Checkstyle静态代码检查工具并邮件发送检查结果

    为了规范代码,我们一般会集成静态代码检测工具,比如PMD.FindBugs.Checkstyle,那么Jenkins如何集成这些检查工具,并把检查结果放到构建邮件里呢? 今天做了调研和实现,过程如下 ...

  9. Cookie实现--用户上次访问时间

    用户上次访问时间  

  10. 【Jsp/Servlet】获取客户端使用的ip

    一般使用jsp的时候大多数时间都可以使用request.getRemoteAddr() 来获取ip,但是这个前提是未经过反向代理等操作的原始地址,所以,需要在反向代理等操作之后还要获取客户端的ip变得 ...