def __deploy_database(rid, data): r = Release.query.filter(Release.id == rid).one() try: client = Client(app.config["SSH_HOST"], app.config["SSH_USER"], app.config["SSH_PASSWORD"]) if u"任务完成" not in client.exec_script("/root/csfscript/dump_data/dump_data.py", data): return r.is_deployed = True log_path = "%s/data_deploy_log/myapp.%s" % (app.root_path, datetime.now().strftime("%Y-%m-%d")) Release.add_log(r.id, log_path) except Exception, e: log.exception(e)
def __deploy_database(rid, data): r = Release.query.filter(Release.id == rid).one() try: client = Client(app.config["SSH_HOST"], app.config["SSH_USER"], app.config["SSH_PASSWORD"]) if u"任务完成" not in client.exec_script( "/root/csfscript/dump_data/dump_data.py", data): return r.is_deployed = True log_path = "%s/data_deploy_log/myapp.%s" % ( app.root_path, datetime.now().strftime("%Y-%m-%d")) Release.add_log(r.id, log_path) except Exception, e: log.exception(e)
def put(self, rid): submit = {"id": rid, "is_draft": False} release = Release.edit(submit) submit["status"] = "" submit["type"] = "" service=release.service if service: submit["type"]=service.type Mail().to(release,submit) return self.succ()
def get(self, begin_time, end_time): result = {} release = pd.read_json(json.dumps(Release.between(begin_time, end_time))).set_index("release_time") for name, g in release.groupby("release_type"): result[name] = {} ids = g.resample("m", how="count").id for ix in ids.index: date = time.format(ix.to_datetime(), "%Y-%m-%d") result[name][date] = ids[ix] return self.succ(result)
def get(self, begin_time, end_time): result = {} release = pd.read_json( json.dumps(Release.between(begin_time, end_time))) \ .set_index("release_time") for name, g in release.groupby("release_type"): result[name] = {} ids = g.resample("m", how="count").id for ix in ids.index: date = time.format(ix.to_datetime(), "%Y-%m-%d") result[name][date] = ids[ix] return self.succ(result)
def get(self, begin_time, end_time): result = {} for release in Release.between( datetime.strptime(begin_time, "%Y-%m-%d"), datetime.strptime(end_time, "%Y-%m-%d")): svc_name = release["service"]["name"] svc_type = release["service"]["type"] if not result.__contains__(svc_name): result[svc_name] = {} if not result[svc_name].__contains__(svc_type): result[svc_name][svc_type] = 1 else: result[svc_name][svc_type] += 1 return self.succ(result)
def get(self, begin_time, end_time): result = {} opts, svc_names = set(), set() for release in Release.between( datetime.strptime(begin_time, "%Y-%m-%d"), datetime.strptime(end_time, "%Y-%m-%d") ): proj = release["project"] svc_name = release["service"]["name"] svc_type = release["service"]["type"] is_pass, options = self.check_approval(release["approvals"]) if is_pass and len(release["approvals"]) < 3: continue svc_names.add(svc_name) if not result.__contains__(proj): result[proj] = {RELEASE.FAIL: {}, RELEASE.PASS: {}, RELEASE.OPTIONS: {}} if not result[proj][RELEASE.PASS].__contains__(svc_name): result[proj][RELEASE.PASS][svc_name] = 0 result[proj][RELEASE.FAIL][svc_name] = 0 if is_pass: result[proj][RELEASE.PASS][svc_name] += 1 else: result[proj][RELEASE.FAIL][svc_name] += 1 for opt in options.split(","): if not opt: continue opts.add(opt) if not result[proj][RELEASE.OPTIONS].__contains__(opt): result[proj][RELEASE.OPTIONS][opt] = 0 result[proj][RELEASE.OPTIONS][opt] += 1 for proj in result.values(): for opt in opts: if not proj[RELEASE.OPTIONS].__contains__(opt): proj[RELEASE.OPTIONS][opt] = 0 for svc_name in svc_names: if not proj[RELEASE.PASS].__contains__(svc_name): proj[RELEASE.PASS][svc_name] = 0 proj[RELEASE.FAIL][svc_name] = 0 return self.succ(result)
def get(self, begin_time, end_time): result = {} opts, svc_names = set(), set() for release in Release.between( datetime.strptime(begin_time, "%Y-%m-%d"), datetime.strptime(end_time, "%Y-%m-%d")): proj = release["project"] svc_name = release["service"]["name"] svc_type = release["service"]["type"] is_pass, options = self.check_approval(release["approvals"]) if is_pass and len(release["approvals"]) < 3: continue svc_names.add(svc_name) if not result.__contains__(proj): result[proj] = {RELEASE.FAIL: {}, RELEASE.PASS: {}, RELEASE.OPTIONS: {}} if not result[proj][RELEASE.PASS].__contains__(svc_name): result[proj][RELEASE.PASS][svc_name] = 0 result[proj][RELEASE.FAIL][svc_name] = 0 if is_pass: result[proj][RELEASE.PASS][svc_name] += 1 else: result[proj][RELEASE.FAIL][svc_name] += 1 for opt in options.split(","): if not opt: continue opts.add(opt) if not result[proj][RELEASE.OPTIONS].__contains__(opt): result[proj][RELEASE.OPTIONS][opt] = 0 result[proj][RELEASE.OPTIONS][opt] += 1 for proj in result.values(): for opt in opts: if not proj[RELEASE.OPTIONS].__contains__(opt): proj[RELEASE.OPTIONS][opt] = 0 for svc_name in svc_names: if not proj[RELEASE.PASS].__contains__(svc_name): proj[RELEASE.PASS][svc_name] = 0 proj[RELEASE.FAIL][svc_name] = 0 return self.succ(result)
def get(self, page=0, pre_page=None): return self.succ(Release.self(page, pre_page))
# coding=utf-8 from bmp.apis.base import BaseApi from bmp.models.release import Release from bmp.tasks.release import deploy_database from bmp import app from datetime import datetime class Release_deployApi(BaseApi): route = ["/release/deploy/<int:rid>", "/release/deploy/<int:page>/<int:pre_page>"] def get(self, page, pre_page): return self.succ(Release.undeployed(page, pre_page)) def post(self, rid): result=deploy_database(rid) return self.succ(result) def put(self, rid): Release.deploy(rid) return self.succ() if __name__ == "__main__": for i in Release.undeployed(1,100)["items"]: print(i["service"]["name"])
def delete(self, rid): Release.delete(rid) return self.succ()
def post(self): submit = self.request() Release.add(submit) return self.succ()
def put(self, rid): Release.deploy(rid) return self.succ()
def delete(self,rid): Release.delete(rid) return self.succ()
def get(self, page=0, pre_page=None, rid=0): if rid: return self.succ(Release.get(rid)) return self.succ(Release.unfinished(page, pre_page))
def get(self, page, pre_page): return self.succ(Release.undeployed(page, pre_page))
# coding=utf-8 from bmp.apis.base import BaseApi from bmp.models.release import Release from bmp.tasks.release import deploy_database from bmp import app from datetime import datetime class Release_deployApi(BaseApi): route = [ "/release/deploy/<int:rid>", "/release/deploy/<int:page>/<int:pre_page>" ] def get(self, page, pre_page): return self.succ(Release.undeployed(page, pre_page)) def post(self, rid): result = deploy_database(rid) return self.succ(result) def put(self, rid): Release.deploy(rid) return self.succ() if __name__ == "__main__": for i in Release.undeployed(1, 100)["items"]: print(i["service"]["name"])
def put(self, rid): submit = self.request() submit["id"] = rid Release.edit(submit) return self.succ()
class ReleaseApi(BaseApi): route = ["/release", "/release/<int:rid>", "/release/<int:page>/<int:pre_page>"] def get(self, page=0, pre_page=None, rid=0): if rid: return self.succ(Release.get(rid)) return self.succ(Release.unfinished(page, pre_page)) def put(self, rid): submit = self.request() if ReleaseApproval.edit(rid, submit): Mail().to(Release.query.filter(Release.id == rid).one(), submit) return self.succ() return self.fail() def post(self): submit = self.request() Release.add(submit) return self.succ() def delete(self,rid): Release.delete(rid) return self.succ() if __name__ == "__main__": print(Release.unfinished(1,10))
class ReleaseApi(BaseApi): route = ["/release", "/release/<int:rid>", "/release/<int:page>/<int:pre_page>"] def get(self, page=0, pre_page=None, rid=0): if rid: return self.succ(Release.get(rid)) return self.succ(Release.unfinished(page, pre_page)) def put(self, rid): submit = self.request() if ReleaseApproval.edit(rid, submit): Mail().to(Release.query.filter(Release.id == rid).one(), submit) return self.succ() return self.fail() def post(self): submit = self.request() Release.add(submit) return self.succ() def delete(self, rid): Release.delete(rid) return self.succ() if __name__ == "__main__": print(Release.unfinished(1, 10))
def get(self,rid): return self.succ(Release.get_log(rid))