Ejemplo n.º 1
0
def run_cell(request, debug=False):
    request.method = 'GET'
    cell_id = request.GET.get('cell_id', '')
    try:
        assert bool(cell_id) == True
    except AssertionError:
        return JsonResponse(dict(status=500, msg='input args error'))
    # return JsonResponse(dict(status=200)) if is_rpc_started(cell_id) else JsonResponse(dict(status=500))
    # tmp_bool = is_rpc_started("test")
    if debug == False:
        cmdb_cell_table = CmdbCellTable(request)
        cell_config = cmdb_cell_table.get_cell_config(cell_id)
        # connections = cmdb_cell_table.get_cell_connections(cell_id)
    else:
        cell_config = [{
            'ip': '172.29.164.91',
            'cpu': 2.0,
            'mem': 4.0,
            'disk': 50.0,
            'node_type': 'jar',
            'node_name': 'kfc_preorder_nh_online_sgemfb8r_jar2'
        }]
    hu = HttpUtils(request)
    hu.post(serivceName='p_job',
            restName='/rest/cell/deploy/',
            datas=dict(host_list=cell_config, cell_name=cell_id))
    tmp_bool = True
    if tmp_bool:
        return JsonResponse(dict(status=200))
    else:
        return JsonResponse(dict(status=500))
Ejemplo n.º 2
0
 def post_ajax(self, request, *args, **kwargs):
     result = {}
     try:
         req = self.request
         devopsgroup = req.devopsgroup
         hu = HttpUtils(req)
         reqData = hu.getRequestParam()
         env = reqData.get("env",None)
         preResult = hu.post(serivceName="job", restName="/rest/deploy/pre_download/", datas=reqData)
         preResult = preResult.json()
         if preResult["status"] == "SUCCESS":
             result['status'] = 0
             result['msg'] = "pre执行成功"
             if devopsgroup == 'store':
                 if env == 'pilot':
                     appId = reqData.get("appId", None)
                     version = reqData.get("param4", None)
                     addResult = hu.post(serivceName="job", restName="/rest/deploy/app_add_version/", datas={"id":appId,"version":version})
                     addResult = addResult.json()
                     if addResult["status"] == "FAILURE":
                         result['status'] = 0
                         result['msg'] = "pre灰度保存版本失败"
             elif devopsgroup == 'ec':
                 app_ids = reqData.get("appIds", [])
                 app_ids = json.loads(app_ids)
                 param2 = input_dict.get("param2", "")
                 for appId in app_ids:
                     addResult = hu.post(serivceName="job", restName="/rest/deploy/app_add_version/",datas={"id": appId, "version": param2})
                     addResult = addResult.json()
                     if addResult["status"] == "FAILURE":
                         result['status'] = 0
                         result['msg'] = "pre灰度保存版本失败"
             elif devopsgroup == 'brand':
                 appId = reqData.get("appId", None)
                 version_list = preResult['version_list']
                 for version in version_list:
                     addResult = hu.post(serivceName="job", restName="/rest/deploy/app_add_version/",
                                         datas={"id": appId, "version": version})
                     addResult = addResult.json()
                     if addResult["status"] == "FAILURE":
                         result['status'] = 0
                         result['msg'] = "pre灰度保存版本失败"
         else:
             result['status'] = 1
             result['msg'] = "pre执行失败"
     except Exception as e:
         result['status'] = 1
         result['msg'] = "pre执行异常"
         logger.error(e)
     return HttpResponse(json.dumps(result), content_type='application/json')
Ejemplo n.º 3
0
    def post_ajax(self, request, *args, **kwargs):
        result = {'status': 0}
        try:
            hu = HttpUtils(self.request)
            reqData = hu.getRequestParam()
            saveJson = reqData.get("saveJson",None);
            if saveJson:
                resultAdd = hu.post(serivceName="presrb", restName="/rest/presrb/project_add/", datas=saveJson)
                resultJson = resultAdd.json()
                if resultJson['status'] == 'SUCCESS':
                    result['status'] = 0
                    result['p_id'] = resultJson.get("p_id","")
                    result['msg'] = '保存成功'
                else:
                    result['status'] = 1
                    result['msg'] = '保存失败'
            else:
                result['status'] = 1
                result['msg'] = '保存值为空'

        except Exception as e:
            result['status'] = 1
            result['msg'] = '保存异常'
            logger.error(e,exc_info=1)
        return HttpResponse(json.dumps(result),content_type='application/json')
Ejemplo n.º 4
0
    def post_ajax(self, request, *args, **kwargs):
        resultJson = {}
        try:
            saveJson = request.POST.get("saveJson", None)
            saveJson = eval(saveJson)
            hu = HttpUtils(request)
            # updateResult = hu.post(serivceName="presrb", restName="/rest/presrb/project_update/", datas={"p_id":saveJson.get("p_id",0),"deploy_envs":saveJson.get("deploy_envs",0),"change":0})
            # updateJson = updateResult.json()
            # if updateJson.get("status") == "SUCCESS":
            #     resultJson1 = hu.post(serivceName="presrb", restName="/rest/presrb/projectItem_add/", datas=saveJson)
            #     resultJson2 = resultJson1.json()
            #     if resultJson2.get("status") == "SUCCESS":
            #         resultJson["status"] = 0
            #     else:
            #         resultJson["status"] = 1
            #         resultJson["msg"] = "保存应用配置失败"

            resultJson1 = hu.post(serivceName="presrb", restName="/rest/presrb/projectItem_add/", datas=saveJson)
            resultJson2 = resultJson1.json()
            if resultJson2.get("status") == "SUCCESS":
                resultJson["status"] = 0
            else:
                resultJson["status"] = 1
                resultJson["msg"] = "保存应用配置失败"

        except Exception as e:
            resultJson["status"] = 1
            resultJson["msg"] = "保存应用配置异常"
            logger.error(e,exc_info=1)
        return HttpResponse(json.dumps(resultJson), content_type='application/json')
Ejemplo n.º 5
0
 def get_ajax(self, request, *args, **kwargs):
     result = {'status': 0}
     try:
         hu = HttpUtils(request)
         id = request.GET.get('id', None)
         if id:
             addAppResults = hu.post(
                 serivceName="p_job",
                 restName="/rest/flowcontrol/deleteById/",
                 datas={'id': id})
             addAppResults = addAppResults.json()
             if addAppResults['status'] == 200:
                 result['status'] = 0
                 result['msg'] = '删除成功'
             else:
                 result['status'] = 1
                 result['msg'] = '删除失败'
         else:
             result['status'] = 1
             result['msg'] = '删除失败'
     except Exception as e:
         result['status'] = 1
         result['msg'] = '删除异常'
         logger.error(e, exc_info=1)
     return HttpResponse(json.dumps(result),
                         content_type='application/json')
Ejemplo n.º 6
0
 def post_ajax(self, request, *args, **kwargs):
     result = {'status': 0}
     try:
         hu = HttpUtils(self.request)
         reqData = hu.getRequestParam()
         app_id = reqData.get("id", None)
         if app_id:
             del reqData['offset']
             del reqData['limit']
             del reqData['csrfmiddlewaretoken']
             deploy_tool_update_result = hu.post(serivceName="p_job", restName="/rest/deploytool/updateById/", datas=reqData) #/rest/deploytool/update/
             deploy_tool_update = deploy_tool_update_result.json()
             if deploy_tool_update['status'] == 200:
                 result['status'] = 0
                 result['msg'] = deploy_tool_update['msg']
             else:
                 result['status'] = 1
                 result['msg'] = '更新发版信息失败'
         else:
             result['status'] = 1
             result['msg'] = '更新发版信息失败'
     except Exception as e:
         result['status'] = 1
         result['msg'] = '更新异常'
         logger.error(e)
     return HttpResponse(json.dumps(result), content_type='application/json')
Ejemplo n.º 7
0
    def post_ajax(self, request, *args, **kwargs):
        files = request.FILES
        path = request.POST.get("path", None)
        resultJson = {}
        if path:
            saveJson = request.POST.get("saveJson", None)
            hu = HttpUtils(request)
            result = hu.post(serivceName="job",
                             restName="/rest/file/add/",
                             datas=saveJson)
            resultJson = result.json()
            if resultJson['status'] == "SUCCESS":
                try:
                    file = files['files']
                    filePath = UPLOAD_SCRIPT_PATH + path
                    filePath = filePath.replace('//', '/')
                    destination = open(os.path.join(filePath, file.name),
                                       'wb+')
                    for chunk in file.chunks():
                        destination.write(chunk)
                    destination.close()

                    (status,
                     output) = subprocess.getstatusoutput("sed -i 's/\r$//' " +
                                                          UPLOAD_SCRIPT_PATH +
                                                          path + file.name)
                    if status != 0:
                        logger.error(output)
                except Exception as e:
                    logger.error(e)
        else:
            resultJson['status'] = 'fail'
            resultJson['msg'] = '文件夹路径为空'
        return self.render_json_response(resultJson)
Ejemplo n.º 8
0
def forward_to_service(request):
    results = {}
    try:
        method = request.method
        hu = HttpUtils(request)
        if method == "GET":
            req_get = request.GET
            serivceName = req_get.get("serivceName", None)
            restName = req_get.get("restName", None)
            req_data = req_get.get("req_data", None)
            if serivceName and restName:
                results = hu.get(serivceName=serivceName,
                                 restName=restName,
                                 datas=req_data)
            else:
                results['status'] = 500
        else:
            req_post = request.POST
            serivceName = req_post.get("serivceName", None)
            restName = req_post.get("restName", None)
            req_data = req_post.get("req_data", None)
            if serivceName and restName:
                p_result = hu.post(serivceName=serivceName,
                                   restName=restName,
                                   datas=req_data)
                results = json.dumps(p_result.json())
            else:
                results['status'] = 500
    except Exception as e:
        logger.error(e, exc_info=1)
        results['status'] = 500
    return HttpResponse(json.dumps(results), content_type='application/json')
Ejemplo n.º 9
0
 def post(self, request, *args, **kwargs):
     result_json = {"status": 1}
     try:
         groupId = request.POST.get("group_id", None)
         host_ids = request.POST.get("host_ids", None)
         if groupId and host_ids:
             hu = HttpUtils(request)
             reqParam = {
                 "group_id": groupId,
                 "host_ids": host_ids.split(',')
             }
             updateResult = hu.post(
                 serivceName="cmdb",
                 restName="/rest/hostgroup/batch_host_unbind_group/",
                 datas=reqParam)  #/rest/hostgroup/static_group_delete/
             result = updateResult.json()
             if result['status'] == 200:
                 result_json = {
                     "status": 0,
                     'failCount': len(result['500']),
                     'successCount': len(result['200'])
                 }
             else:
                 result_json = {
                     "status": 1,
                     'failCount': len(result['500']),
                     'successCount': len(result['200'])
                 }
     except Exception as e:
         logger.error(e, exc_info=1)
     return self.render_json_response(result_json)
Ejemplo n.º 10
0
    def post_ajax(self, request, *args, **kwargs):
        result_json = {"status": 1}
        try:
            flag = request.POST.get("flag", None)
            if flag:
                hu = HttpUtils(request)
                go_live = request.POST.get("status")
                reqParam = []
                if flag == '1':
                    ip_list = json.loads(request.POST.get("ip_list"))
                    for ip in ip_list:
                        reqParam.append({'go_live': go_live, 'host_ip': ip})
                else:
                    seach = json.loads(request.POST.get("seach", None))
                    seach['go_live'] = 2
                    resultJson = hu.get(serivceName="cmdb",
                                        restName="/rest/host/",
                                        datas=seach)
                    list = resultJson.get("results", [])
                    for l in list:
                        reqParam.append({
                            'go_live': go_live,
                            'host_ip': l.get("host_ip")
                        })

                updateResult = hu.post(serivceName="cmdb",
                                       restName="/rest/host/update/",
                                       datas=reqParam)
                result = updateResult.json()
                if result['status'] == '0':
                    result_json = {"status": 0}
        except Exception as e:
            logger.error(e)
        return self.render_json_response(result_json)
Ejemplo n.º 11
0
 def post_ajax(self, request, *args, **kwargs):
     result = {'status': 0}
     try:
         hu = HttpUtils(self.request)
         reqData = hu.getRequestParam()
         app_id = reqData.get("id", None)
         if app_id:
             del reqData['offset']
             del reqData['limit']
             del reqData['csrfmiddlewaretoken']
             addAppResults = hu.post(serivceName="p_job",
                                     restName="/rest/appmanage/updateById/",
                                     datas=reqData)  #/rest/app/update_app/
             addAppResults = addAppResults.json()
             if addAppResults['status'] == 200:
                 result['status'] = 200
                 result['msg'] = '更新应用信息成功'
             else:
                 result['status'] = 500
                 result['msg'] = '更新应用信息失败'
         else:
             result['status'] = 500
             result['msg'] = '更新应用信息失败'
     except Exception as e:
         result['status'] = 500
         result['msg'] = '更新异常'
         logger.error(e, exc_info=1)
     return HttpResponse(json.dumps(result),
                         content_type='application/json')
Ejemplo n.º 12
0
 def get_context_data(self, **kwargs):
     context = super(List3View, self).get_context_data(**kwargs)
     try:
         req = self.request
         hu = HttpUtils(req)
         reqData = hu.getRequestParam()
         host = reqData.get('host', None)
         if host:
             host = json.loads(host)
             host['go_live'] = 3
             reqData['host'] = host
         else:
             reqData['host'] = {'go_live': 3}
         tree = reqData.get('tree', None)
         if tree:
             reqData['tree'] = json.loads(tree)
         resultJson = hu.post(serivceName="cmdb",
                              restName="/rest/host/list/",
                              datas=reqData)
         resultJson = resultJson.json()
         list = resultJson.get("results", [])
         #hostgroupResult = hu.get(serivceName="cmdb", restName="/rest/host/host_group_list/", datas={})
         hostGroup_list = RedisBase.get("host_group_3", 2)
         count = resultJson.get("count", 0)
         paginator = Paginator(list, req.limit)
         paginator.count = count
         context['result_list'] = list
         context['is_paginated'] = count > 0
         context['page_obj'] = paginator.page(req.offset)
         context['paginator'] = paginator
         context['hostGroup_list'] = hostGroup_list
     except Exception as e:
         logger.error(e, exc_info=1)
     return context
Ejemplo n.º 13
0
def push_key(request,
             cell_id,
             cell_config,
             connections,
             ssh_user,
             ssh_passwd,
             debug=False):
    """
    push key file to servers derived from excel
    """
    print("cell_id is %s" % (cell_id))
    if debug:
        cell_config = [{
            'ip': '172.29.164.91',
            'cpu': 2.0,
            'mem': 4.0,
            'disk': 50.0,
            'node_type': 'jar',
            'node_name': 'kfc_preorder_nh_online_sgemfb8r_jar2'
        }]

        connections = {'a': 'b'}
    hu = HttpUtils(request)
    ret = hu.post(serivceName='p_job',
                  restName='/rest/cell/authorizedkey/',
                  datas=dict(host_list=cell_config,
                             relation_dict=connections,
                             cell_name=cell_id,
                             ssh_user=ssh_user,
                             ssh_passwd=ssh_passwd))
    print(ret)
Ejemplo n.º 14
0
    def post_ajax(self, request, *args, **kwargs):
        result = {'status': 0}
        try:
            user = request.user
            files = request.FILES
            command_set = request.POST.get("command_set",None)

            hu = HttpUtils()
            resultJson = hu.post(serivceName="job", restName="/rest/job/add/", datas=command_set)
            resultJson  = eval(resultJson.text)
            if(resultJson["status"] == "FAILURE"):
                result['status'] = 1
            else:
                data = resultJson["data"]
                for k in data:
                    step_ids = data[k]
                    for file in files:
                        t = file.split(',')
                        step = step_ids[int(t[0])]
                        f = files[file]
                        path = UPLOAD_SCRIPT_PATH + k + "/"
                        for k2 in step:
                            line = step[k2]
                            path += str(k2) + "/"+str(line[int(t[1])])+"/"
                            os.makedirs(path)
                            destination = open(os.path.join(path, f.name), 'wb+')
                            for chunk in f.chunks():
                                destination.write(chunk)
                            destination.close()
        except Exception as e:
            logger.error(e)
        return HttpResponse(json.dumps(result),content_type='application/json')
Ejemplo n.º 15
0
    def post_ajax(self, request, *args, **kwargs):
        result = {'status': 0}
        try:
            hu = HttpUtils(self.request)
            reqData = hu.getRequestParam()
            script_lang_dict = {'shell': 'sh', 'python': 'py', 'yaml': 'yaml'}
            if reqData:
                logger.info("DevopsToolsCreateView.post_ajax reqData:%s" %
                            (reqData))
                #tool_set_prime_type = reqData.get("tool_set_prime_type",None)
                tool_type = reqData.get("tool_type", None)
                if tool_type:
                    fileName = ""
                    #if tool_type == '5':
                    t = time.time()
                    toolScriptPath = settings.TOOL_SCRIPT_PATH  #'/opt/devops/tool_script/'
                    command = reqData.get("command", None)
                    script_lang = reqData.get("script_lang", "shell")
                    try:
                        if not os.path.exists(toolScriptPath):
                            os.makedirs(toolScriptPath)
                        fileName = "%s%s%s.%s" % (
                            toolScriptPath, int(round(t * 1000)),
                            randomCharStr(), script_lang_dict[script_lang])
                        f = open(fileName, 'w')
                        f.write(command)
                        os.chmod(fileName,
                                 stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU)
                        reqData['command'] = fileName
                        reqData['script_md5'] = md5(command)
                    except Exception as e:
                        logger.error(e, exc_info=1)
                    finally:
                        f.close()

                    addResult = hu.post(
                        serivceName="p_job",
                        restName="/rest/tool/add/",
                        datas=reqData)  #/rest/job/add_tool_set/
                    addResultJson = addResult.json()
                    if addResultJson['status'] == 200:
                        result['status'] = 0
                        result['msg'] = '保存成功'
                    else:
                        remove_file(fileName)
                        result['status'] = 1
                        result['msg'] = addResultJson['msg']
                else:
                    result['status'] = 1
                    result['msg'] = '未检测到类别和类型信息,保存失败'
            else:
                result['status'] = 1
                result['msg'] = '保存值为空'

        except Exception as e:
            result['status'] = 1
            result['msg'] = '保存异常'
            logger.error(e, exc_info=1)
        return HttpResponse(json.dumps(result),
                            content_type='application/json')
Ejemplo n.º 16
0
 def post_ajax(self, request, *args, **kwargs):
     result = {}
     try:
         req = self.request
         hu = HttpUtils(req)
         reqData = hu.getRequestParam()
         id = reqData.get("id",None)
         appids = reqData.get("app_ids",None)
         idc = reqData.get("idc",None)
         env = reqData.get("env",None)
         version = reqData.get("version",None)
         #is_all = reqData.get("is_all",0)
         if id and appids:
             appids = json.loads(appids)
             setRunResult = hu.post(serivceName="job", restName="/rest/deploy/set_run_version/",datas={"id": id, "app_ids": appids, "idc": idc, "env": env,"version":version})
             # setRunResult = hu.post(serivceName="job", restName="/rest/deploy/set_run/", datas={"id":id,"app_ids":appids,"idc":idc,"env":env})
             setRunResult = setRunResult.json()
             if setRunResult['status'] == "SUCCESS":
                 result['status'] = 0
                 result['msg'] = "发布成功,后端正在执行中"
             else:
                 result['status'] = 1
                 result['msg'] = setRunResult['msg']
         else:
             result['status'] = 1
             result['msg'] = "发布失败"
     except Exception as e:
         result['status'] = 1
         result['msg'] = "发布异常"
         logger.error(e)
     return HttpResponse(json.dumps(result),content_type='application/json')
Ejemplo n.º 17
0
 def get(self, request, *args, **kwargs):
     req = self.request
     id = req.GET.get("id", 0)
     hu = HttpUtils(req)
     resultJson = hu.post(serivceName="p_job",
                          restName="/rest/commandset/deleteById/",
                          datas={"id": id})
     return self.render_json_response(resultJson.json())
Ejemplo n.º 18
0
 def get_context_data(self, **kwargs):
     context = super(Host1DetailView, self).get_context_data(**kwargs)
     hu = HttpUtils(self.request)
     result = hu.post(serivceName="cmdb", restName="/rest/host/id_list/", datas={'host_id':[kwargs.get('pk')]})
     list = result.json().get("result", [])
     if list:
         context['host_info'] = list[0]
     else:
         context['host_info'] = {}
     return context
Ejemplo n.º 19
0
 def get_ajax(self, request, *args, **kwargs):
     resultJson = {}
     try:
         req_get = request.GET
         hu = HttpUtils(request)
         resultJson1 = hu.post(serivceName="presrb", restName="/rest/presrb/project_status_update/", datas={"p_id":req_get['p_id'],"status":req_get['status']})
         resultJson = resultJson1.json()
     except Exception as e:
         logger.error(e,exc_info=1)
     return HttpResponse(json.dumps(resultJson), content_type='application/json')
Ejemplo n.º 20
0
def deploy_agent(request):
    if request.method == 'POST':
        data = json.loads(str(request.body, 'utf-8'))
        site_id = data['id']
        #site_name = data['site_name']
        host_list = data['hosts']
        version = data['version']
        hu = HttpUtils(request)
        result = hu.post(serivceName='p_job', restName='/rest/slb/deployagent/', datas={"id": site_id, "version": version, 'hosts':host_list})
        return JsonResponse(data=result.json())
Ejemplo n.º 21
0
def MappingRulesCreateOrUpdate(request):
    results = {}
    try:
        input_param = json.loads(str(request.body, 'utf-8'))
        if input_param:
            id = input_param['id']
            hu = HttpUtils(request)
            if int(id) < 0:
                input_param = trans_mappingRule(input_param)
                del input_param['id']
                post_results = hu.post(serivceName='p_job', restName='/rest/slb/addMappingRules/', datas=input_param)
                post_results = post_results.json()
                if post_results['status'] == 200:
                    results['status'] = 200
                    results['msg'] = "新增成功"
                    results['id'] = post_results['id']
                else:
                    results['status'] = 500
                    results['msg'] = "新增失败"
            else:
                mapping_rules_list = input_param['mapping_rules_list']
                new_mapping_rules_list = []
                for mapping_rule in mapping_rules_list:
                    tmp = trans_mappingRule(mapping_rule)
                    new_mapping_rules_list.append(tmp)
                input_param.update({'mapping_rules_list': new_mapping_rules_list})
                print(input_param)
                post_results = hu.post(serivceName='p_job', restName='/rest/slb/updateMappingRules/',datas=input_param)
                post_results = post_results.json()
                if post_results['status'] == 200:
                    results['status'] = 200
                    results['msg'] = "修改成功"
                else:
                    results['status'] = 500
                    results['msg'] = "修改失败"
        else:
            results['status'] = 500
            results['msg'] = "参数为空"
    except Exception as e:
        results['status'] = 500
        results['msg'] = "新增或更新异常"
        logger.error(e,exc_info=1)
    return JsonResponse(data=results)
Ejemplo n.º 22
0
def serviceClusterByID(request):
    #data={
            #"id":1,
            #"cluster_name":"kfc_preorder_nh_pilot_idc_nginx",
            #"check_up_timeout":3000,
            #"load_balancin_strategy":1,
            #"check_up_space":3000,
            #"check_up_type":1,
            #"keep_alive":20,
            #"pool_down_ratio": 'null',
            #"pool_force_down": 'null',
            #"is_enabled": True,
            #"created_by":"admin",
            #"updated_by":"admin",
            #"cluster_nodes":[
                #{"id":1,
                #"host_id":1,
                #"service_cluster_id":1,
                #"port":80,
                #"weight":30,
                #"max_fails":20,
                #"fail_timeout":40,
                #"state":1,
                #"host_ip":"1.1.1.1"
                #}]
        #}
    hu = HttpUtils(request)
    if request.method == 'GET':
        upstream_id = int(request.GET.get('id'))
        setListResult = hu.get(serivceName="p_job", restName="/rest/slb/serviceclusterbyid/", datas={'id': upstream_id})
        #print(setListResult)
        data = trans_cluster_detail(setListResult)
        return JsonResponse(data=dict(ret=data))
    elif request.method == 'POST':
        #print('str(request.body, 'utf-8'): %s' % str(request.body, 'utf-8'))
        data = json.loads(str(request.body, 'utf-8'))
        #try:
            #assert operation in ['create', 'update']
        #except AssertionError:
            #return JsonResponse(data=dict(status=500, msg="unsupported operation orz"))
        cluster_data = trans_cluster_detail(data, reverser=True)
        if data['id'] < 0:
            restName = "/rest/slb/serviceclustercreate/"
        else:
            restName = "/rest/slb/serviceclusterupdate/"
        #print('cluster_data: %s'%cluster_data)
        setListResult = hu.post(serivceName="p_job", restName=restName, datas=cluster_data)
        #print(json.loads(setListResult.content))
        #{'service_cluster_id': 12, 'status': 200, 'msg': '新增成功'}
        ret = setListResult.json()
        return JsonResponse(data=ret)
Ejemplo n.º 23
0
def config_preview(request):
    if request.method == 'POST':
        data = str(request.body, 'utf-8')
        data = json.loads(data)
        siteDetail = data['siteDetail']
        siteDetail = trans_siteInfo(siteDetail)
        #siteDetail = trans4configpreview(siteDetail)
        mplist = data['mplist']
        mplist = trans_mappingRuleList(mplist, cmd_list_flag=True)
        hu = HttpUtils(request)
        siteDetail.update({'locations': mplist})
        result = hu.post(serivceName='p_job',restName='/rest/slb/configpreview/', datas=siteDetail)
        result = result.json()
        return JsonResponse(data=dict(ret=result))
Ejemplo n.º 24
0
 def updateDns(self,req):
     result = {}
     saveJson = req.POST.get("saveJson", None)
     if saveJson:
         hu = HttpUtils(req)
         resultJson = hu.post(serivceName="cmdb", restName="/rest/dns_edit/", datas=saveJson)
         resultJson = resultJson.json()
         if resultJson['status'] == 'SUCCESS':
             result['status'] = 'SUCCESS';
         else:
             result['status'] = 'FAILURE';
             result['msg'] = resultJson['msg'];
     else:
         result['status'] = 'FAILURE';
     return result
Ejemplo n.º 25
0
 def createPhysical_idc(self,req):
     result = {}
     saveJson = req.POST.get("saveJson", None)
     if saveJson:
         hu = HttpUtils(req)
         resultJson = hu.post(serivceName="cmdb", restName="/rest/physicalIDC_add/", datas=saveJson)
         resultJson = resultJson.json()
         if resultJson['status'] == 'SUCCESS':
             result['status'] = 'SUCCESS';
         else:
             result['status'] = 'FAILURE';
             result['msg'] = resultJson['msg'];
     else:
         result['status'] = 'FAILURE';
     return result
Ejemplo n.º 26
0
 def createDeployment_environment(self,req):
     result = {}
     saveJson = req.POST.get("saveJson", None)
     if saveJson:
         hu = HttpUtils(req)
         resultJson = hu.post(serivceName="cmdb", restName="/rest/deploymentEnv_add/", datas=saveJson)
         resultJson = resultJson.json()
         if resultJson['status'] == 'SUCCESS':
             result['status'] = 'SUCCESS';
         else:
             result['status'] = 'FAILURE';
             result['msg'] = resultJson['msg'];
     else:
         result['status'] = 'FAILURE';
     return result
Ejemplo n.º 27
0
 def post(self, request, *args, **kwargs):
     result_json = {"status": 1}
     try:
         hostIp = request.POST.get("hostIp", None);
         reqParam = []
         hu = HttpUtils(request)
         for ip in hostIp.split(','):
             reqParam.append({'host_ip':ip})
         scanResult = hu.post(serivceName="cmdb", restName="/rest/host/scan/", datas=reqParam)
         result = scanResult.json()
         if len(result) > 0:
             result_json = {"status": 0}
     except Exception as e:
         logger.error(e)
     return self.render_json_response(result_json)
Ejemplo n.º 28
0
def MngSiteCreateOrUpdate(request):
    results = {}
    try:
        input_param = json.loads(str(request.body, 'utf-8'))
        if input_param:
            id = input_param['id']
            hu = HttpUtils(request)
            input_param = trans_siteInfo(input_param)
            if int(id) < 0:
                del input_param['id']
                post_results = hu.post(serivceName='p_job', restName='/rest/slb/addMngSite/', datas=input_param)
                post_results = post_results.json()
                if post_results['status'] == 200:
                    results['status'] = 200
                    results['msg'] = "新增成功"
                    results['id'] = post_results['id']
                else:
                    results['status'] = 500
                    results['msg'] = "新增失败"
            elif int(id) > 0:
                post_results = hu.post(serivceName='p_job', restName='/rest/slb/updateMngSite/',datas=input_param)
                post_results = post_results.json()
                if post_results['status'] == 200:
                    results['status'] = 200
                    results['msg'] = "修改成功"
                else:
                    results['status'] = 500
                    results['msg'] = "修改失败"
        else:
            results['status'] = 500
            results['msg'] = "参数为空"
    except Exception as e:
        logger.error(e, exc_info=1)
        results['status'] = 500
        results['msg'] = "新增或更新异常"
    return JsonResponse(data=results)
Ejemplo n.º 29
0
 def delPub(self,url,req):
     result = {}
     id = req.POST.get("id",None)
     if id:
         hu = HttpUtils(req)
         resultJson = hu.post(serivceName="cmdb", restName=url, datas={"id":id,"is_enabled":False})
         resultJson = resultJson.json()
         if resultJson['status'] == 'SUCCESS':
             result['status'] = 'SUCCESS';
         else:
             result['status'] = 'FAILURE';
             result['msg'] = resultJson['msg'];
     else:
         result['status'] = 'FAILURE';
     return result
Ejemplo n.º 30
0
 def post_ajax(self, request, *args, **kwargs):
     result = {'status': 0}
     try:
         command_set_str = request.POST.get("command_set", None)
         hu = HttpUtils(request)
         resultJson = hu.post(serivceName="p_job",
                              restName="/rest/commandset/add/",
                              datas=command_set_str)  #/rest/job/add/
         resultJson = eval(resultJson.text)
         if resultJson["status"] == 200:
             result['status'] = 0
         else:
             result['status'] = 1
     except Exception as e:
         logger.error(e)
     return HttpResponse(json.dumps(result),
                         content_type='application/json')