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

  • 相关阅读:
    轻院:2211: 小明的有趣回文数
    轻院:2209: 小明找整数
    轻院:2206: 小明发福利
    轻院:2207: 小明被提问
    2135: 这里是天堂!
    牛客小白月赛2:文
    轻院2261: flower
    问题 I: 堆
    SharePoint Server 2010安装图解
    Microsoft Windows Sharepoint Services V3.0 安装图示
  • 原文地址:https://www.cnblogs.com/Dev0ps/p/8242620.html
Copyright © 2011-2022 走看看