summaryrefslogtreecommitdiff
path: root/py_common/common_modules_operator.py
blob: 09605b36366a9db697656f966100a713751e8915 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#coding=utf-8
import os
import sys
import syslog
import subprocess
import time
import re
import logging
from sys import path
path.append(r'../py_common') #将存放module的路径添加进来
path.append(r'./py_common') #将存放module的路径添加进来
from common_json import *

# coding: utf-8
#先根据tsg_chassis_ip.json, 根据当前设备的ip地址, 知道当前设备的sled名称
#然后根据设备类型名称, 找到当前运行的所有模块(应用)名称
#然后根据模块名称, 到common_modules_operator.json查找每个模块的操作方法
#此文件定义, 每个模块的启动、停止、检查运行状态的方法
#操作方法参数说明:
#
# prog_name: 实际运行进程名称, 如kni模块实际运行的是sapp
# extra_progs: 其他需要kill的附加程序, 如sapp的r3守护, 需要杀掉, 否则后台可能会重复启动sapp
# module_cwd:  应用的绝对路径
# module_exe: 启动应用的名称, 可能跟module_name不一样, 比如用r2启动sapp
# stop_method: 停止应用方法  
# start_method: 启动应用方法  
# check_method: 检测应用是否运行方法  
#  
#例如:   "kni": ["sapp", "r3", "/home/tsg/kni", "r2", "killall", "exec", "ps"],

G_MODULE_DEPLOY_JSON = "/opt/tsg/etc/tsg_module_deploy.json"

TSG_OP_MODULE_NAME_INDEX = 0
TSG_OP_MODULE_EXTRA_INDEX = 1
TSG_OP_MODULE_CWD_INDEX = 2
TSG_OP_MODULE_EXE_INDEX = 3
TSG_OP_MODULE_STOP_INDEX = 4
TSG_OP_MODULE_START_INDEX = 5
TSG_OP_MODULE_STATUS_INDEX = 6

def tsg_get_module_opertor(module_name):
    empty = []
    
    ret, err_msg, json_dict = tsg_json_parse(G_MODULE_DEPLOY_JSON)   
    if ret != 0:
        print("open or parse json file %s error, %s" %(G_MODULE_DEPLOY_JSON, err_msg))
        return empty  
		
    module_oplist = json_dict['modules_operator']
    if len(module_oplist) <= 0:
        print("can't get modules_operator from %s" %(G_MODULE_DEPLOY_JSON))
        return empty

    for module_operator in module_oplist:
        if module_operator == module_name:
            #print(module_oplist[module_operator])
            return module_oplist[module_operator]
        
    return empty