def dir(request, action, env): if request.is_ajax() and request.method == 'POST': url = str('%s%s' % (__shiva_url, methodEnum.server_url_info_get)) severUrlInfo = HttpHelper().url(url).headers().post( json.dumps({'env': env}), HttpHelper().getData) kwargs = { 'env': env, 'url': severUrlInfo[0]['url'], 'port': severUrlInfo[0]['port'], 'out_time': severUrlInfo[0]['out_time'] } if action == 'scan': params = requestDict().dirScanDict(request.POST['dirPath']) jsonData = httpTohnoUtils(params, methodEnum.dir_scan, **kwargs).httpTohnoWithPost() return HttpResponse(jsonData) if action == 'addDir': params = requestDict().dirCreateDict(request.POST['dirPath']) jsonData = httpTohnoUtils(params, methodEnum.dir_create, **kwargs).httpTohnoWithPost() return HttpResponse(jsonData) if action == 'deleteDir': params = requestDict().dirDeleteDict(request.POST['dirPath']) jsonData = httpTohnoUtils(params, methodEnum.dir_delete, **kwargs).httpTohnoWithPost() return HttpResponse(jsonData) if action == 'renameDir': params = requestDict().dirRenameDict(request.POST['parentDir'], request.POST['newName'], request.POST['oldName']) jsonData = httpTohnoUtils(params, methodEnum.dir_rename, **kwargs).httpTohnoWithPost() return HttpResponse(jsonData)
def get_context_data(self, **kwargs): context = super(configFileManage, self).get_context_data(**kwargs) url = 'http://%s:%s%s%s' % (SHIVA_URL, SHIVA_PORT, SHIVA_VERSION, methodEnum.server_url_infos) jsonData = HttpHelper().url(url).get(func=HttpHelper().getData) context['serverUrlInfos'] = jsonData return context
def fileHandle(request, action, env): if request.is_ajax() and request.method == 'POST': url = str('%s%s' % (__shiva_url, methodEnum.server_url_info_get)) severUrlInfo = HttpHelper().url(url).headers().post( json.dumps({'env': env}), HttpHelper().getData) kwargs = { 'env': env, 'url': severUrlInfo[0]['url'], 'port': severUrlInfo[0]['port'], 'out_time': severUrlInfo[0]['out_time'] } if action == 'renameFile': params = requestDict().fileRenameDict(request.POST['parentDir'], request.POST['newName'], request.POST['oldName']) jsonData = httpTohnoUtils(params, methodEnum.dir_rename, **kwargs).httpTohnoWithPost() return HttpResponse(jsonData) if action == 'createFile': params = requestDict().fileCreateDict( json.loads(request.POST['configFileInfo'])) jsonData = httpTohnoUtils(params, methodEnum.file_create, **kwargs).httpTohnoWithPost() return HttpResponse(jsonData) if action == 'updateFile': params = requestDict().fileUpdateDict( json.loads(request.POST['configFileInfo'])) jsonData = httpTohnoUtils(params, methodEnum.file_update, **kwargs).httpTohnoWithPost() return HttpResponse(jsonData) if action == 'getFile': params = requestDict().fileGetDict(request.POST['filePath']) jsonData = httpTohnoUtils(params, methodEnum.file_get, **kwargs).httpTohnoWithPost() return HttpResponse(jsonData) if action == 'getFileBackup': params = requestDict().fileGetBackupDict( request.POST['filePath'], request.POST['backupfile']) jsonData = httpTohnoUtils(params, methodEnum.file_backupget, **kwargs).httpTohnoWithPost() return HttpResponse(jsonData) if action == 'deleteFile': params = requestDict().fileDeleteDict(request.POST['filePath']) jsonData = httpTohnoUtils(params, methodEnum.file_delete, **kwargs).httpTohnoWithPost() return HttpResponse(jsonData)
def getServerUrlInfo(request, env): url = str('%s%s' % (__shiva_url, methodEnum.server_url_info_get)) serverUrlInfo = HttpHelper().url(url).headers().post( json.dumps({'env': env}), HttpHelper().getData) jsonData = httpTohnoUtils(None, methodEnum.server_infos, env, serverUrlInfo[0]['url'], serverUrlInfo[0]['port'], serverUrlInfo[0]['out_time']).httpTohonWithGet() res = set() for item in jsonData['hostinfos']: if item['groupname']: res.add('file:%s' % item['groupname']) if item['hosts']: res.update(map(conventForFile, item['hosts'])) for item in jsonData['zkinfos']: if item['zkname']: res.add('zk:%s' % item['zkname']) return HttpResponse('|'.join(res))
def tpHandle(request, action): if request.is_ajax() and request.method == 'POST': if action == 'get': try: url = str( '%s%s/%s' % (__shiva_url, methodEnum.templateFile, request.POST['id'])) obj = HttpHelper().url(url).get(func=HttpHelper().getData) obj[0]['content'] = base64.b64decode(obj[0]['content']) return HttpResponse(json.dumps(obj[0])) except Exception, e: logging.error('tpHandle>get>exception:%s' % e) if action == 'getTpList': try: data = HttpHelper().url( '%s%s' % (__shiva_url, methodEnum.templateFileList)).get( func=HttpHelper().getData) return HttpResponse(json.dumps(data)) except Exception, e: logging.error('tpHandle>getTpList>exception:%s' % e)
def getTplist(request): """ :param request: :return: 返回模板文件列表 """ try: url = '%s%s' % (__shiva_url, methodEnum.templateFileList) data = HttpHelper().url(url).get(func=HttpHelper().getData) listSet = [] dic = {} for obj in data: #%Y-%m-%d %H:%M:%S listSet.append([ obj['name'], datetime.datetime.strptime( obj['modify_time'], "%a, %d %b %Y %H:%M:%S GMT").strftime('%Y-%m-%d %H:%M:%S'), obj['id'] ]) dic['data'] = listSet return HttpResponse(json.dumps(dic)) except Exception, e: logging.error('getTplist>exception:%s' % e)
jsonDataDict = {} try: fileInfo = json.loads(request.POST['fileInfo']) requestData = {} jsonDataDict['code'] = 0 jsonDataDict['msg'] = '处理成功' requestData['name'] = fileInfo['fileName'] requestData['content'] = fileInfo['fileContent'] requestData['modify_time'] = time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime()) if len(fileInfo['id']) > 0: requestData['id'] = fileInfo['id'] url = str( '%s%s/%s' % (__shiva_url, methodEnum.templateFile, fileInfo['id'])) rowCount = HttpHelper().url(url).headers().put( json.dumps(requestData), func=HttpHelper().getData) if not rowCount: jsonDataDict['code'] = -1 jsonDataDict['msg'] = '系统异常,请联系管理员' return HttpResponse(json.dumps(jsonDataDict)) else: url = str('%s%s' % (__shiva_url, methodEnum.templateFile)) rowCount = HttpHelper().url(url).headers().post( json.dumps(requestData), func=HttpHelper().getData) if not rowCount: jsonDataDict['code'] = -1 jsonDataDict['msg'] = '系统异常,请联系管理员' return HttpResponse(json.dumps(jsonDataDict)) except Exception, e: logging.error('tpHandle>save>exception:%s' % e) jsonDataDict['code'] = -1