Exemplo n.º 1
0
 def create_or_update_register(self, **args):
     try:
         register = db_adapter.find_first_object(Register,Register.email==args['email'],Register.hackathon_id==g.hackathon_id)
         if register is None:
             #create a register
             log.debug("create a new register")
             db_adapter.add_object_kwargs(Register,
                                          register_name=args['name'],
                                          email=args['email'],
                                          create_time=datetime.utcnow(),
                                          description=args['description'],
                                          enabled=1,  # 0: disabled 1:enabled
                                          jstrom_api='',
                                          jstrom_mgmt_portal='',
                                          hackathon_id=g.hackathon_id)
         else:
             #update a aready existe register
             log.debug("update a new register")
             db_adapter.update_object(register,
                                      register_name=args['name'],
                                      email=args['email'],
                                      create_time=datetime.utcnow(),
                                      description=args['description'],
                                      enabled=args['enabled'],  # 0: disabled 1:enabled
                                      strom_api='',
                                      jstrom_mgmt_portal='',
                                      hackathon_id=g.hackathon_id)
     except Exception:
         log.error("create or update register faild")
         return {"error": "INTERNAL SERVER ERROR"}, 500
Exemplo n.º 2
0
 def create_or_update_register(self, **args):
     try:
         register = db_adapter.find_first_object(
             Register, Register.email == args['email'],
             Register.hackathon_id == g.hackathon_id)
         if register is None:
             #create a register
             log.debug("create a new register")
             db_adapter.add_object_kwargs(
                 Register,
                 register_name=args['name'],
                 email=args['email'],
                 create_time=datetime.utcnow(),
                 description=args['description'],
                 enabled=1,  # 0: disabled 1:enabled
                 jstrom_api='',
                 jstrom_mgmt_portal='',
                 hackathon_id=g.hackathon_id)
         else:
             #update a aready existe register
             log.debug("update a new register")
             db_adapter.update_object(
                 register,
                 register_name=args['name'],
                 email=args['email'],
                 create_time=datetime.utcnow(),
                 description=args['description'],
                 enabled=args['enabled'],  # 0: disabled 1:enabled
                 strom_api='',
                 jstrom_mgmt_portal='',
                 hackathon_id=g.hackathon_id)
     except Exception:
         log.error("create or update register faild")
         return {"error": "INTERNAL SERVER ERROR"}, 500
Exemplo n.º 3
0
def commit_azure_cloud_service(name, label, location, status, experiment_id):
    db_adapter.add_object_kwargs(AzureCloudService,
                                 name=name,
                                 label=label,
                                 location=location,
                                 status=status,
                                 experiment_id=experiment_id)
    db_adapter.commit()
Exemplo n.º 4
0
def commit_azure_endpoint(name, protocol, public_port, private_port, virtual_machine):
    db_adapter.add_object_kwargs(AzureEndpoint,
                                 name=name,
                                 protocol=protocol,
                                 public_port=public_port,
                                 private_port=private_port,
                                 virtual_machine=virtual_machine)
    db_adapter.commit()
Exemplo n.º 5
0
def commit_azure_endpoint(name, protocol, public_port, private_port, virtual_machine):
    db_adapter.add_object_kwargs(AzureEndpoint,
                                 name=name,
                                 protocol=protocol,
                                 public_port=public_port,
                                 private_port=private_port,
                                 virtual_machine=virtual_machine)
    db_adapter.commit()
Exemplo n.º 6
0
def commit_azure_cloud_service(name, label, location, status, experiment_id):
    db_adapter.add_object_kwargs(AzureCloudService,
                                 name=name,
                                 label=label,
                                 location=location,
                                 status=status,
                                 experiment_id=experiment_id)
    db_adapter.commit()
Exemplo n.º 7
0
def commit_azure_storage_account(name, description, label, location, status, experiment_id):
    db_adapter.add_object_kwargs(AzureStorageAccount,
                                 name=name,
                                 description=description,
                                 label=label,
                                 location=location,
                                 status=status,
                                 experiment_id=experiment_id)
    db_adapter.commit()
Exemplo n.º 8
0
def commit_azure_storage_account(name, description, label, location, status, experiment_id):
    db_adapter.add_object_kwargs(AzureStorageAccount,
                                 name=name,
                                 description=description,
                                 label=label,
                                 location=location,
                                 status=status,
                                 experiment_id=experiment_id)
    db_adapter.commit()
Exemplo n.º 9
0
def commit_azure_deployment(name, slot, status, cloud_service_name, experiment_id):
    cs = db_adapter.find_first_object_by(AzureCloudService, name=cloud_service_name)
    db_adapter.add_object_kwargs(AzureDeployment,
                                 name=name,
                                 slot=slot,
                                 status=status,
                                 cloud_service=cs,
                                 experiment_id=experiment_id)
    db_adapter.commit()
Exemplo n.º 10
0
def commit_azure_deployment(name, slot, status, cloud_service_name, experiment_id):
    cs = db_adapter.find_first_object_by(AzureCloudService, name=cloud_service_name)
    db_adapter.add_object_kwargs(AzureDeployment,
                                 name=name,
                                 slot=slot,
                                 status=status,
                                 cloud_service=cs,
                                 experiment_id=experiment_id)
    db_adapter.commit()
Exemplo n.º 11
0
def commit_azure_log(experiment_id, operation, status, note=None, code=None):
    db_adapter.add_object_kwargs(
        AzureLog, experiment_id=experiment_id, operation=operation, status=status, note=note, code=code
    )
    db_adapter.commit()
    if status == ALStatus.FAIL:
        update_experiment_status(experiment_id, EStatus.FAILED)
    elif status == ALStatus.END:
        need_status = EStatus.RUNNING
        if operation == ALOperation.STOP_VIRTUAL_MACHINE:
            need_status = EStatus.STOPPED
        check_experiment_done(experiment_id, need_status)
Exemplo n.º 12
0
def commit_azure_log(experiment_id, operation, status, note=None, code=None):
    db_adapter.add_object_kwargs(AzureLog,
                                 experiment_id=experiment_id,
                                 operation=operation,
                                 status=status,
                                 note=note,
                                 code=code)
    db_adapter.commit()
    if status == ALStatus.FAIL:
        update_experiment_status(experiment_id, EStatus.FAILED)
    elif status == ALStatus.END:
        need_status = EStatus.RUNNING
        if operation == ALOperation.STOP_VIRTUAL_MACHINE:
            need_status = EStatus.STOPPED
        check_experiment_done(experiment_id, need_status)
Exemplo n.º 13
0
def commit_azure_virtual_machine(
    name,
    label,
    status,
    dns,
    public_ip,
    private_ip,
    cloud_service_name,
    deployment_name,
    experiment_id,
    virtual_environment,
):
    cs = db_adapter.find_first_object_by(AzureCloudService, name=cloud_service_name)
    dm = db_adapter.find_first_object_by(AzureDeployment, name=deployment_name, cloud_service=cs)
    vm = db_adapter.add_object_kwargs(
        AzureVirtualMachine,
        name=name,
        label=label,
        status=status,
        dns=dns,
        public_ip=public_ip,
        private_ip=private_ip,
        deployment=dm,
        experiment_id=experiment_id,
        virtual_environment=virtual_environment,
    )
    db_adapter.commit()
    return vm
Exemplo n.º 14
0
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 db : add a super admin account
    superadmin = db_adapter.find_first_object_by(AdminUserHackathonRel,
                                                 admin_email=ADMIN.DEFAULT_SUPER_ADMIN_EMAIL,
                                                 hackathon_id=ADMIN.SUPER_ADMIN_GROUP_ID)
    if superadmin is None:
        db_adapter.add_object_kwargs(AdminUserHackathonRel,
                                     admin_email=ADMIN.DEFAULT_SUPER_ADMIN_EMAIL,
                                     hackathon_id=ADMIN.SUPER_ADMIN_GROUP_ID,
                                     state=AdminUserHackathonRelStates.Actived,
                                     remarks='super admins',
                                     create_time=datetime.utcnow())
        db_adapter.commit()
Exemplo n.º 15
0
def commit_virtual_environment(provider, name, image, status, remote_provider, remote_paras, experiment_id):
    ve = db_adapter.add_object_kwargs(VirtualEnvironment,
                                      provider=provider,
                                      name=name,
                                      image=image,
                                      status=status,
                                      remote_provider=remote_provider,
                                      remote_paras=remote_paras,
                                      experiment_id=experiment_id)
    db_adapter.commit()
    return ve
Exemplo n.º 16
0
def commit_virtual_environment(provider, name, image, status, remote_provider, remote_paras, experiment_id):
    ve = db_adapter.add_object_kwargs(VirtualEnvironment,
                                      provider=provider,
                                      name=name,
                                      image=image,
                                      status=status,
                                      remote_provider=remote_provider,
                                      remote_paras=remote_paras,
                                      experiment_id=experiment_id)
    db_adapter.commit()
    return ve
Exemplo n.º 17
0
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 db : add a super admin account
    superadmin = db_adapter.find_first_object_by(
        AdminUserHackathonRel,
        admin_email=ADMIN.DEFAULT_SUPER_ADMIN_EMAIL,
        hackathon_id=ADMIN.SUPER_ADMIN_GROUP_ID)
    if superadmin is None:
        db_adapter.add_object_kwargs(
            AdminUserHackathonRel,
            admin_email=ADMIN.DEFAULT_SUPER_ADMIN_EMAIL,
            hackathon_id=ADMIN.SUPER_ADMIN_GROUP_ID,
            state=AdminUserHackathonRelStates.Actived,
            remarks='super admins',
            create_time=datetime.utcnow())
        db_adapter.commit()
Exemplo n.º 18
0
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)
Exemplo n.º 19
0
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)
Exemplo n.º 20
0
def commit_azure_virtual_machine(name, label, status, dns, public_ip, private_ip,
                                 cloud_service_name, deployment_name, experiment_id, virtual_environment):
    cs = db_adapter.find_first_object_by(AzureCloudService, name=cloud_service_name)
    dm = db_adapter.find_first_object_by(AzureDeployment, name=deployment_name, cloud_service=cs)
    vm = db_adapter.add_object_kwargs(AzureVirtualMachine,
                                      name=name,
                                      label=label,
                                      status=status,
                                      dns=dns,
                                      public_ip=public_ip,
                                      private_ip=private_ip,
                                      deployment=dm,
                                      experiment_id=experiment_id,
                                      virtual_environment=virtual_environment)
    db_adapter.commit()
    return vm