Beispiel #1
0
def ecs_init(tgt, func):
    data = {"client": "local", "tgt": tgt, "fun": "state.sls", "arg": func}
    token = get_token()
    salt_api_object = SaltAPI(data, SALT_REST_URL, token)
    res = salt_api_object.cmdrun()
    redisconn = RedisConn(REDIS_HOST, REDIS_PORT)
    key = "{}_{}".format(tgt, func)
    redisconn.set_key(key, json.dumps(res))
Beispiel #2
0
 def get(self, request, *args, **kwargs):
     target = kwargs.get("target")
     key = "{}_init_func".format(target)
     redisconn = RedisConn(REDIS_HOST, REDIS_PORT)
     func_list = redisconn.get_key(key)["func_list"]
     install_res = {}
     for func in func_list:
         res_key = "{}_{}".format(target, func)
         install_res[func] = redisconn.get_key(res_key)
     self.context = {"install_res": install_res, "target": target}
     return render(request, "cmdb/ecshost/ecshost_init_res.html",
                   self.context)
Beispiel #3
0
 def post(
     self,
     request,
 ):
     target = request.POST.get("tgt")
     func_list = request.POST.getlist("func_list")
     for func in func_list:
         ecs_init(target, func)
     func_dict = {func: "true" for func in func_list}
     redisconn = RedisConn(REDIS_HOST, REDIS_PORT)
     key = "{}_init_func".format(target)
     value = {"func_list": func_dict}
     redisconn.set_key(key, json.dumps(value))
     return JsonResponse({"message": "initial success"})
Beispiel #4
0
 def get(self, request, *args, **kwargs):
     id = kwargs.get("id")
     deploytask = DeployTask.objects.get(pk=id)
     module_name = deploytask.project.module_name
     tag_version = deploytask.tag_version
     zip_file = "{}-{}.zip".format(module_name, tag_version)
     redisconn = RedisConn(REDIS_HOST, REDIS_PORT)
     test_report_key = "{}_{}_test_report".format(module_name, tag_version)
     receiving_report_key = "{}_{}_receiving_report".format(
         module_name, tag_version)
     if deploytask.need_test == "yes" and deploytask.is_test_pass == "yes":
         test_report_json = redisconn.get_key_no_json(test_report_key)
         receiving_report_json = redisconn.get_key_no_json(
             receiving_report_key)
         test_report = json.loads(test_report_json.decode(
             "utf-8")) if test_report_json is not None else None
         receiving_report = json.loads(receiving_report_json.decode(
             "utf-8")) if receiving_report_json is not None else None
     else:
         test_report = None
         receiving_report = None
     if deploytask.is_sql_exec == "yes" and deploytask.need_test == "no":
         self.context = {"zip_file": zip_file, "deploytask": deploytask}
     elif deploytask.is_sql_exec == "yes" and deploytask.need_test == "yes" and deploytask.is_test_pass == "no":
         self.context = {
             "zip_file": zip_file,
             "deploytask": deploytask,
             "test_report": test_report,
             "receiving_report": receiving_report
         }
     elif deploytask.is_sql_exec == "yes" and deploytask.need_test == "yes" and deploytask.is_test_pass == "yes":
         self.context = {
             "zip_file": zip_file,
             "deploytask": deploytask,
             "test_report": test_report,
             "receiving_report": receiving_report
         }
     elif deploytask.is_sql_exec == "no" and deploytask.need_test == "yes" and deploytask.is_test_pass == "yes":
         self.context = {
             "deploytask": deploytask,
             "test_report": test_report,
             "receiving_report": receiving_report
         }
     elif deploytask.is_sql_exec == "no" and deploytask.need_test == "yes" and deploytask.is_test_pass == "no":
         self.context = {"deploytask": deploytask}
     else:
         self.context = {"deploytask": deploytask}
     return render(request, "deploy/deploytask_info.html", self.context)
Beispiel #5
0
 def get(self, request, *args, **kwargs):
     id = kwargs.get("id")
     ecshost = EcsHost.objects.get(pk=id)
     redisconn = RedisConn(REDIS_HOST, REDIS_PORT)
     func_dict = redisconn.get_key_no_json("{}_init_func".format(
         ecshost.minion_id))
     if func_dict is not None:
         func_list = [
             k for k, v in json.loads(func_dict)["func_list"].items()
             if v == "true"
         ]
         saltstate = SaltState.objects.exclude(fun_name__in=func_list)
     else:
         saltstate = SaltState.objects.all()
     self.context = {"func_list": saltstate, "minion_id": ecshost.minion_id}
     return render(request, "cmdb/ecshost/select_func.html", self.context)
Beispiel #6
0
 def get(self, request, *args, **kwargs):
     id = kwargs.get("id")
     deploytask = DeployTask.objects.get(pk=id)
     test_report_key = "{}_{}_test_report".format(
         deploytask.project.module_name, deploytask.tag_version)
     receiving_report_key = "{}_{}_receiving_report".format(
         deploytask.project.module_name, deploytask.tag_version)
     redisconn = RedisConn(REDIS_HOST, REDIS_PORT)
     if deploytask.is_sql_exec == "no" and deploytask.need_test == "no":
         deploytask.delete()
     elif deploytask.is_sql_exec == "no" and deploytask.need_test == "yes" and deploytask.is_test_pass == "no":
         deploytask.delete()
     elif deploytask.is_sql_exec == "no" and deploytask.need_test == "yes" and deploytask.is_test_pass == "yes":
         redisconn.del_key(test_report_key)
         redisconn.del_key(receiving_report_key)
         shutil.rmtree(
             os.path.join(
                 os.path.join(DEPLOY_UPLOAD_PATH,
                              deploytask.project.module_name),
                 deploytask.tag_version))
         deploytask.delete()
     elif deploytask.is_sql_exec == "yes" and deploytask.need_test == "no":
         shutil.rmtree(
             os.path.join(
                 os.path.join(DEPLOY_UPLOAD_PATH,
                              deploytask.project.module_name),
                 deploytask.tag_version))
         deploytask.delete()
     elif deploytask.is_sql_exec == "yes" and deploytask.need_test == "yes" and deploytask.is_test_pass == "no":
         shutil.rmtree(
             os.path.join(
                 os.path.join(DEPLOY_UPLOAD_PATH,
                              deploytask.project.module_name),
                 deploytask.tag_version))
         deploytask.delete()
     elif deploytask.is_sql_exec == "yes" and deploytask.need_test == "yes" and deploytask.is_test_pass == "yes":
         redisconn.del_key(test_report_key)
         redisconn.del_key(receiving_report_key)
         shutil.rmtree(
             os.path.join(
                 os.path.join(DEPLOY_UPLOAD_PATH,
                              deploytask.project.module_name),
                 deploytask.tag_version))
         deploytask.delete()
     else:
         deploytask.delete()
     return HttpResponsePermanentRedirect(reverse("deploy_task_list"))
Beispiel #7
0
 def get(self,request,*args,**kwargs):
     id = kwargs.get("id")
     upload_file = UploadFile.objects.get(pk=id)
     redis_conn = RedisConn(REDIS_HOST,REDIS_PORT)
     if upload_file.sql_billing_file is not None:
         key = "billing_{}".format(id)
         billing_run_res = redis_conn.get_key(key)["result"].split("\n")
     else:
         billing_run_res = None
     if upload_file.sql_pay_file is not None:
         key = "pay_{}".format(id)
         pay_run_res = redis_conn.get_key(key)["result"].split("\n")
     else:
         pay_run_res = None
     if upload_file.jar_file is not None:
         key = "jar_{}".format(id)
         jar_run_res = redis_conn.get_key(key)["result"].split("\n")
     else:
         jar_run_res = None
     self.context = {"upload_file":upload_file,"billing_run_res":billing_run_res,"pay_run_res":pay_run_res,"jar_run_res":jar_run_res}
     return render(request,"deploy/file_run_res.html",self.context)
Beispiel #8
0
 def get(self,request,*args,**kwargs):
     id = kwargs.get("id")
     upload_file = UploadFile.objects.get(pk=id)
     upload_file.delete()
     timestamp = str(int(time.mktime(upload_file.upload_time.timetuple())))
     redis_conn = RedisConn(REDIS_HOST,REDIS_PORT)
     if upload_file.sql_billing_file != None:
         billing_dir = os.path.join(os.path.join(DEPLOY_UPLOAD_PATH,"billing"),timestamp)
         shutil.rmtree(billing_dir)
         key = "billing_{}".format(upload_file.id)
         redis_conn.del_key(key)
     if upload_file.sql_pay_file != None:
         pay_dir = os.path.join(os.path.join(DEPLOY_UPLOAD_PATH,"pay"),timestamp)
         shutil.rmtree(pay_dir)
         key = "pay_{}".format(id)
         redis_conn.del_key(key)
     if upload_file.jar_file != None:
         jar_dir = os.path.join(os.path.join(DEPLOY_UPLOAD_PATH,"jar"),timestamp)
         shutil.rmtree(jar_dir)
         key = "jar_{}".format(id)
         redis_conn.del_key(key)
     return HttpResponseRedirect(reverse("execute_file_list"))
Beispiel #9
0
 def post(self,request,*args,**kwargs):
     id = request.POST["id"]
     upload_file = UploadFile.objects.get(pk=id)
     sql_billing_file = upload_file.sql_billing_file
     sql_pay_file = upload_file.sql_pay_file
     jar_file = upload_file.jar_file
     timestamp = time.mktime(upload_file.upload_time.timetuple())
     if sql_billing_file is not None:
         file_name_billing = os.path.join(os.path.join(os.path.join(DEPLOY_UPLOAD_PATH,"billing"),str(int(timestamp))),sql_billing_file)
         unzip_file(file_name_billing,"/opt/billing/runfiles")
         billing_run_res = str(script_execute("/opt/runsql/billing_run.sh"),encoding="utf-8")
         redis_conn = RedisConn(REDIS_HOST,REDIS_PORT)
         key = "billing_{}".format(upload_file.id)
         val = {"id":str(upload_file.id),"timestamp":str(timestamp),"result":billing_run_res}
         redis_conn.set_key(key,json.dumps(val))
     if sql_pay_file is not None:
         file_name_pay = os.path.join(os.path.join(os.path.join(DEPLOY_UPLOAD_PATH,"pay"),str(int(timestamp))),sql_pay_file)
         unzip_file(file_name_pay,"/opt/pay/runfiles")
         pay_run_res = str(script_execute("/opt/runsql/pay_run.sh"),encoding="utf-8")
         redis_conn = RedisConn(REDIS_HOST,REDIS_PORT)
         key = "pay_{}".format(upload_file.id)
         val = {"id":str(upload_file.id),"timestamp":str(timestamp),"result":pay_run_res}
         redis_conn.set_key(key,json.dumps(val))
     if jar_file is not None:
         file_name_jar = os.path.join(os.path.join(os.path.join(DEPLOY_UPLOAD_PATH,"jar"),str(int(timestamp))),jar_file)
         shutil.copy(file_name_jar,"/opt/transfile/jar/")
         jar_run_res = str(script_execute("/opt/transfile/pscpfile.sh"),encoding="utf-8")
         redis_conn = RedisConn(REDIS_HOST,REDIS_PORT)
         key = "jar_{}".format(upload_file.id)
         val = {"id":str(upload_file.id),"timestamp":str(timestamp),"result":jar_run_res}
         redis_conn.set_key(key,json.dumps(val))
     self.context = {"id":id,"message":"execute success"}
     return JsonResponse(self.context)
Beispiel #10
0
def uidNumbers():
    redisconn = RedisConn(REDIS_HOST, REDIS_PORT)
    key = "uidNumber"
    uidNumber = redisconn.get_key(key)
    redisconn.set_key(key, int(uidNumber) + 1)
    return uidNumber
Beispiel #11
0
 def post(self, request, *args, **kwargs):
     module_name = kwargs.get("module_name")
     tag_version = kwargs.get("tag_version")
     test_report_form = TestReportUploadForm(request.POST, request.FILES)
     if test_report_form.is_valid():
         test_report = request.FILES.getlist("test_report")
         receiving_report = request.FILES.getlist("receiving_report")
         redisconn = RedisConn(REDIS_HOST, REDIS_PORT)
         test_report_dir = os.path.join(
             os.path.join(os.path.join(DEPLOY_UPLOAD_PATH, module_name),
                          tag_version), "test_report")
         receiving_report_dir = os.path.join(
             os.path.join(os.path.join(DEPLOY_UPLOAD_PATH, module_name),
                          tag_version), "receiving_report")
         if not os.path.exists(test_report_dir):
             os.makedirs(test_report_dir)
         if not os.path.exists(receiving_report_dir):
             os.makedirs(receiving_report_dir)
         test_report_filename_list = []
         test_report_filename_dict = {}
         receiving_report_filename_list = []
         receiving_report_filename_dict = {}
         test_report_key = "{0}_{1}_test_report".format(
             module_name, tag_version)
         receiving_report_key = "{0}_{1}_receiving_report".format(
             module_name, tag_version)
         for tr in test_report:
             test_report_filename = os.path.join(test_report_dir, tr.name)
             test_report_filename_list.append(tr.name)
             handle_uploaded_file(test_report_filename, tr)
         test_report_filename_dict[
             "test_report_file_list"] = test_report_filename_list
         redisconn.set_key(test_report_key,
                           json.dumps(test_report_filename_dict))
         if len(receiving_report) > 0:
             for rr in receiving_report:
                 receiving_report_filename = os.path.join(
                     receiving_report_dir, rr.name)
                 receiving_report_filename_list.append(rr.name)
                 handle_uploaded_file(receiving_report_filename, rr)
             receiving_report_filename_dict[
                 "receiving_report_file_list"] = receiving_report_filename_list
             redisconn.set_key(receiving_report_key,
                               json.dumps(receiving_report_filename_dict))
         deploytask = DeployTask.objects.filter(
             project__module_name=module_name).filter(
                 tag_version=tag_version)[0]
         deploytask.is_test_pass = "******"
         deploytask.save()
         subject = "测试通过,可以升级"
         message = "{0}-{1}-可以升级".format(module_name, tag_version)
         addr = ["{}@zhexinit.com".format(deploytask.handle_person)]
         emailthread = EmailThread(subject, message, addr)
         emailthread.start()
         return HttpResponseRedirect(reverse("deploy_task_list"))
     else:
         self.context = {
             "test_report_form": test_report_form,
             "errors": test_report_form.errors
         }
         return render(request, "deploy/test_report_upload.html",
                       self.context)