Пример #1
0
def host_asn_new(host_id):
    """ Create a new host_peer_asn.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    form = forms.AddHostAsnForm()
    if form.validate_on_submit():
        host_asn = model.HostPeerAsn()
        SESSION.add(host_asn)
        host_asn.host_id = hostobj.id
        form.populate_obj(obj=host_asn)
        host_asn.asn = int(host_asn.asn)

        try:
            SESSION.flush()
            flask.flash('Host Peer ASN added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not add Peer ASN to the host')
            APP.logger.debug('Could not add Peer ASN 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_asn_new.html',
        form=form,
        host=hostobj,
    )
Пример #2
0
def create_hostpeerasn(session):
    ''' Create some HostPeerAsn to play with for the tests
    '''
    item = model.HostPeerAsn(
        host_id=3,
        asn='25640',
        name='Hawaii',
    )
    session.add(item)

    session.commit()
Пример #3
0
def host_asn_new(host_id):
    """ Create a new host_peer_asn.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    if not (is_site_admin(flask.g.fas_user, hostobj.site)
            or is_mirrormanager_admin(flask.g.fas_user)):
        flask.abort(403, 'Access denied')

    form = forms.AddHostAsnForm()
    if form.validate_on_submit():
        host_asn = model.HostPeerAsn()
        SESSION.add(host_asn)
        host_asn.host_id = hostobj.id
        form.populate_obj(obj=host_asn)
        host_asn.asn = int(host_asn.asn)

        try:
            SESSION.flush()
            flask.flash('Host Peer ASN 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 Peer ASN to the host')
            APP.logger.debug('Could not add Peer ASN 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_asn_new.html',
        form=form,
        host=hostobj,
    )