class HDocumentBase(DynamicDocument): """ DB model base class, providing basic functions """ create_time = DateTimeField(default=get_now()) update_time = DateTimeField(default=get_now()) meta = { 'allow_inheritance': True, 'abstract': True, 'queryset_class': HQuerySet } unsafe_columns = [] def __init__(self, **kwargs): super(HDocumentBase, self).__init__(**kwargs) def dic(self): result = to_dic(self) for k in self.unsafe_columns: result.pop(k, None) return result def __repr__(self): return '%s: %s' % (self.__class__.__name__, self.to_json())
class AzureVirtualMachine(DBBase): """ Azure virtual machine information """ __tablename__ = 'azure_virtual_machine' id = Column(Integer, primary_key=True) name = Column(String(50)) label = Column(String(50)) # AVMStatus in enum.py status = Column(String(50)) dns = Column(String(50)) public_ip = Column(String(50)) private_ip = Column(String(50)) deployment_id = Column(Integer, ForeignKey('azure_deployment.id', ondelete='CASCADE')) deployment = relationship('AzureDeployment', backref=backref('azure_virtual_machines_d', lazy='dynamic')) experiment_id = Column(Integer, ForeignKey('experiment.id', ondelete='CASCADE')) experiment = relationship('Experiment', backref=backref('azure_virtual_machines_e', lazy='dynamic')) virtual_environment_id = Column(Integer, ForeignKey('virtual_environment.id', ondelete='CASCADE')) virtual_environment = relationship('VirtualEnvironment', backref=backref('azure_virtual_machines_v', lazy='dynamic')) create_time = Column(TZDateTime, default=get_now()) last_modify_time = Column(TZDateTime, default=get_now()) def __init__(self, **kwargs): super(AzureVirtualMachine, self).__init__(**kwargs)
def report_health(q): """Report health status of open hackathon server :type q: str|unicode :param q: the report type. Can be 'all' or None or a key of health item :rtype dict :return health status including overall status and details of sub items """ items = basic_health_items if q == "all": items = all_health_items elif q in all_health_items.keys(): items = { q: all_health_items[q] } up = get_now() - app_start_time days, hours, minutes = up.days, up.seconds / 3600, up.seconds % 3600 / 60.0 health = { STATUS: HEALTH_STATUS.OK, "start_time": str(app_start_time), "report_time": str(get_now()), "up": "%d days %d hours %d minutes" % (days, hours, minutes) } return __report_detail(health, items)
def report_health(q): """Report health status of open hackathon server :type q: str|unicode :param q: the report type. Can be 'all' or None or a key of health item :rtype dict :return health status including overall status and details of sub items """ items = basic_health_items if q == "all": items = all_health_items elif q in list(all_health_items.keys()): items = { q: all_health_items[q] } up = get_now() - app_start_time days, hours, minutes = up.days, up.seconds / 3600, up.seconds % 3600 / 60.0 health = { STATUS: HEALTH_STATUS.OK, "start_time": str(app_start_time), "report_time": str(get_now()), "up": "%d days %d hours %d minutes" % (days, hours, minutes) } return __report_detail(health, items)
class User(DBBase): __tablename__ = 'user' id = Column(Integer, primary_key=True) password = Column(String(100)) # encrypted password for the default admin/guest users. name = Column(String(50)) nickname = Column(String(50)) provider = Column(String(20)) openid = Column(String(100)) avatar_url = Column(String(200)) access_token = Column(String(100)) online = Column(Integer) # 0:offline 1:online create_time = Column(TZDateTime, default=get_now()) last_login_time = Column(TZDateTime, default=get_now()) def get_user_id(self): return self.id def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return unicode(self.get_user_id()) def __init__(self, **kwargs): super(User, self).__init__(**kwargs)
class Experiment(DBBase): """ Experiment is launched once template is used: 1. user use template directly (user manage his own azure resources through template) 2. hackathon use template directly (hackathon manage its own azure resources through template) 3. user use template via hackathon (online) """ __tablename__ = 'experiment' id = Column(Integer, primary_key=True) # EStatus in enum.py status = Column(Integer) create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) last_heart_beat_time = Column(TZDateTime, default=get_now()) template_id = Column(Integer, ForeignKey('template.id', ondelete='CASCADE')) template = relationship('Template', backref=backref('experiments', lazy='dynamic')) # negative if hackathon use template directly user_id = Column(Integer, ForeignKey('user.id', ondelete='CASCADE')) user = relationship('User', backref=backref('experiments', lazy='dynamic')) # negative if user use template directly hackathon_id = Column(Integer, ForeignKey('hackathon.id', ondelete='CASCADE')) hackathon = relationship('Hackathon', backref=backref('experiments', lazy='dynamic')) def __init__(self, **kwargs): super(Experiment, self).__init__(**kwargs)
class AzureCloudService(DBBase): """ Azure cloud service information """ __tablename__ = 'azure_cloud_service' id = Column(Integer, primary_key=True) name = Column(String(50)) label = Column(String(50)) location = Column(String(50)) # ACSStatus in enum.py status = Column(String(50)) # AzureCloudService should have nothing to do with experiment # instead, it should belong to a azure_key # # experiment_id = Column(Integer, ForeignKey('experiment.id', ondelete='CASCADE')) # experiment = relationship('Experiment', backref=backref('azure_cloud_service', lazy='dynamic')) azure_key_id = Column(Integer, ForeignKey("azure_key.id", ondelete='CASCADE')) azure_key = relationship('AzureKey', backref=backref("azure_cloud_service", lazy="dynamic")) create_time = Column(TZDateTime, default=get_now()) last_modify_time = Column(TZDateTime, default=get_now()) def __init__(self, **kwargs): super(AzureCloudService, self).__init__(**kwargs)
class AzureDeployment(DBBase): """ Azure deployment information """ __tablename__ = 'azure_deployment' id = Column(Integer, primary_key=True) name = Column(String(50)) slot = Column(String(50)) # ADStatus in enum.py status = Column(String(50)) cloud_service_id = Column( Integer, ForeignKey('azure_cloud_service.id', ondelete='CASCADE')) cloud_service = relationship('AzureCloudService', backref=backref('azure_deployment_c', lazy='dynamic')) experiment_id = Column(Integer, ForeignKey('experiment.id', ondelete='CASCADE')) experiment = relationship('Experiment', backref=backref('azure_deployment_e', lazy='dynamic')) create_time = Column(TZDateTime, default=get_now()) last_modify_time = Column(TZDateTime, default=get_now()) def __init__(self, **kwargs): super(AzureDeployment, self).__init__(**kwargs)
def run_job(mdl_cls_func, cls_args, func_args, second=DEFAULT_TICK): exec_time = get_now() + timedelta(seconds=second) scheduler = RequiredFeature("scheduler") scheduler.get_scheduler().add_job(call, 'date', run_date=exec_time, args=[mdl_cls_func, cls_args, func_args])
class Hackathon(DBBase): __tablename__ = 'hackathon' id = Column(Integer, primary_key=True) name = Column(String(50), unique=True, nullable=False, index=True) display_name = Column(String(64)) ribbon = Column(String(64)) # a short sentence of advertisement short_description = Column(String(200)) banners = Column(Text) description = Column(Text) status = Column(Integer, default=0) # 0-new 1-online 2-offline creator_id = Column(Integer, default=-1) type = Column(Integer, default=1) # enum.HACK_TYPE event_start_time = Column(TZDateTime) event_end_time = Column(TZDateTime) registration_start_time = Column(TZDateTime) registration_end_time = Column(TZDateTime) judge_start_time = Column(TZDateTime) judge_end_time = Column(TZDateTime) create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) archive_time = Column(TZDateTime) def __init__(self, **kwargs): super(Hackathon, self).__init__(**kwargs)
class DockerHostServer(DBBase): __tablename__ = 'docker_host_server' id = Column(Integer, primary_key=True) vm_name = Column(String(100), nullable=False) public_dns = Column(String(50)) public_ip = Column(String(50)) public_docker_api_port = Column(Integer) private_ip = Column(String(50)) private_docker_api_port = Column(Integer) container_count = Column(Integer, nullable=False) container_max_count = Column(Integer, nullable=False) is_auto = Column(Integer, default=0) # 0-started manually 1-started by OHP server create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) state = Column(Integer, default=0) # 0-VM starting, 1-docker init, 2-docker API ready, 3-unavailable disabled = Column(Integer, default=0) # 1-disabled by manager, 0-available hackathon_id = Column(Integer, ForeignKey('hackathon.id', ondelete='CASCADE')) hackathon = relationship('Hackathon', backref=backref('docker_host_servers', lazy='dynamic')) def __init__(self, **kwargs): super(DockerHostServer, self).__init__(**kwargs)
def setup_db(): """Initialize db tables make sure database and user correctly created in mysql in case upgrade the table structure, the origin table need be dropped firstly """ Base.metadata.create_all(bind=engine) # init REQUIRED db data. # reserved user res_u = db_adapter.get_object(User, ReservedUser.DefaultUserID) if res_u is None: db_adapter.add_object_kwargs(User, id=ReservedUser.DefaultUserID, create_time=get_now()) # default super admin if db_adapter.get_object(User, ReservedUser.DefaultSuperAdmin) is None: db_adapter.add_object_kwargs( User, id=ReservedUser.DefaultSuperAdmin, name="admin", nickname="admin", password="******") # default admin privilege if db_adapter.find_first_object_by(AdminHackathonRel, user_id=ReservedUser.DefaultSuperAdmin, hackathon_id=-1) is None: db_adapter.add_object_kwargs(AdminHackathonRel, user_id=ReservedUser.DefaultSuperAdmin, hackathon_id=-1, role_type=ADMIN_ROLE_TYPE.ADMIN)
class VirtualEnvironment(DBBase): """ Virtual environment is abstraction of smallest environment unit in template """ __tablename__ = 'virtual_environment' id = Column(Integer, primary_key=True) # VE_PROVIDER in enum.py provider = Column(Integer) name = Column(String(100), nullable=False) image = Column(String(100)) # VEStatus in enum.py status = Column(Integer) # VERemoteProvider in enum.py remote_provider = Column(Integer) remote_paras = Column(String(300)) create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) experiment_id = Column(Integer, ForeignKey('experiment.id', ondelete='CASCADE')) experiment = relationship('Experiment', backref=backref('virtual_environments', lazy='dynamic')) def __init__(self, **kwargs): super(VirtualEnvironment, self).__init__(**kwargs)
class Hackathon(DBBase): __tablename__ = 'hackathon' id = Column(Integer, primary_key=True) name = Column(String(50), unique=True, nullable=False, index=True) display_name = Column(String(64)) description = Column(Text) status = Column(Integer, default=0) # 0-new 1-online 2-offline creator_id = Column(Integer, default=-1) type = Column(Integer, default=1) # enum.HACK_TYPE event_start_time = Column(TZDateTime) event_end_time = Column(TZDateTime) registration_start_time = Column(TZDateTime) registration_end_time = Column(TZDateTime) judge_start_time = Column(TZDateTime) judge_end_time = Column(TZDateTime) basic_info = Column(Text) extra_info = Column(Text) create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) archive_time = Column(TZDateTime) def dic(self): d = to_dic(self, self.__class__) d["basic_info"] = json.loads(self.basic_info or "{}") d["extra_info"] = json.loads(self.extra_info or "{}") return d def __init__(self, **kwargs): super(Hackathon, self).__init__(**kwargs)
class AzureEndpoint(DBBase): """ Input endpoint information of Azure virtual machine """ __tablename__ = 'azure_endpoint' id = Column(Integer, primary_key=True) name = Column(String(50)) protocol = Column(String(50)) public_port = Column(Integer) private_port = Column(Integer) virtual_machine_id = Column(Integer, ForeignKey('azure_virtual_machine.id', ondelete='CASCADE')) virtual_machine = relationship('AzureVirtualMachine', backref=backref('azure_endpoints', lazy='dynamic')) create_time = Column(TZDateTime, default=get_now()) last_modify_time = Column(TZDateTime, default=get_now()) def __init__(self, **kwargs): super(AzureEndpoint, self).__init__(**kwargs)
class AzureKey(DBBase): """ Azure certificate information of user/hackathon """ __tablename__ = 'azure_key' id = Column(Integer, primary_key=True) # cert_url is cert file path in azure cert_url = Column(String(200)) # pem_url is pem file path in local pem_url = Column(String(200)) subscription_id = Column(String(100)) management_host = Column(String(100)) create_time = Column(TZDateTime, default=get_now()) last_modify_time = Column(TZDateTime, default=get_now()) def __init__(self, **kwargs): super(AzureKey, self).__init__(**kwargs)
class AzureStorageAccount(DBBase): """ Azure storage account information """ __tablename__ = 'azure_storage_account' id = Column(Integer, primary_key=True) name = Column(String(50)) description = Column(String(100)) label = Column(String(50)) location = Column(String(50)) # ASAStatus in enum.py status = Column(String(50)) experiment_id = Column(Integer, ForeignKey('experiment.id', ondelete='CASCADE')) experiment = relationship('Experiment', backref=backref('azure_storage_account', lazy='dynamic')) create_time = Column(TZDateTime, default=get_now()) last_modify_time = Column(TZDateTime, default=get_now()) def __init__(self, **kwargs): super(AzureStorageAccount, self).__init__(**kwargs)
class HackathonTag(DBBase): __tablename__ = 'hackathon_tag' id = Column(Integer, primary_key=True) tag = Column(String(50)) create_time = Column(TZDateTime, default=get_now()) hackathon_id = Column(Integer, ForeignKey('hackathon.id', ondelete='CASCADE')) hackathon = relationship('Hackathon', backref=backref('tags', lazy='dynamic'))
def add_once(self, feature, method, context=None, id=None, replace_existing=True, run_date=None, **delta): """Add a job to APScheduler and executed only once Job will be executed at 'run_date' or after certain timedelta. :Example: scheduler = RequiredFeature("scheduler") # execute task once in 5 minutes: context = Context(user_id=1) scheduler.add_once("user_manager","get_user_by_id",context=context, minutes=5) # 5 minutes later, user_manager.get_user_by_id(context) will be executed :type feature: str|unicode :param: the feature that are used to look for instance through hackathon_factory. All features are defined in __init__.py :type method: str|unicode :param method: the method name defined in the instance :type context: Context, see hackathon/__init__.py :param context: the execution context. Actually the parameters of 'method' :type id: str :param id: id for APScheduler job. Random id will be generated if not specified by caller :type replace_existing: bool :param replace_existing: if true, existing job with the same id will be replaced. If false, exception will be raised :type run_date: datetime | None :param run_date: job run date. If None, job run date will be datetime.now()+timedelta(delta) :type delta: kwargs for timedelta :param delta: kwargs for timedelta. For example: minutes=5. Will be ignored if run_date is not None """ if not run_date: run_date = get_now() + timedelta(**delta) if self.__apscheduler: self.__apscheduler.add_job(scheduler_executor, trigger='date', run_date=run_date, id=id, max_instances=1, replace_existing=replace_existing, jobstore=self.jobstore, args=[feature, method, context])
class VirtualEnvironment(DynamicEmbeddedDocument): """ Virtual environment is abstraction of smallest environment unit in template """ provider = IntField() # VE_PROVIDER in enum.py name = StringField(required=True, unique=True) status = IntField(required=True) # VEStatus in enum.py remote_provider = IntField() # VERemoteProvider in enum.py remote_paras = DictField() create_time = DateTimeField(default=get_now()) update_time = DateTimeField() docker_container = EmbeddedDocumentField(DockerContainer) azure_resource = EmbeddedDocumentField(AzureVirtualMachine)
class UserToken(DBBase): __tablename__ = 'user_token' id = Column(Integer, primary_key=True) token = Column(String(50), unique=True, nullable=False) user_id = Column(Integer, ForeignKey('user.id', ondelete='CASCADE')) user = relationship('User', backref=backref('tokens', lazy='dynamic')) issue_date = Column(TZDateTime, default=get_now()) expire_date = Column(TZDateTime, nullable=False) def __init__(self, **kwargs): super(UserToken, self).__init__(**kwargs)
class AdminHackathonRel(DBBase): __tablename__ = 'admin_hackathon_rel' id = Column(Integer, primary_key=True) user_id = Column(Integer, ForeignKey('user.id', ondelete='CASCADE')) user = relationship('User', backref=backref('admin_hackathon_rels', lazy='dynamic')) role_type = Column(Integer) # enum.ADMIN_ROLE_TYPE hackathon_id = Column(Integer) status = Column(Integer, default=0) # reserved, not in use currently remarks = Column(String(255)) create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) def __init__(self, **kwargs): super(AdminHackathonRel, self).__init__(**kwargs)
class UserHackathonAsset(DBBase): __tablename__ = 'user_hackathon_asset' id = Column(Integer, primary_key=True) user_id = Column(Integer, ForeignKey('user.id', ondelete='CASCADE')) hackathon_id = Column(Integer, ForeignKey('hackathon.id', ondelete='CASCADE')) asset_name = Column(String(50)) asset_value = Column(Text) description = Column(Text) create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) def __init__(self, **kwargs): super(UserHackathonAsset, self).__init__(**kwargs)
class UserEmail(DBBase): __tablename__ = 'user_email' id = Column(Integer, primary_key=True) name = Column(String(80)) email = Column(String(120)) primary_email = Column(Integer) # 0:NOT Primary Email 1:Primary Email verified = Column(Integer) # 0 for not verified, 1 for verified create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) user_id = Column(Integer, ForeignKey('user.id', ondelete='CASCADE')) user = relationship('User', backref=backref('emails', lazy='dynamic')) def get_user_email(self): return self.email
class HackathonLike(DBBase): __tablename__ = 'hackathon_like' id = Column(Integer, primary_key=True) create_time = Column(TZDateTime, default=get_now()) user_id = Column(Integer, ForeignKey('user.id', ondelete='CASCADE')) user = relationship('User', backref=backref('likes', lazy='dynamic')) hackathon_id = Column(Integer, ForeignKey('hackathon.id', ondelete='CASCADE')) hackathon = relationship('Hackathon', backref=backref('likes', lazy='dynamic')) def __init__(self, **kwargs): super(HackathonLike, self).__init__(**kwargs)
class HackathonTemplateRel(DBBase): __tablename__ = 'hackathon_template_rel' id = Column(Integer, primary_key=True) create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) team_id = Column(Integer, default=-1) # -1: avaiable for all teams hackathon_id = Column(Integer, ForeignKey('hackathon.id', ondelete='CASCADE')) hackathon = relationship('Hackathon', backref=backref('hackathon_template_rels', lazy='dynamic')) template_id = Column(Integer, ForeignKey('template.id', ondelete='CASCADE')) template = relationship('Template', backref=backref('hackathon_template_rels', lazy='dynamic')) def __init__(self, **kwargs): super(HackathonTemplateRel, self).__init__(**kwargs)
class HackathonOrganizer(DBBase): __tablename__ = 'hackathon_organizer' id = Column(Integer, primary_key=True) name = Column(String(50)) organization_type = Column(Integer) description = Column(Text) homepage = Column(String(100)) logo = Column(String(200)) create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) hackathon_id = Column(Integer, ForeignKey('hackathon.id', ondelete='CASCADE')) hackathon = relationship('Hackathon', backref=backref('organizers', lazy='dynamic'))
class Template(DBBase): __tablename__ = 'template' id = Column(Integer, primary_key=True) name = Column(String(50), unique=True) url = Column(String(200)) local_path = Column(String(200)) provider = Column(Integer, default=0) status = Column(Integer) # 1=online , 0=offline create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) description = Column(Text) virtual_environment_count = Column(Integer, default=0) creator_id = Column(Integer, ForeignKey('user.id', ondelete='CASCADE')) def __init__(self, **kwargs): super(Template, self).__init__(**kwargs)
class TeamScore(DBBase): __tablename__ = 'team_score' id = Column(Integer, primary_key=True) type = Column(Integer, default=0) score = Column(Integer) reason = Column(String(200)) create_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) team_id = Column(Integer, ForeignKey('team.id', ondelete='CASCADE')) team = relationship('Team', backref=backref('scores', lazy='dynamic')) judge_id = Column(Integer, ForeignKey('user.id', ondelete='CASCADE')) judge = relationship('User', backref=backref('scores', lazy='dynamic')) def __init__(self, **kwargs): super(TeamScore, self).__init__(**kwargs)
class UserTeamRel(DBBase): __tablename__ = 'user_team_rel' id = Column(Integer, primary_key=True) join_time = Column(TZDateTime, default=get_now()) update_time = Column(TZDateTime) status = Column(Integer) # 0:unaudit ,1:audit_passed, 2:audit_refused hackathon_id = Column(Integer, ForeignKey('hackathon.id', ondelete='CASCADE')) user_id = Column(Integer, ForeignKey('user.id', ondelete='CASCADE')) user = relationship('User', backref=backref('user_team_rels', lazy='dynamic')) team_id = Column(Integer, ForeignKey('team.id', ondelete='CASCADE')) team = relationship('Team', backref=backref('user_team_rels', lazy='dynamic')) def __init__(self, **kwargs): super(UserTeamRel, self).__init__(**kwargs)
class UserToken(HDocumentBase): token = StringField(required=True) user = ReferenceField(User) issue_date = DateTimeField(default=get_now()) expire_date = DateTimeField(required=True) meta = { 'indexes': [ { # See mongodb and mongo engine documentation for details # by default, mongoengine will add a `_cls` field with the index as a compund index # but mongodb only support Single Key Index on Hashed Token so far # set the `cls` option to False can disable this beahviour on mongoengine "fields": ["#token"], "cls": False}]} def __init__(self, **kwargs): super(UserToken, self).__init__(**kwargs)
def setup_db(): """Initialize db tables make sure database and user correctly created in mysql in case upgrade the table structure, the origin table need be dropped firstly """ Base.metadata.create_all(bind=engine) # init REQUIRED db data. # reserved user res_u = db_adapter.get_object(User, ReservedUser.DefaultUserID) if res_u is None: db_adapter.add_object_kwargs(User, id=ReservedUser.DefaultUserID, create_time=get_now()) # default super admin if db_adapter.get_object(User, ReservedUser.DefaultSuperAdmin) is None: db_adapter.add_object_kwargs(User, id=ReservedUser.DefaultSuperAdmin, name="admin", nickname="admin", password="******") # default admin privilege if db_adapter.find_first_object_by(AdminHackathonRel, user_id=ReservedUser.DefaultSuperAdmin, hackathon_id=-1) is None: db_adapter.add_object_kwargs(AdminHackathonRel, user_id=ReservedUser.DefaultSuperAdmin, hackathon_id=-1, role_type=ADMIN_ROLE_TYPE.ADMIN)
# THE SOFTWARE. # ----------------------------------------------------------------------------------- import sys sys.path.append("..") from hackathon.util import get_now from hackathon import RequiredFeature from hackathon.constants import HEALTH_STATUS __all__ = ["report_health"] # the time when application starts app_start_time = get_now() STATUS = "status" # all available health check items all_health_items = { "mysql": RequiredFeature("health_check_mysql"), "docker": RequiredFeature("health_check_hosted_docker"), "alauda": RequiredFeature("health_check_alauda_docker"), "guacamole": RequiredFeature("health_check_guacamole"), "azure": RequiredFeature("health_check_azure"), "storage": RequiredFeature("storage") } # basic health check items which are fundamental for OHP basic_health_items = {
""" from hackathon.database.models import * from hackathon.constants import HACKATHON_BASIC_INFO, VE_PROVIDER from datetime import timedelta import json import os from os.path import realpath, dirname from hackathon.util import get_now # test hackathon hackathon = db_adapter.find_first_object_by(Hackathon, name="sample") if hackathon is None: hackathon = Hackathon(name="sample", display_name="Open Hackathon", description="This is a demo for Open Hackathon Project", event_start_time=get_now(), event_end_time=get_now() + timedelta(days=365), registration_start_time=get_now(), registration_end_time=get_now() + timedelta(days=365), judge_start_time=get_now(), judge_end_time=get_now() + timedelta(days=365), status=1) db_adapter.add_object(hackathon) # test docker host server docker_host = DockerHostServer(vm_name="contosovmhost", public_dns="contosovmhost.chinacloudapp.cn", public_ip="42.159.193.92", public_docker_api_port=4243, private_ip="10.207.210.29", private_docker_api_port=4243, container_count=0, container_max_count=100, hackathon=hackathon) if db_adapter.find_first_object_by(DockerHostServer, vm_name=docker_host.vm_name, hackathon_id=hackathon.id) is None: db_adapter.add_object(docker_host) # test template: ubuntu terminal