Exemplo n.º 1
0
 def linux(self):
     '''
     执行命令,获取资产信息
     :return:
     '''
     ret = {'status': True, 'data': None, 'error': None}
     ret = response.BaseResponse()
     try:
         result = self.cmd('nic')
         ret.data = result
     except Exception as e:
         ret.status = False
         ret.error = traceback.format_exc()
     return ret
Exemplo n.º 2
0
 def linux(self):
     '''
     执行命令,获取资产信息
     :return:
     '''
     ret = response.BaseResponse()
     try:
         result = self.cmd('mem')
         ret.data = result
     except Exception as e:
         ret.status = False
         ret.error = traceback.format_exc()
         obj = logger_helper.LoggerHelper.instance()
         obj.error_logger.log(logging.FATAL,ret.error)
     return ret
Exemplo n.º 3
0
 def linux(self):
     '''
     执行命令,获取资产信息
     :return:
     '''
     ret = response.BaseResponse()
     try:
         if self.test_mode:
             result = open(os.path.join(settings.BASE_DIR,'files/disk.out'),'r').read()
         else:
             shell_command = 'sudo MegaCli  -PDList -aALL'
             result = self.cmd(shell_command)
         ret.data = result
     except Exception as e:
         ret.status = False
         ret.error = traceback.format_exc()
         obj = logger_helper.LoggerHelper.instance()
         obj.error_logger.log(logging.FATAL,ret.error)
     return ret
Exemplo n.º 4
0
from json import JSONEncoder
from lib import response
import json


class JsonCustomerEncoder(JSONEncoder):
    def default(self, o):
        if isinstance(o, response.BaseResponse):
            return o.__dict__
        return JSONEncoder.default(self, o)


if __name__ == '__main__':
    resp = response.BaseResponse()
    print(json.dumps(resp, cls=JsonCustomerEncoder))