自定义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. SSH Secure Shell Client最新版,解决Win10不兼容问题

    SSH的工具很多,像XShell,SecureCRT等等. 不过我一直用的是:SSH Secure Shell Client 主要的原因就是: 软件本身带文件浏览的功能,可以通过拖拽去实现文件上传和下 ...

  2. Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】

    F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standar ...

  3. Spring框架学习笔记(2)——IOC&DI

    IOC:控制反转,创建对象的权利交给Spring,Spring会自动创建对象. DI:依赖注入,操作的对象靠Spring注入,如果不使用Spring,对象的属性值是要靠setter方法来添加的,使用S ...

  4. 慕课网-前端JavaScrpt基础面试技巧-学习笔记

    章节目录: JS基础知识(上)--讲解 JS 基础语法相关的面试题,分析原理以及解答方法.这一章节讲解了基础知识的第一部分:变量的类型和计算.以及JS "三座大山" -- 原型.作 ...

  5. 【shell mysql 导出数据到csv脚本,完美解决乱码转义符等问题】-费元星

    #!/bin/bash#@author:feiyuanxing [既然笨到家,就要努力到家]#@date:2017-12-05#@E-Mail:feiyuanxing@gmail.com#@TARGE ...

  6. Spark性能调优之Shuffle调优

    Spark性能调优之Shuffle调优    • Spark底层shuffle的传输方式是使用netty传输,netty在进行网络传输的过程会申请堆外内存(netty是零拷贝),所以使用了堆外内存. ...

  7. 算法-java代码实现快速排序

    快速排序 对于一个int数组,请编写一个快速排序算法,对数组元素排序. 给定一个int数组A及数组的大小n,请返回排序后的数组. 测试样例: [1,2,3,5,2,3],6 [1,2,2,3,3,5] ...

  8. 一步一步从原理跟我学邮件收取及发送 5.C语言的socket示例

    说到 C 语言版本的程序,首先要解决的问题就是兼容性. 作为 20 年开发有 10 多年是在服务端的程序员,我深刻地感受到服务端平台的两极分化之严重,linux 派对 windows 那是超级的不屑一 ...

  9. Nginx负载均衡配置简单配置方法

    http://www.jb51.net/article/121235.htm Nginx作为负载均衡服务器,用户请求先到达nginx,再由nginx根据负载配置将请求转发至不同的Web服务器.下面通过 ...

  10. bug 对应

    异常1:not-null property references a null or transient value解决方法:将“一对多”关系中的“一”方,not-null设置为false http: ...