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

  • 相关阅读:
    9.Java通过axis调用WebService
    8.AXIS1基础
    7.Web Service 调用天气代码
    Exception in thread "main" java.lang.NoClassDefFoundError: org.jaxen.NamespaceContext
    webservices 服务器未能识别 HTTP 头 SOAPAction 的值:.
    几种流行Webservice框架性能对比
    6. 使用Axis开发WebService程序
    5. webservice通信调用天气预报接口实例
    4.菜鸟教你一步一步开发 web service 之 axis 客户端创建
    3.菜鸟教你一步一步开发 web service 之 axis 服务端创建
  • 原文地址:https://www.cnblogs.com/Dev0ps/p/8242620.html
Copyright © 2011-2022 走看看