cube-studio/myapp/models/model_docker.py

62 lines
2.1 KiB
Python
Raw Normal View History

2021-09-07 18:09:47 +08:00
from flask_appbuilder import Model
from sqlalchemy import Column, Integer, String, ForeignKey,Float
from sqlalchemy.orm import relationship
import datetime,time,json
from sqlalchemy import (
Boolean,
Column,
create_engine,
DateTime,
ForeignKey,
Integer,
MetaData,
String,
Table,
Text,
Enum,
)
import pysnooper
from myapp.models.base import MyappModelBase
from myapp.models.helpers import AuditMixinNullable, ImportMixin
from flask import escape, g, Markup, request
from myapp import app,db
from myapp.models.helpers import ImportMixin
from sqlalchemy import Column, Integer, String, ForeignKey ,Date,DateTime
from flask_appbuilder.models.decorators import renders
from flask import Markup
import datetime
metadata = Model.metadata
conf = app.config
2021-10-14 17:33:57 +08:00
# from myapp.utils.py.py_k8s import K8s
2021-09-07 18:09:47 +08:00
class Docker(Model,AuditMixinNullable,MyappModelBase):
__tablename__ = 'docker'
id = Column(Integer, primary_key=True)
2022-08-08 20:11:53 +08:00
project_id = Column(Integer, ForeignKey('project.id'), nullable=False)
2021-11-25 18:05:19 +08:00
project = relationship(
"Project", foreign_keys=[project_id]
)
2021-09-07 18:09:47 +08:00
describe = Column(String(200), nullable=True)
base_image = Column(String(200), nullable=True)
target_image=Column(String(200), nullable=True,default='')
2021-10-14 17:33:57 +08:00
last_image = Column(String(200), nullable=True, default='')
need_gpu = Column(Boolean, nullable=True, default=False)
2022-08-08 20:11:53 +08:00
consecutive_build = Column(Boolean, default=True)
2021-10-14 17:33:57 +08:00
expand = Column(Text(65536), default='{}')
2021-09-07 18:09:47 +08:00
def __repr__(self):
return self.label
@property
def save(self):
return Markup(f'<a href="/docker_modelview/save/{self.id}">保存</a>')
@property
def debug(self):
2022-08-04 16:00:41 +08:00
return Markup(f'<a target=_blank href="/docker_modelview/debug/{self.id}">调试</a> | <a href="/docker_modelview/delete_pod/{self.id}">清理</a> | <a target=_blank href="/docker_modelview/save/{self.id}">保存</a>')
2021-10-14 17:33:57 +08:00
2021-11-25 18:05:19 +08:00
@property
def image_history(self):
return Markup(f'基础镜像:{self.base_image}<br>当前镜像:{self.last_image if self.last_image else self.base_image}<br>目标镜像:{self.target_image}')