Exemplo n.º 1
0
def get_environment_node(server_id, environment_type):
    environment = None
    if server_id is not None and environment_type is not None:
        environment = Environment()
        environment.server = server_id
        environment.type = environment_type
    return environment
Exemplo n.º 2
0
            def post(self, project_uuid, environment_uuid):

                # create a new environment in the project
                environment_json = request.json.get("environment")

                e = Environment(
                    uuid=str(uuid.uuid4()),
                    name=environment_json["name"],
                    project_uuid=project_uuid,
                    language=environment_json["language"],
                    setup_script=environment_json["setup_script"],
                    base_image=environment_json["base_image"],
                    gpu_support=environment_json["gpu_support"],
                )

                # use specified uuid if it's not keyword 'new'
                if environment_uuid != "new":
                    e.uuid = environment_uuid

                environment_dir = get_environment_directory(
                    e.uuid, project_uuid)

                os.makedirs(environment_dir, exist_ok=True)
                serialize_environment_to_disk(e, environment_dir)

                # refresh kernels after change in environments
                populate_kernels(app, db, project_uuid)

                return environment_schema.dump(e)
Exemplo n.º 3
0
def populate_default_environments(project_uuid):

    for env_spec in current_app.config["DEFAULT_ENVIRONMENTS"]:
        e = Environment(**env_spec)

        e.uuid = str(uuid.uuid4())
        e.project_uuid = project_uuid

        environment_dir = get_environment_directory(e.uuid, project_uuid)
        os.makedirs(environment_dir, exist_ok=True)

        serialize_environment_to_disk(e, environment_dir)
Exemplo n.º 4
0
def environment_add():
    form = EnvironmentFrom()
    if form.validate_on_submit():
        data = form.data
        smtp = str({
            'mail_host': data["mail_host"],
            'mail_user': data["mail_user"],
            'mail_pass': data["mail_pass"],
            'From': data["FromUser"],
            'To': data["ToUser"],
            'subject': data["subject"],
            'MIMEText': data["MIMEText"]
        })
        if Environment.query.filter_by(name=data['name']).count() == 1:
            flash('环境名称已存在!', category='err')
            return redirect(url_for('admin.environment_add'))
        environment = Environment(name=data["name"],
                                  version=data["version"],
                                  project_url=data["project_url"],
                                  smtp=smtp,
                                  dbconfig=data["dbconfig"],
                                  user_id=session["admin"],
                                  comment=data["comment"],
                                  status=0)
        db.session.add(environment)
        db.session.commit()
        flash("添加环境成功!", "ok")
        oplog = Oplog(admin_id=session["admin_id"],
                      ip=request.remote_addr,
                      reason="添加环境:%s" % data['name'])
        db.session.add(oplog)
        db.session.commit()
    return render_template("admin/environment_add.html", form=form)
Exemplo n.º 5
0
def read_environment_from_disk(env_directory):

    try:
        with open(os.path.join(env_directory, "properties.json"), "r") as file:
            env_dat = json.load(file)

        with open(os.path.join(env_directory, "startup_script.sh"),
                  "r") as file:
            startup_script = file.read()

        e = Environment(**env_dat)
        e.startup_script = startup_script

        return e
    except Exception as e:
        logging.error(
            "Could not environment from env_directory %s. Error: %s" %
            (env_directory, e))
Exemplo n.º 6
0
def environment_insert_data():
    environments = {
        u'bd-blink-server': (Module.query.filter_by(name=u"bd-blink-server").first(), 'PRD',
                             Idc.query.filter_by(name=u'周浦').first(), "http://www.blink.com/status",
                             "/opt/app/bd-blink-server/", "www.blink.com"),

        u'bd-tiger-web': (Module.query.filter_by(name=u"bd-tiger-web").first(), 'PRD',
                          Idc.query.filter_by(name=u'周浦').first(), "http://www.tiger.com/status",
                          "/opt/app/bd-tiger-web/", "www.tiger.com"),

        u'bd-cmdb': (Module.query.filter_by(name=u"bd-cmdb").first(), 'PRD',
                     Idc.query.filter_by(name=u'周浦').first(), "http://www.cmdb.com/status",
                     "/opt/app/bd-cmdb/", "www.cmdb.com"),

        u'bd-bdmp': (Module.query.filter_by(name=u"bd-bdmp").first(), 'PRD',
                     Idc.query.filter_by(name=u'周浦').first(), "http://www.bdmp.com/status",
                     "/opt/app/bd-bdmp/", "www.bdmp.com"),

        u'bd-test': (Module.query.filter_by(name=u"bd-test").first(), 'DEV',
                     Idc.query.filter_by(name=u'周浦').first(), "http://www.test.com/status",
                     "/opt/app/bd-test/", "www.test.com"),

        u'bd-test2': (Module.query.filter_by(name=u"bd-test2").first(), 'DEV',
                     Idc.query.filter_by(name=u'周浦').first(), "http://www.test2.com/status",
                     "/opt/app/bd-test2/", "www.test2.com"),

        u'bd-test3': (Module.query.filter_by(name=u"bd-test3").first(), 'DEV',
                     Idc.query.filter_by(name=u'周浦').first(), "http://www.test3.com/status",
                     "/opt/app/bd-test3/", "www.test3.com"),

        u'bd-jenkins': (Module.query.filter_by(name=u"bd-jenkins").first(), 'QA',
                     Idc.query.filter_by(name=u'周浦').first(), "http://www.jenkins.com/status",
                     "/opt/app/bd-jenkins/", "www.jenkins.com"),

        u'bd-qa': (Module.query.filter_by(name=u"bd-qa").first(), 'QA',
                     Idc.query.filter_by(name=u'周浦').first(), "http://www.qa.com/status",
                     "/opt/app/bd-qa/", "www.qa.com"),

        u'bd-oracle': (Module.query.filter_by(name=u"bd-oracle").first(), 'STG',
                     Idc.query.filter_by(name=u'周浦').first(), "http://www.oracle.com/status",
                     "/opt/app/bd-oracle/", "www.oracle.com"),

        u'bd-mongodb': (Module.query.filter_by(name=u"bd-mongodb").first(),  'STG',
                     Idc.query.filter_by(name=u'周浦').first(), "http://www.mongodb.com/status",
                     "/opt/app/bd-mongodb/", "www.mongodb.com"),
    }
    for e in environments:
        environment = Environment(
            module=environments[e][0],
            env=environments[e][1],
            idc=environments[e][2],
            check_point1=environments[e][3],
            deploy_path=environments[e][4],
            domain=environments[e][5])
        db.session.add(environment)
        db.session.commit()
    print "Insert environment test data."
Exemplo n.º 7
0
def read_environment_from_disk(env_directory,
                               project_uuid) -> Optional[Environment]:

    try:
        with open(safe_join(env_directory, "properties.json"), "r") as file:
            env_dat = json.load(file)

        with open(safe_join(env_directory, _config.ENV_SETUP_SCRIPT_FILE_NAME),
                  "r") as file:
            setup_script = file.read()

        e = Environment(**env_dat)
        e.project_uuid = project_uuid
        e.setup_script = setup_script

        return e
    except Exception as e:
        current_app.logger.error(
            "Could not get environment from env_directory %s. Error: %s" %
            (env_directory, e))
Exemplo n.º 8
0
def index():
    form = EnvironmentForm()
    environments = Environment.query.order_by(Environment.id.desc()).all()

    env = Environment()
    columns = env.serialize_columns()

    envs = []
    for e in environments:
        envs.append(e.as_dict())

    base_url = url_for('environment.index')
    action_url = url_for('environment.add')
    return render_template('environment.html',
                           title='Environments',
                           rows=envs,
                           columns=columns,
                           base_url=base_url,
                           action_url=action_url,
                           per_page=current_app.config['ROWS_PER_PAGE'],
                           form=form)
Exemplo n.º 9
0
def add():
    form = EnvironmentForm()
    if form.validate_on_submit():
        environment_active = form.active.data
        environment_name = re.sub('[^A-Za-z0-9_]+', '', form.envname.data)

        environment = Environment(name=environment_name,
                                  active=environment_active)

        db.session.add(environment)
        db.session.commit()

    return redirect(url_for('environment.index'))
Exemplo n.º 10
0
            def post(self, project_uuid, environment_uuid):

                # create a new environment in the project
                environment_json = request.json.get("environment")

                e = Environment(
                    uuid=str(uuid.uuid4()),
                    name=environment_json["name"],
                    project_uuid=project_uuid,
                    language=environment_json["language"],
                    setup_script=preprocess_script(
                        environment_json["setup_script"]),
                    base_image=environment_json["base_image"],
                    gpu_support=environment_json["gpu_support"],
                )

                # use specified uuid if it's not keyword 'new'
                if environment_uuid != "new":
                    e.uuid = environment_uuid
                else:
                    url = (f'http://{app.config["ORCHEST_API_ADDRESS"]}'
                           f"/api/environments/{project_uuid}")
                    resp = requests.post(url, json={"uuid": e.uuid})
                    if resp.status_code != 201:
                        return {}, resp.status_code, resp.headers.items()

                environment_dir = get_environment_directory(
                    e.uuid, project_uuid)

                os.makedirs(environment_dir, exist_ok=True)
                serialize_environment_to_disk(e, environment_dir)

                # refresh kernels after change in environments
                populate_kernels(app, db, project_uuid)

                return environment_schema.dump(e)
Exemplo n.º 11
0
def averageEnvironmentData():
    gyro_x = 0
    gyro_y = 0
    gyro_z = 0
    sensor_temp = 0
    room_temp = 0
    compass_x = 0
    compass_y = 0
    compass_z = 0
    accel_x = 0
    accel_y = 0
    accel_z = 0
    air_pressure = 0
    light = 0

    data = Environment.query.order_by(-Environment.id.desc()).limit(10)
    for environment in data:
        gyro_x += environment.gyro_x
        gyro_y += environment.gyro_y
        gyro_z += environment.gyro_z
        sensor_temp += environment.sensor_temp
        room_temp += environment.room_temp
        compass_x += environment.compass_x
        compass_y += environment.compass_y
        compass_z += environment.compass_z
        accel_x += environment.accel_x
        accel_y += environment.accel_y
        air_pressure += environment.air_pressure
        light += environment.light

    return Environment(gyro_x=gyro_x / 10,
                       gyro_y=gyro_y / 10,
                       gyro_z=gyro_z / 10,
                       sensor_temp=sensor_temp / 10,
                       room_temp=room_temp / 10,
                       compass_x=compass_x / 10,
                       compass_y=compass_y / 10,
                       compass_z=compass_z / 10,
                       accel_x=accel_x / 10,
                       accel_y=accel_y / 10,
                       accel_z=accel_z / 10,
                       air_pressure=air_pressure / 10,
                       light=light / 10)
Exemplo n.º 12
0
def environments(id):
    """
    Load and adds Environments for a specified ID
    :param id: Environment ID
    :return: renders environments template
    """
    user = User.query.filter_by(id=id).first_or_404()
    environments = Environment.query.filter_by(user_id_fk=id).all()
    form = EnvironmentForm()
    if form.validate_on_submit():
        environment = Environment(name=form.name.data,
                                  timing=form.timing.data,
                                  user_id_fk=id)
        db.session.add(environment)
        db.session.commit()
        flash('Congratulations, your environment has been added!')
        return redirect(url_for('environments', id=id))
    return render_template('environments.html',
                           user=user,
                           environments=environments,
                           form=form)