Esempio n. 1
0
def edit_ipmi_config_handler(config_id):

    config = IpmiConfig.query.filter_by(id=config_id).first()

    form = IpmiConfigForm(id=config.id, name=config.name, desc=config.desc, groups=config.groups,
                          username=config.username, interface=True if config.interface else False)

    if request.method == 'POST' and form.validate():

        if form.name.data != config.name:
            config.name = form.name.data

        if form.desc.data != config.desc:
            config.desc = form.desc.data

        config.set_groups(form.groups.data)

        if form.username.data != config.username:
            config.username = form.username.data

        if form.password.data != config.password:
            config.password = form.password.data

        if form.interface.data or config.interface:
            config.interface = 1 if form.interface.data else 0

        db.session.commit()

        flash(u'Edit IPMI configuration successfully', 'success')
        return redirect(url_for('dashboard.list_ipmi_config_handler'))

    else:
        return render_template('dashboard/ipmi_config.html', form=form, action='edit')
Esempio n. 2
0
def create_ipmi_config_handler():

    form = IpmiConfigForm()

    if request.method == 'POST' and form.validate():

        ipmi_config = IpmiConfig(form.username.data, form.desc.data, current_user.id, form.groups.data,
                                 form.username.data, form.password.data, 1 if form.interface.data else 0)
        db.session.add(ipmi_config)
        db.session.commit()

        flash(u'Creating IPMI configuration successfully', 'success')

        return redirect(url_for('dashboard.list_ipmi_config_handler'))

    else:
        return render_template('dashboard/ipmi_config.html', form=form, action='create')
Esempio n. 3
0
def edit_ipmi_config_handler(config_id):

    config = IpmiConfig.query.filter_by(id=config_id).first()

    if config.author_id != current_user.id:
        flash(u'Don\'t have permission to access this link', 'error')
        return redirect(url_for('account.index_handler'))

    form = IpmiConfigForm(id=config.id,
                          name=config.name,
                          desc=config.desc,
                          username=config.username,
                          groups=config.groups,
                          interface=True if config.interface else False)

    if request.method == 'POST' and form.validate():

        if form.name.data != config.name:
            config.name = form.name.data

        if form.desc.data != config.desc:
            config.desc = form.desc.data

        config.set_groups(form.groups.data)

        if form.username.data != config.username:
            config.username = form.username.data

        if form.password.data != config.password:
            config.password = form.password.data

        if form.interface.data or config.interface:
            config.interface = 1 if form.interface.data else 0

        db.session.commit()

        flash(u'Edit IPMI configuration successfully', 'success')
        return redirect(url_for('account.list_ipmi_config_handler'))

    else:
        return render_template('account/ipmi_config.html',
                               form=form,
                               action='edit')
Esempio n. 4
0
def create_ipmi_config_handler():

    form = IpmiConfigForm()

    if request.method == 'POST' and form.validate():

        ipmi_config = IpmiConfig(form.username.data, form.desc.data,
                                 current_user.id, form.groups.data,
                                 form.username.data, form.password.data,
                                 1 if form.interface.data else 0)
        db.session.add(ipmi_config)
        db.session.commit()

        flash(u'Creating IPMI configuration successfully', 'success')

        return redirect(url_for('account.list_ipmi_config_handler'))

    else:
        return render_template('account/ipmi_config.html',
                               form=form,
                               action='create')