def get(self, **kwargs): data = self.get_pro_info_res(kwargs["pro_id"]) applies = data["pro_info_res"].data.pro_resource_applies svc = ProjectService(self) pro_list_res = svc.get_project_list() logger.info(pro_list_res) # svc = ProUserService(self, {"pro_id": kwargs["pro_id"]}) # pro_users_res = svc.get_list() # pro_user_res = svc.get_info() # svc = ApplyPublish(self, {"pro_id": kwargs["pro_id"]}) # pro_publish_res = svc.get_publish() # svc = ApplyLoadBalance(self, {"pro_id": kwargs["pro_id"]}) # pro_loadbalance_res = svc.get_loadbalance() # svc = ApplyBackups(self, {"pro_id": kwargs["pro_id"]}) # backups_res = svc.get_backups() data.update( pro_list_res=pro_list_res, pro_id=kwargs["pro_id"] # pro_users_res=pro_users_res, # pro_user_res=pro_user_res, # pro_publish_res=pro_publish_res, # pro_loadbalance_res=pro_loadbalance_res, # backups_res=backups_res, ) if len(applies) > 0: last_apply = applies[-1] if not last_apply.start_date: self.add_message(u"尚未设置云资源启用时间!", level="warning") return self.render_to_string("admin/guide/step3.html", **data) else: return self.render_to_string("admin/guide/step1.html", **data)
def get(self): svc = ProjectService(self) pro_list_res = svc.get_project_list() if pro_list_res.return_code < 0: raise SystemError(pro_list_res.return_code, pro_list_res.return_message) logger.info(pro_list_res) data = dict(pro_list_res=pro_list_res) return self.render_to_string("admin/event/add.html", **data)
def get(self): env_svc = EnvService(self) env_list_res = env_svc.get_list() svc = ProjectService(self) result = svc.get_project_list() if result.return_code < 0: raise SystemError(result.return_code, result.return_message) logger.info(result) return self.render_to_string("admin/guide/index.html", result=result, pro_resource_apply_status_types=pro_resource_apply_status_types, env_list_res=env_list_res)
def get_pro_info_res(self, pro_id): kw = {"pro_id": pro_id} svc = ProjectService(self, kw) pro_info_res = svc.get_project() if isinstance(pro_info_res, Exception): raise pro_info_res data = { "pro_info_res": pro_info_res, # "STATUS_RESOURCE": STATUS_RESOURCE, } return data
def get(self): svc = ProjectService(self) pro_list_res = svc.get_project_list() logger.info(pro_list_res) svc = ProResourceApplyService(self) pro_resource_applies_res = svc.get_list() pro_resource_apply_list = pro_resource_applies_res.data logger.info(pro_resource_apply_list) data = dict(pro_list_res=pro_list_res, page=self.getPage(pro_resource_apply_list)) return self.render_to_string("admin/apply/resource/index.html", **data)
def get_pro_info_res(self, pro_id): kw = {"pro_id": pro_id} svc = ProjectService(self, kw) pro_info_res = svc.get_project() if isinstance(pro_info_res, Exception): raise pro_info_res data = { "pro_info_res": pro_info_res, "STATUS_RESOURCE": STATUS_RESOURCE, } return data
def get(self): svc = ProjectService(self) pro_list_res = svc.get_project_list() logger.info(pro_list_res) svc = ProResourceApplyService(self) pro_resource_applies_res = svc.get_list() pro_resource_apply_list = pro_resource_applies_res.data logger.info(pro_resource_apply_list) data = dict( pro_list_res = pro_list_res, page = self.getPage(pro_resource_apply_list) ) return self.render_to_string("admin/apply/resource/index.html", **data)
def get_pro_info_res(self, pro_id): kw = {"pro_id": pro_id} svc = ProjectService(self, kw) pro_info_res = svc.get_project() pro_list_res = svc.get_project_list() if isinstance(pro_info_res, Exception): raise pro_info_res data = { "pro_info_res": pro_info_res, "pro_list_res": pro_list_res, "STATUS_RESOURCE": STATUS_RESOURCE, "Pro_Resource_Apply": Pro_Resource_Apply } return data
def get_pro_data(self, **kw): # kw = {"pro_id": pro_id} svc = ProjectService(self, kw) if "pro_id" in kw: pro_info_res = svc.get_project() if isinstance(pro_info_res, Exception): raise pro_info_res pro_list_res = svc.get_project_list() data = { "pro_list_res": pro_list_res, "Pro_Resource_Apply": Pro_Resource_Apply } if "pro_id" in kw: data.update({"pro_info_res": pro_info_res}) return data
def get(self): if self.kwargs["name"] == "apply.resource.add": data = self.get_pro_data() return self.render_to_string("admin/apply/resource/add.html", **data) else: data = self.get_pro_data() svc = ProResourceApplyService(self) pro_resource_apply_res = svc.get_resource() if self.kwargs["name"] == "apply.resource.pay": data.update( dict(pro_resource_apply_res=pro_resource_apply_res)) return self.render_to_string("admin/apply/resource/pay.html", **data) svc = ProjectService(self) env_resource_value_res = svc.load_env_resource_values() env_internet_ip_types_res = svc.load_env_internet_ip_types() data.update( dict( pro_resource_apply_res=pro_resource_apply_res, env_internet_ip_types_res=env_internet_ip_types_res, env_resource_value_res=env_resource_value_res, )) return self.render_to_string("admin/apply/resource/edit.html", **data)
def post(self, **kwargs): svc = ProResourceApplyService(self, kwargs) delete_res = svc.do_delete() pro_resource_applies_res = svc.get_list() svc = ProjectService(self) pro_list_res = svc.get_project_list() # svc = ProResourceApplyService(self) if pro_list_res.return_code < 0: raise SystemError(pro_list_res.return_code, pro_list_res.return_message) logger.info(pro_list_res) data = dict(pro_list_res=pro_list_res, page=self.getPage(pro_resource_applies_res.data)) if isinstance(delete_res, Exception): raise delete_res # data = self.get_pro_info_res(kwargs["pro_id"]) if delete_res.return_code == 0: self.add_message( "云资源[%s-%s]记录删除成功!" % (delete_res.data.project.name, delete_res.data.desc), level="success") publish_notice_checker.delay(self.current_user.id) else: self.add_message( "云资源记录删除失败!(%s)%s" % (delete_res.return_code, delete_res.return_message), level="warning") # logger.info("\t [data]: %s" % data ) # logger.info("\t [data pro_info_res]: %s" % data["pro_info_res"]) tmpl = self.render_to_string("admin/apply/resource/index_pjax.html", **data) return simplejson.dumps(self.success(data=tmpl))
def post(self): id_list = self.get_arguments("id") svc = EventService(self, {"id_list": id_list}) del_res = svc.do_del_pro_event() logger.info(del_res) if del_res.return_code == 0: self.add_message(u"事件信息删除成功!", level="success") publish_notice_checker.delay(self.current_user.id) else: self.add_message(u"事件信息删除失败!(%s)(%s)" % (del_res.return_code, del_res.return_message), level="warning") svc = EventService(self, {"user_id": self.current_user.id}) pro_events_res = svc.get_list() svc = ProjectService(self) pro_list_res = svc.get_project_list() if pro_list_res.return_code < 0: raise SystemError(pro_list_res.return_code, pro_list_res.return_message) logger.info(pro_list_res) data = { "pro_list_res": pro_list_res, "pro_events_res": pro_events_res, "page": self.getPage(pro_events_res.data) } tmpl = self.render_to_string("admin/event/index_pjax.html", **data) return simplejson.dumps(self.success(data=tmpl))
def post(self): kw = {"user_id": self.current_user.id} svc = ProResourceApplyService(self, kw) # pro_svc = ProjectService(self, kw) # pro_info_res = pro_svc.get_project() if self.kwargs["name"] == "apply.resource.add": post_action = u"提交" pro_resource_apply_res = svc.do_apply() elif self.kwargs["name"] == "apply.resource.edit": post_action = u"重新提交" pro_resource_apply_res = svc.do_re_apply() elif self.kwargs["name"] == "apply.resource.revoke": post_action = u"撤销" pro_resource_apply_res = svc.do_revoke() elif self.kwargs["name"] == "apply.resource.pay": post_action = u"支付" pro_resource_apply_res = svc.do_pay() pro_info_data = self.get_pro_data(pro_id=self.args.get("pro_id")) data = {"pro_resource_apply_res": pro_resource_apply_res} svc = ProjectService(self) env_resource_value_res = svc.load_env_resource_values() env_internet_ip_types_res = svc.load_env_internet_ip_types() data.update( dict( env_internet_ip_types_res=env_internet_ip_types_res, env_resource_value_res=env_resource_value_res, )) data.update(pro_info_data) if pro_resource_apply_res.return_code == 0: self.add_message(u"申请项目[%s-%s]%s资源成功!" % (pro_resource_apply_res.data.project.name, pro_resource_apply_res.data.desc, post_action), level="success", post_action=True) publish_notice_checker.delay(self.current_user.id) if self.kwargs["name"] == "apply.resource.pay": tmpl = self.render_to_string( "admin/guide/_step_2_pay_detail.html", **data) else: tmpl = self.render_to_string( "admin/guide/_step_1_res_detail.html", **data) else: self.add_message(u"申请项目%s资源失败!(%s)%s" % (post_action, pro_resource_apply_res.return_code, pro_resource_apply_res.return_message), level="warning") if self.kwargs["name"] == "apply.resource.pay": tmpl = self.render_to_string("admin/guide/_step_2_pay.html", **data) else: tmpl = self.render_to_string( "admin/guide/_step_1_res_add.html", **data) messages_tmpl = self.render_to_string("admin/base/base_messages.html") return simplejson.dumps( self.success(data={ "tmpl": tmpl, "messages_tmpl": messages_tmpl }))
def post(self): env_svc = EnvService(self) env_list_res = env_svc.get_list() svc = ProjectService(self) result = svc.create_project() logger.info(result) if result.return_code == 0: logger.info("return_code:%s" % result.return_code) self.add_message(u"项目[%s]添加成功" % result.data.name, level="success", post_action=True) data = self.get_pro_info_res(result.data.id) return self.render_to_string("admin/guide/step1.html", **data) else: logger.info("return_code:%s" % result.return_code) post_result = result proj_result = svc.get_project_list() self.add_message(post_result.return_message, level='warning') return self.render_to_string("admin/guide/index.html", result=proj_result, post_result=post_result, env_list_res=env_list_res)
def post(self, **kwargs): kw = {"user_id": self.current_user.id} kw.update(self.args) kw.update(kwargs) svc = ProResourceApplyService(self, kw) revoke_res = svc.do_revoke() kw.update({"pro_id": revoke_res.data.pro_id if revoke_res.return_code == 0 else 0}) pro_svc = ProjectService(self, kw) pro_info_res = pro_svc.get_project() data = { "pro_info_res": pro_info_res, "post_apply_res": revoke_res, "STATUS_RESOURCE": STATUS_RESOURCE } if revoke_res.return_code == 0: self.add_message(u"资源[%s-%s]申请撤销成功!" % (revoke_res.data.project.name, revoke_res.data.desc), level="success", post_action=True) tmpl = self.render_to_string("admin/guide/step2_pjax.html", **data) return simplejson.dumps(self.success(data=tmpl)) else: self.add_message(u"资源申请撤销失败!(%s)%s" % (post_apply_res.return_code, post_apply_res.return_message), level="warning") tmpl = self.render_to_string("admin/guide/step1_pjax.html", **data) return simplejson.dumps(self.success(data=tmpl))
def xget(self): svc = ProjectService(self) project_list_res = svc.filter_list() if project_list_res.return_code == 0: project_list = project_list_res.data.projects projects_by_env = project_list_res.data.projects_by_env projects_by_status = project_list_res.data.projects_by_status else: project_list = [] page = self.getPage(project_list) data = dict( page = page, projects_by_env = projects_by_env, projects_by_status = projects_by_status ) tmpl_project_list = self.render_to_string("admin/project/_project_list.html", **data) tmpl_project_charts = self.render_to_string("admin/project/_project_charts.html", **data) # tmpl_project_charts = self.render_to_string("admin/project/_project_chartjs_charts.html", **data) return simplejson.dumps(self.success(data=dict( tmpl_project_list=tmpl_project_list, tmpl_project_charts=tmpl_project_charts, )))
def get(self, **kwargs): data = self.get_pro_data() svc = ProjectService(self) env_resource_value_res = svc.load_env_resource_values() env_internet_ip_types_res = svc.load_env_internet_ip_types() svc = ProResourceApplyService(self, self.args) pro_resource_apply_res = svc.get_resource() pro_resource_apply = pro_resource_apply_res.data if pro_resource_apply_res.return_code == 0 else None internet_ip_options = env_internet_ip_types_res.data if env_internet_ip_types_res.return_code == 0 else [] internet_ip_value = 0 if pro_resource_apply: internet_ip_value = pro_resource_apply.internet_ip else: if env_resource_value_res.return_code == 0: internet_ip_value = env_resource_value_res.data["internet_ip"] try: # internet_bandwidths = [] # for i in internet_ip_options: # logger.info("internet_ip: %s, value: %s" % (i["value"], internet_ip_value)) internet_bandwidths = {internet_ip_value: i["bandwidths"] for i in internet_ip_options if int(i["value"]) == int(internet_ip_value)}[internet_ip_value] # logger.info(internet_bandwidths) except: logThrown() internet_bandwidths = [] data.update(dict( env_internet_ip_types_res = env_internet_ip_types_res, env_resource_value_res = env_resource_value_res, pro_resource_apply = pro_resource_apply, internet_bandwidths = internet_bandwidths )) env_internet_ip_types_tmpl = self.render_to_string("admin/apply/resource/_env_internet_ip_types.html", **data) env_internet_bandwidth_tmpl = self.render_to_string("admin/apply/resource/_env_internet_bandwidth.html", **data) return simplejson.dumps(self.success(data=dict( env_resource_value = env_resource_value_res.data, env_internet_ip_types_tmpl = env_internet_ip_types_tmpl, env_internet_bandwidth_tmpl = env_internet_bandwidth_tmpl )))
def get(self): svc = EventService(self, {"user_id": self.current_user.id}) pro_events_res = svc.get_list() svc = ProjectService(self) pro_list_res = svc.get_project_list() if pro_list_res.return_code < 0: raise SystemError(pro_list_res.return_code, pro_list_res.return_message) logger.info(pro_list_res) data = { "pro_list_res": pro_list_res, "pro_events_res": pro_events_res, "page": self.getPage(pro_events_res.data) } return self.render_to_string("admin/event/index.html", **data)
def post(self, **kwargs): data = self.get_pro_data() svc = ProResourceApplyService(self, self.args) pro_resource_apply_res = svc.get_resource() logger.info("[pro_resource_apply_res] %s" % pro_resource_apply_res) fee_res = svc.generate_fee() svc = ProjectService(self) env_resource_value_res = svc.load_env_resource_values() env_internet_ip_types_res = svc.load_env_internet_ip_types() data.update( dict( fee_res=fee_res, pro_resource_apply_res=pro_resource_apply_res, env_internet_ip_types_res=env_internet_ip_types_res, env_resource_value_res=env_resource_value_res, )) logger.info(fee_res) if fee_res.return_code == 0: self.add_message( u"费用计算成功!单月费用 %s(元/月)×有效期 %s(月)=总费用 %s(元)" % (fee_res.data["unit_fee"], self.args.get('period'), fee_res.data["total_fee"]), level="success") else: if fee_res.return_code == ERROR.database_save_err.errcode: return_messages = fee_res.return_messages self.add_message(u"费用计算失败!", level="warning") for msg in return_messages: self.add_message(u"%s" % msg, level="warning") else: self.add_message(u"费用计算失败! %s(%s)" % (fee_res.return_code, fee_res.return_message), level="warning") messages_tmpl = self.render_to_string("admin/base/base_messages.html") tmpl = self.render_to_string("admin/guide/_step_1_res_fee_form.html", **data) # tmpl = self.render_to_string("admin/apply/resource/add_pjax.html", **data) return simplejson.dumps( self.success(data={ "tmpl": tmpl, "messages_tmpl": messages_tmpl }))
def get(self, **kwargs): data = self.get_pro_info_res(kwargs["pro_id"]) pro_info_res = data["pro_info_res"] if pro_info_res.return_code == 0: pro_info = pro_info_res["data"] res_apply_id = pro_info.last_apply.id if pro_info.last_apply else 0 else: res_apply_id = 0 kwargs["res_apply_id"] = res_apply_id svc = ProResourceApplyService(self, kwargs) pro_resource_apply_res = svc.get_resource() logger.info("[pro_resource_apply_res] %s" % pro_resource_apply_res) svc = ProjectService(self) env_resource_value_res = svc.load_env_resource_values() env_internet_ip_types_res = svc.load_env_internet_ip_types() data.update(dict( pro_resource_apply_res = pro_resource_apply_res, env_internet_ip_types_res = env_internet_ip_types_res, env_resource_value_res = env_resource_value_res, )) return self.render_to_string("admin/guide/step1.html", **data)
def post(self): svc = EventService(self) do_event_res = svc.do_event() if do_event_res.return_code < 0: self.add_message( u"事件提交失败 %s(%s)" % (do_event_res.return_code, do_event_res.return_message), level="warning") template = "admin/event/add_pjax.html" else: self.add_message(u"事件提交成功", level="success") template = "admin/event/detail_pjax.html" svc = ProjectService(self) pro_list_res = svc.get_project_list() if pro_list_res.return_code < 0: raise SystemError(pro_list_res.return_code, pro_list_res.return_message) logger.info(pro_list_res) data = dict(pro_list_res=pro_list_res, pro_event_res=do_event_res) tmpl = self.render_to_string(template, **data) return simplejson.dumps(self.success(data=tmpl))
def reply(self, template=""): svc = EventService(self) pro_event_res = svc.do_reply() logger.info(pro_event_res) # if pro_event_detail_res.return_code < 0: # self.add_message(u"回复事件失败!(%s)%s" % (pro_event_detail_res.return_code, pro_event_detail_res.return_message), level="warning") # else: # self.add_message(u"回复事件成功!", level="success") pro_event_res = svc.get_info() svc = ProjectService(self) pro_list_res = svc.get_project_list() logger.info(pro_event_res) data = { "pro_event_res": pro_event_res, "pro_list_res": pro_list_res, } if self.current_user.imchecker: publish_notice_user.delay(pro_event_res.data.user.id) else: publish_notice_checker.delay(self.current_user.id) tmpl = self.render_to_string(template, **data) return simplejson.dumps(self.success(data=tmpl))
def get(self, **kwargs): data = self.get_pro_data() svc = ProjectService(self) env_resource_value_res = svc.load_env_resource_values() env_internet_ip_types_res = svc.load_env_internet_ip_types() svc = ProResourceApplyService(self, self.args) pro_resource_apply_res = svc.get_resource() pro_resource_apply = pro_resource_apply_res.data if pro_resource_apply_res.return_code == 0 else None internet_ip_options = env_internet_ip_types_res.data if env_internet_ip_types_res.return_code == 0 else [] internet_ip_value = 0 if pro_resource_apply: internet_ip_value = pro_resource_apply.internet_ip else: if env_resource_value_res.return_code == 0: internet_ip_value = env_resource_value_res.data["internet_ip"] try: # internet_bandwidths = [] # for i in internet_ip_options: # logger.info("internet_ip: %s, value: %s" % (i["value"], internet_ip_value)) internet_bandwidths = { internet_ip_value: i["bandwidths"] for i in internet_ip_options if int(i["value"]) == int(internet_ip_value) }[internet_ip_value] # logger.info(internet_bandwidths) except: logThrown() internet_bandwidths = [] data.update( dict(env_internet_ip_types_res=env_internet_ip_types_res, env_resource_value_res=env_resource_value_res, pro_resource_apply=pro_resource_apply, internet_bandwidths=internet_bandwidths)) env_internet_ip_types_tmpl = self.render_to_string( "admin/apply/resource/_env_internet_ip_types.html", **data) env_internet_bandwidth_tmpl = self.render_to_string( "admin/apply/resource/_env_internet_bandwidth.html", **data) return simplejson.dumps( self.success(data=dict( env_resource_value=env_resource_value_res.data, env_internet_ip_types_tmpl=env_internet_ip_types_tmpl, env_internet_bandwidth_tmpl=env_internet_bandwidth_tmpl)))
# -*- coding: utf-8 -*- import uuid from os.path import abspath, dirname, join current_path = abspath(dirname(__file__)) import sys sys.path.insert(0, join(current_path, '..', "scloud")) # sys.path.insert(0, join(current_path, '..')) from scloud.config import logger # from scloud.async_services.listener import init_listener from scloud.models.base import DataBaseService from scloud.models.project import Pro_Info from scloud.services.svc_project import ProjectService #init_listener() if __name__ == '__main__': logger.info("-----[0 post_act_history]------") # try: dbsvc = DataBaseService({}) dbsvc._db_init() svc = ProjectService(dbsvc, {"env": 2, "status": ""}) svc.filter_list()
def xget(self): task_svc = TaskPublish(self) tasks_res = task_svc.publish_tasks(user_id=self.current_user.id, pro_id=self.args.get("pro_id"), do_publish=False) if tasks_res.return_code == 0: # tasks = tasks_res.data pro_backup_list = tasks_res.data["pro_backup_list"] pro_balance_list = tasks_res.data["pro_balance_list"] pro_event_list = tasks_res.data["pro_event_list"] pro_publish_list = tasks_res.data["pro_publish_list"] pro_user_list = tasks_res.data["pro_user_list"] task_list = tasks_res.data["task_list"] todo_list = pro_backup_list\ + pro_balance_list\ + pro_event_list\ + pro_publish_list\ + pro_user_list\ + task_list todo_list.sort(key=lambda x: x.update_time) todo_list.reverse() else: todo_list = [] page = self.getPage(todo_list, page_name='todo_page') tmpl_todo_list = self.render_to_string( "admin/apply/project/_pro_todo_list.html", page=page) svc = ProjectService(self) project_res = svc.get_project() tmpl_pro_info_detail = self.render_to_string( "admin/apply/project/_pro_info_detail.html", project_res=project_res) tmpl_pro_table_detail = self.render_to_string( "admin/apply/project/_pro_table_detail.html", project_res=project_res) if project_res.return_code == 0: pro_info = project_res.data last_apply = pro_info.last_apply if last_apply: pro_resource_apply_res = ObjectDict() pro_resource_apply_res.return_code = 0 pro_resource_apply_res.return_message = u"" pro_resource_apply_res.data = last_apply tmpl_pro_resource_apply_detail = self.render_to_string( "admin/apply/project/_pro_resource_apply_detail.html", pro_resource_apply_res=pro_resource_apply_res) else: pro_resource_apply_res = ObjectDict() pro_resource_apply_res.return_code = STATUS_RESOURCE.UNKNOWN pro_resource_apply_res.return_message = STATUS_RESOURCE.unknown.value tmpl_pro_resource_apply_detail = self.render_to_string( "admin/apply/project/_pro_resource_apply_detail.html", pro_resource_apply_res=pro_resource_apply_res) else: tmpl_pro_resource_apply_detail = self.render_to_string( "admin/apply/project/_pro_resource_apply_detail.html", pro_resource_apply_res=project_res) evt_svc = EventService(self) pro_events_res = evt_svc.get_list() logger.info(pro_events_res) tmpl_pro_events = self.render_to_string( "admin/apply/project/_pro_events.html", pro_events_res=pro_events_res, project_res=project_res) data = dict( tmpl_pro_table_detail=tmpl_pro_table_detail, tmpl_pro_info_detail=tmpl_pro_info_detail, tmpl_todo_list=tmpl_todo_list, tmpl_pro_resource_apply_detail=tmpl_pro_resource_apply_detail, tmpl_pro_events=tmpl_pro_events, ) return simplejson.dumps(self.success(data=data))