示例#1
0
def invoke(dirconf, pgm, confname, action):

    program = 'sr_' + pgm
    config = re.sub(r'(\.conf)', '', confname)

    # c does not implement action sanity yet
    cfg.logger.info("action %s" % action)

    try:
        # anything but sr_post
        if program != 'sr_post':
            cfg.logger.debug("%s %s %s" % (program, action, config))
            cfg.run_command([program, action, config])
            return

        # sr_post needs -c with absolute confpath

        confpath = dirconf + os.sep + pgm + os.sep + confname
        post = sr_post(confpath)

        cfg.logger.debug("INVOKE %s %s %s %s" %
                         (program, '-c', confpath, action))
        cfg.run_command([program, '-c', confpath, action])
        return

    except:
        (stype, svalue, tb) = sys.exc_info()
        print("sr/invoke Type: %s, Value: %s" % (stype, svalue))
示例#2
0
文件: sr.py 项目: jeixav/sarracenia
def instantiate(dirconf, pgm, confname, action):

    # c stuff always requiere to spawn a call

    if pgm in ['audit', 'cpost', 'cpump']:
        # try to avoid error code while running sanity
        if action == 'sanity': return
        cfg.logger.debug("%s %s %s" % ("sr_" + pgm, action, confname))
        cfg.run_command(["sr_" + pgm, action, confname])
        return

    #print(dirconf,pgm,confname,action)

    config = re.sub(r'(\.conf)', '', confname)
    orig = sys.argv[0]

    sys.argv[0] = 'sr_' + pgm

    try:
        inst = None
        cfg.logger.debug("inst %s %s %s" % (pgm, config, action))
        if pgm == 'poll': inst = sr_poll(config, [action])
        elif pgm == 'post': inst = sr_post(config, [action])
        elif pgm == 'sarra': inst = sr_sarra(config, [action])
        elif pgm == 'sender': inst = sr_sender(config, [action])
        elif pgm == 'shovel': inst = sr_shovel(config, [action])
        elif pgm == 'subscribe': inst = sr_subscribe(config, [action])
        elif pgm == 'watch': inst = sr_watch(config, [action])
        elif pgm == 'winnow': inst = sr_winnow(config, [action])
        elif pgm == 'report': inst = sr_report(config, [action])
        elif pgm == 'audit': inst = sr_audit(config, [action])
        else:
            cfg.logger.error("code not configured for process type sr_%s" %
                             pgm)
            sys.exit(1)

        if action == 'cleanup': inst.exec_action('cleanup', False)
        elif action == 'declare': inst.exec_action('declare', False)
        elif action == 'setup': inst.exec_action('setup', False)

        elif action == 'remove': inst.exec_action('remove', False)

        sys.argv[0] = orig

    except:
        cfg.logger.error("could not instantiate and run sr_%s %s %s" %
                         (pgm, action, confname))
        sys.exit(1)
示例#3
0
文件: sr.py 项目: jeixav/sarracenia
def invoke(dirconf, pgm, confname, action):

    program = 'sr_' + pgm
    config = re.sub(r'(\.conf)', '', confname)

    # c does not implement action sanity yet
    cfg.logger.info("action %s" % action)

    try:
        # anything but sr_post
        if program != 'sr_post':
            cfg.logger.debug("%s %s %s" % (program, action, config))
            cfg.run_command([program, action, config])
            return

        # sr_post needs -c with absolute confpath

        confpath = dirconf + os.sep + pgm + os.sep + confname
        sleeps = False

        if (action == 'status'):
            f = open(confpath, 'r')
            for li in f.readlines():
                l = li.split()
                if len(l) < 2:
                    continue

                if l[0] == 'sleep':
                    if float(l[1]) > 0:
                        sleeps = True
            f.close()

        if not sleeps:
            return

        post = sr_post(confpath)

        cfg.logger.debug("INVOKE %s %s %s %s" %
                         (program, '-c', confpath, action))
        cfg.run_command([program, '-c', confpath, action])
        return

    except:
        cfg.logger.error("Invoke failed")
        cfg.logger.debug('Exception details: ', exc_info=True)
示例#4
0
 def __init__(self, config=None, args=None):
     self.post = sr_post(config, args)
     sr_instances.__init__(self, config, args)
示例#5
0
 def __init__(self,config=None,args=None):
     self.post = sr_post(config,args)
     sr_instances.__init__(self,config,args)