Пример #1
0
def create_remote_control_handler():

    operation_type = u'remote_control'

    form = CreatePowerCtrlForm()

    if form.validate_on_submit():

        author = current_user.id

        fruit = format_address_list(form.server_list.data)
        if fruit['status'] is not True:
            flash(fruit['desc'], 'error')
            return redirect(url_for('operation.create_remote_control_handler'))

        operation = OperationDb(author, operation_type, fruit['servers'],
                                form.script_template.data, u'', form.ipmi_config.data.id, 0, u'')
        db.session.add(operation)
        db.session.commit()

        ipmi_config = IpmiConfig.query.filter_by(id=form.ipmi_config.data.id).first()
        ipmi_config_dict = get_obj_attributes(ipmi_config, 'IPMI')
        operations = get_obj_attributes(operation, 'OPT')
        operations.update(ipmi_config_dict)

        print operations

        q.enqueue(backend_runner, operations, get_dict_items(current_app.config, 'SETTINGS'))

        flash(u'Creating operation successfully', 'success')
        return redirect(url_for('operation.list_operation_handler'))

    else:
        return render_template('operation/create_power_control.html', form=form)
Пример #2
0
def create_ping_connectivity_detecting_handler():

    operation_type = u'ping_connectivity_detecting'

    form = CreatePingDetectForm()

    if form.validate_on_submit():

        author = current_user.id

        fruit = format_address_list(form.server_list.data)
        if fruit['status'] is not True:
            flash(fruit['desc'], 'error')
            return redirect(url_for('operation.create_ping_connectivity_detecting_handler'))

        operation = OperationDb(author, operation_type, fruit['servers'], u'', u'', 0, 0, u'')
        db.session.add(operation)
        db.session.commit()

        q.enqueue(backend_runner, get_obj_attributes(operation, 'OPT'), get_dict_items(current_app.config, 'SETTINGS'))

        flash(u'Creating operation successfully', 'success')
        return redirect(url_for('operation.list_operation_handler'))

    else:
        return render_template('operation/create_ping_detecting.html', form=form)
Пример #3
0
def create_ssh_status_detecting_handler():

    operation_type = u'ssh_status_detecting'

    form = CreateSshDetectForm()

    if form.validate_on_submit():

        author = current_user.id

        fruit = format_address_list(form.server_list.data)
        if fruit['status'] is not True:
            flash(fruit['desc'], 'error')
            return redirect(url_for('operation.create_ssh_status_detecting_handler'))

        operation = OperationDb(author, operation_type, fruit['servers'], u'', u'', form.ssh_config.data.id, 0, u'')
        db.session.add(operation)
        db.session.commit()

        ssh_config = SshConfig.query.filter_by(id=form.ssh_config.data.id).first()
        ssh_config_dict = get_obj_attributes(ssh_config, 'SSH')

        operations = get_obj_attributes(operation, 'OPT')
        operations.update(ssh_config_dict)

        q.enqueue(backend_runner, operations, get_dict_items(current_app.config, 'SETTINGS'))

        flash(u'Creating operation successfully', 'success')
        return redirect(url_for('operation.list_operation_handler'))

    else:
        return render_template('operation/create_ssh_detecting.html', form=form)
Пример #4
0
def create_fabfile_execute_handler():

    operation_type = u'fabfile_execute'

    form = CreateFabfileExecuteForm()

    if form.validate_on_submit():

        author = current_user.id

        fruit = format_address_list(form.server_list.data)
        if fruit['status'] is not True:
            flash(fruit['desc'], 'error')
            return redirect(url_for('operation.create_fabfile_execute_handler'))

        ext_variables_dict = format_ext_variables(form.ext_variables.data)
        if ext_variables_dict['status'] is not True:
            flash(ext_variables_dict['desc'], 'error')
            return redirect(url_for('operation.create_fabfile_execute_handler'))
        ext_variables = json.dumps(ext_variables_dict['vars'], ensure_ascii=False)

        operation = OperationDb(author, operation_type, fruit['servers'], form.script_template.data.id,
                                ext_variables, form.ssh_config.data.id, 0, u'')
        db.session.add(operation)
        db.session.commit()

        ssh_config = SshConfig.query.filter_by(id=form.ssh_config.data.id).first()
        ssh_config_dict = get_obj_attributes(ssh_config, 'SSH')
        fabfile = FabFile.query.filter_by(id=form.script_template.data.id).first()
        fabfile_dict = get_obj_attributes(fabfile, 'FABFILE')

        operations = get_obj_attributes(operation, 'OPT')
        operations.update(ssh_config_dict)
        operations.update(fabfile_dict)

        q.enqueue(backend_runner, operations, get_dict_items(current_app.config, 'SETTINGS'))

        flash(u'Creating operation successfully', 'success')
        return redirect(url_for('operation.list_operation_handler'))

    else:
        return render_template('operation/create_fabfile_execute.html', form=form)