zoukankan      html  css  js  c++  java
  • 自定义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

  • 相关阅读:
    绝对路径和相对路径
    基本的文件操作
    Python2和3字符编码区别
    java开发两年了,连个java代理模式都摸不透,你怎么跳槽涨薪?
    【建议收藏】阿里P7总结的Spring注解笔记,把组件注册讲的明明白白
    面试官:你说你精通SpringBoot,你给我说一下类的自动装配吧
    面试BAT问的最多的27道MyBatis 面试题(含答案和思维导图总结)
    Springboot 框架整理,建议做开发的都看看,整理的比较详细!
    直面秋招!非科班生背水一战,最终拿下阿里等大厂offer!
    写的太细了!Spring MVC拦截器的应用,建议收藏再看!
  • 原文地址:https://www.cnblogs.com/Dev0ps/p/8242620.html
Copyright © 2011-2022 走看看