• 自定义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

  • 相关阅读:
    学校的破网,你别再掉了
    PhotoShop SDK的获取
    我的C++博客开张了
    一个新的嵌入式门户
    试用Bloglines.com
    PhotoShop的插件体系
    VB6 to VB.NET Migration Guide Community Preview #4
    看看Microsoft都买了些什么
    Borland CTO辞职
    PhotoShop插件的开发
  • 原文地址:https://www.cnblogs.com/Dev0ps/p/8242620.html
Copyright © 2020-2023  润新知