Beispiel #1
0
def create_hostaclip(session):
    ''' Create some HostAclIp to play with for the tests
    '''
    item = model.HostAclIp(
        ip='85.12.0.250',
        host_id=1,
    )
    session.add(item)

    item = model.HostAclIp(
        ip='192.168.0.12',
        host_id=2,
    )
    session.add(item)

    session.commit()
Beispiel #2
0
def host_acl_ip_new(host_id):
    """ Create a new host_acl_ip.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    form = forms.AddHostAclIpForm()
    if form.validate_on_submit():
        host_acl = model.HostAclIp()
        SESSION.add(host_acl)
        host_acl.host_id = hostobj.id
        form.populate_obj(obj=host_acl)

        try:
            SESSION.flush()
            flask.flash('Host ACL IP added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not add ACL IP to the host')
            APP.logger.debug('Could not add ACL IP 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_acl_ip_new.html',
        form=form,
        host=hostobj,
    )