return redirect('/service_modelview/list/') @expose('/link/<service_id>') def link(self, service_id): service = db.session.query(Service).filter_by(id=service_id).first() url = "http://" + service.name + "." + conf.get('SERVICE_DOMAIN') if service.host: if 'http://' in service.host or 'https://' in service.host: url = service.host else: url = "http://"+service.host data={ "url":url # 'http://127.0.0.1:8080/video_sample/' # } # 返回模板 return self.render_template('link.html', data=data) class Service_ModelView(Service_ModelView_base,MyappModelView,DeleteMixin): datamodel = SQLAInterface(Service) appbuilder.add_view(Service_ModelView,"内部服务",icon = 'fa-internet-explorer',category = '服务化') class Service_ModelView_Api(Service_ModelView_base,MyappModelRestApi): datamodel = SQLAInterface(Service) route_base = '/service_modelview/api' appbuilder.add_api(Service_ModelView_Api)
# @pysnooper.snoop() def post_list(self, items): return core.sort_expand_index(items, db.session) class Project_ModelView_job_template(Project_ModelView_Base, MyappModelView): project_type = 'job-template' base_filters = [["id", Project_Filter, project_type]] # 设置权限过滤器 datamodel = SQLAInterface(Project) label_title = '模板分类' appbuilder.add_view(Project_ModelView_job_template, "模板分类", icon='fa-tasks', category='项目组', category_icon='fa-users') # 添加api class Project_ModelView_job_template_Api(Project_ModelView_Base, MyappModelRestApi): route_base = '/project_modelview/job_template/api' datamodel = SQLAInterface(Project) project_type = 'job-template' base_filters = [["id", Project_Filter, project_type]] # 设置权限过滤器 appbuilder.add_api(Project_ModelView_job_template_Api)
db.session.commit() except InvalidRequestError: db.session.rollback() except Exception as e: raise e return redirect(request.referrer) class Job_Template_ModelView(Job_Template_ModelView_Base, MyappModelView, DeleteMixin): datamodel = SQLAInterface(Job_Template) appbuilder.add_view(Job_Template_ModelView, "任务模板", href="/job_template_modelview/list/?_flt_2_name=", icon='fa-flag-o', category='训练', category_icon='fa-envelope') # 添加api class Job_Template_ModelView_Api(Job_Template_ModelView_Base, MyappModelRestApi): datamodel = SQLAInterface(Job_Template) route_base = '/job_template_modelview/api' add_columns = [ 'project', 'images', 'name', 'version', 'describe', 'args', 'env', 'hostAliases', 'privileged', 'accounts', 'demo', 'expand' ] edit_columns = add_columns list_columns = [
def post_add(self, item): self.apply_hubsecret(item) def post_update(self, item): self.apply_hubsecret(item) class Repository_ModelView(Repository_ModelView_Base, MyappModelView, DeleteMixin): datamodel = SQLAInterface(Repository) # 添加视图和菜单 appbuilder.add_view(Repository_ModelView, "仓库", icon='fa-shopping-basket', category='训练', category_icon='fa-sitemap') # 添加api class Repository_ModelView_Api(Repository_ModelView_Base, MyappModelRestApi): datamodel = SQLAInterface(Repository) route_base = '/repository_modelview/api' appbuilder.add_api(Repository_ModelView_Api) # 只能查看到自己归属的项目组的镜像
k8s_client = py_k8s.K8s( item.project.cluster.get('KUBECONFIG', '')) crd_info = conf.get("CRD_INFO", {}).get(self.crd_name, {}) if crd_info: k8s_client.delete_crd( group=crd_info['group'], version=crd_info['version'], plural=crd_info['plural'], namespace=conf.get('KFSERVING_NAMESPACE'), name=item.name) except Exception as e: flash(str(e), "danger") def pre_delete(self, item): self.base_muldelete([item]) # @event_logger.log_this # @expose("/delete/<pk>") # @has_access # def delete(self, pk): # pk = self._deserialize_pk_if_composite(pk) # self.base_delete(pk) # url = url_for(f"{self.endpoint}.list") # return redirect(url) appbuilder.add_view(KfService_ModelView, "kfserving", icon='fa-tasks', category='服务化')
db.session.add(new_nni) db.session.commit() return redirect(request.referrer) class NNI_ModelView(NNI_ModelView_Base, MyappModelView): datamodel = SQLAInterface(NNI) conv = GeneralModelConverter(datamodel) appbuilder.add_separator("训练") # 在指定菜单栏下面的每个子菜单中间添加一个分割线的显示。 # 添加视图和菜单 # appbuilder.add_view(NNI_ModelView,"nni超参搜索",icon = 'fa-shopping-basket',category = '超参搜索',category_icon = 'fa-share-alt') appbuilder.add_view(NNI_ModelView, "nni超参搜索", icon='fa-shopping-basket', category='训练') # 添加api class NNI_ModelView_Api(NNI_ModelView_Base, MyappModelRestApi): datamodel = SQLAInterface(NNI) conv = GeneralModelConverter(datamodel) route_base = '/nni_modelview/api' list_columns = [ 'created_by', 'changed_by', 'created_on', 'changed_on', 'job_type', 'name', 'namespace', 'describe', 'parallel_trial_count', 'max_trial_count', 'objective_type', 'objective_goal', 'objective_metric_name', 'objective_additional_metric_names', 'algorithm_name', 'algorithm_setting', 'parameters', 'job_json', 'trial_spec', 'working_dir', 'node_selector', 'image_pull_policy',
resource_gpu='0', image_pull_policy=conf.get('IMAGE_PULL_POLICY', 'Always'), image_pull_secrets=conf.get('HUBSECRET', []), image='ccr.ccs.tencentyun.com/cube-studio/docker', hostAliases=hostAliases, env=None, privileged=None, accounts=None, username=docker.created_by.username, node_name=node_name) from myapp.tasks.async_task import check_docker_commit # 发起异步任务检查commit pod是否完成,如果完成,修正last_image kwargs = {"docker_id": docker.id} check_docker_commit.apply_async(kwargs=kwargs) return redirect("/myapp/web/log/%s/%s/%s" % (conf.get('ENVIRONMENT'), namespace, pod_name)) class Docker_ModelView(Docker_ModelView_Base, MyappModelView, DeleteMixin): datamodel = SQLAInterface(Docker) # 添加视图和菜单 appbuilder.add_view(Docker_ModelView, "镜像调试", href="/docker_modelview/list/", icon='fa-cubes', category='在线开发', category_icon='fa-glass')
def stop(self, crd_id): workflow = db.session.query(self.datamodel.obj).filter_by(id=crd_id).first() self.delete_workflow(workflow) flash('清理完成','warning') self.update_redirect() return redirect(self.get_redirect()) label_title = '运行实例' datamodel = SQLAInterface(Workflow) list_columns = ['project','pipeline_url', 'create_time','change_time','elapsed_time', 'final_status','status', 'username', 'log','stop'] show_columns = ['name', 'namespace', 'create_time', 'status','task_status', 'annotations_html', 'labels_html', 'spec_html','status_more_html', 'info_json_html'] crd_name = 'workflow' appbuilder.add_view(Workflow_ModelView,"运行实例",href='/workflow_modelview/list/?_flt_2_name=&_flt_2_labels=',icon = 'fa-tasks',category = '训练') # 添加api class Workflow_ModelView_Api(Crd_ModelView_Base,MyappModelRestApi): datamodel = SQLAInterface(Workflow) route_base = '/workflow_modelview/api' list_columns = ['name', 'namespace_url', 'create_time', 'status', 'username', 'log'] crd_name = 'workflow' appbuilder.add_api(Workflow_ModelView_Api)
from flask_appbuilder.models.sqla.interface import SQLAInterface from flask_babel import gettext as __ from myapp import app, appbuilder from myapp.models.log import Log from myapp.views.base import MyappModelView from . import LogMixin class LogModelView(LogMixin, MyappModelView): datamodel = SQLAInterface(Log) list_columns = ['user', 'method', 'path', 'duration_ms', 'dttm'] if (not app.config.get("FAB_ADD_SECURITY_VIEWS") is False or app.config.get("MYAPP_LOG_VIEW") is False): appbuilder.add_view( LogModelView, "Action Log", label=__("Action Log"), category="Security", category_label=__("Security"), icon="fa-list-ol", )
template['username'] = g.user.username, index += 1 return jsonify(all_template) class Service_Pipeline_ModelView(Service_Pipeline_ModelView_Base, MyappModelView, DeleteMixin): datamodel = SQLAInterface(Service_Pipeline) # base_order = ("changed_on", "desc") # order_columns = ['changed_on'] appbuilder.add_view(Service_Pipeline_ModelView, "推理pipeline", href="/service_pipeline_modelview/list/", icon='fa-sitemap', category='服务化') # 添加api class Service_Pipeline_ModelView_Api(Service_Pipeline_ModelView_Base, MyappModelRestApi): datamodel = SQLAInterface(Service_Pipeline) route_base = '/service_pipeline_modelview/api' show_columns = [ 'project', 'name', 'describe', 'namespace', 'node_selector', 'image_pull_policy', 'env', 'dag_json', 'run_id', 'created_by', 'changed_by', 'created_on', 'changed_on', 'expand' ] list_columns = show_columns
__("Stop"), __("Stop all Really?"), "fa-trash", single=False) def stop_all(self, items): self.base_muldelete(items) self.update_redirect() return redirect(self.get_redirect()) class Notebook_ModelView(Notebook_ModelView_Base, MyappModelView, DeleteMixin): datamodel = SQLAInterface(Notebook) # 添加视图和菜单 appbuilder.add_view(Notebook_ModelView, "notebook", href="/notebook_modelview/list/?_flt_0_created_by=", icon='fa-file-code-o', category='在线开发', category_icon='fa-code') # 添加api class Notebook_ModelView_Api(Notebook_ModelView_Base, MyappModelRestApi): datamodel = SQLAInterface(Notebook) route_base = '/notebook_modelview/api' appbuilder.add_api(Notebook_ModelView_Api)
new_hp.name = new_hp.name+"-copy" new_hp.describe = new_hp.describe + "-copy" new_hp.created_on = datetime.datetime.now() new_hp.changed_on = datetime.datetime.now() db.session.add(new_hp) db.session.commit() return redirect(request.referrer) class Hyperparameter_Tuning_ModelView(Hyperparameter_Tuning_ModelView_Base,MyappModelView): datamodel = SQLAInterface(Hyperparameter_Tuning) conv = GeneralModelConverter(datamodel) # 添加视图和菜单 appbuilder.add_view(Hyperparameter_Tuning_ModelView,"katib超参搜索",icon = 'fa-shopping-basket',category = '超参搜索',category_icon = 'fa-glass') # 添加api class Hyperparameter_Tuning_ModelView_Api(Hyperparameter_Tuning_ModelView_Base,MyappModelRestApi): datamodel = SQLAInterface(Hyperparameter_Tuning) conv = GeneralModelConverter(datamodel) route_base = '/hyperparameter_tuning_modelview/api' list_columns = ['created_by','changed_by','created_on','changed_on','job_type','name','namespace','describe', 'parallel_trial_count','max_trial_count','max_failed_trial_count','objective_type', 'objective_goal','objective_metric_name','objective_additional_metric_names','algorithm_name', 'algorithm_setting','parameters','job_json','trial_spec','working_dir','node_selector', 'image_pull_policy','resource_memory','resource_cpu','experiment','alert_status'] add_columns = ['job_type','name','namespace','describe', 'parallel_trial_count','max_trial_count','max_failed_trial_count','objective_type', 'objective_goal','objective_metric_name','objective_additional_metric_names','algorithm_name',
edit_columns = ['status'] base_filters = [["id", RunHistory_Filter, lambda: []]] # 设置权限过滤器 add_form_extra_fields = { "status": SelectField(_(datamodel.obj.lab('status')), description="状态comed为已识别未提交,created为已提交", widget=Select2Widget(), choices=[['comed', 'comed'], ['created', 'created']]), } edit_form_extra_fields = add_form_extra_fields class RunHistory_ModelView(RunHistory_ModelView_Base, MyappModelView, DeleteMixin): datamodel = SQLAInterface(RunHistory) appbuilder.add_view(RunHistory_ModelView, "定时调度记录", icon='fa-clock-o', category='训练') # 添加api class RunHistory_ModelView_Api(RunHistory_ModelView_Base, MyappModelRestApi): datamodel = SQLAInterface(RunHistory) route_base = '/runhistory_modelview/api' appbuilder.add_api(RunHistory_ModelView_Api)