コード例 #1
0
ファイル: __init__.py プロジェクト: yumsuresht/mirrormanager2
def host_netblock_new(host_id):
    """ Create a new host_netblock.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

    if hostobj is None:
        flask.abort(404, 'Host not found')

    form = forms.AddHostNetblockForm()
    if form.validate_on_submit():
        host_netblock = model.HostNetblock()
        SESSION.add(host_netblock)
        host_netblock.host_id = hostobj.id
        form.populate_obj(obj=host_netblock)

        try:
            SESSION.flush()
            flask.flash('Host netblock added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not add netblock to the host')
            APP.logger.debug('Could not add netblock to the host')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('host_view', host_id=host_id))

    return flask.render_template(
        'host_netblock_new.html',
        form=form,
        host=hostobj,
    )
コード例 #2
0
ファイル: app.py プロジェクト: kushal124/mirrormanager2
def host_netblock_new(host_id):
    """ Create a new host_netblock.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

    if hostobj is None:
        flask.abort(404, 'Host not found')

    form = forms.AddHostNetblockForm()
    if form.validate_on_submit():
        host_netblock = model.HostNetblock()
        SESSION.add(host_netblock)
        host_netblock.host_id = hostobj.id
        form.populate_obj(obj=host_netblock)

        try:
            SESSION.flush()
            flask.flash('Host netblock added')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this as there is no unique constraint in the
            # table. So the only situation where it could fail is a failure
            # at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not add netblock to the host')
            APP.logger.debug('Could not add netblock to the host')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('host_view', host_id=host_id))

    return flask.render_template(
        'host_netblock_new.html',
        form=form,
        host=hostobj,
    )