Exemplo n.º 1
0
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,
    )
Exemplo n.º 2
0
def host_view(host_id):
    """ Create a new host.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    form = forms.AddHostForm(obj=hostobj)
    if form.validate_on_submit():
        form.populate_obj(obj=hostobj)
        hostobj.bandwidth_int = int(hostobj.bandwidth_int)
        hostobj.asn = None if not hostobj.asn else int(hostobj.asn)

        try:
            SESSION.flush()
            flask.flash('Host updated')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code updates data therefore
            # the only situation where it could fail is a failure at the
            # DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update the host')
            APP.logger.debug('Could not update 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.html',
        form=form,
        host=hostobj,
    )
Exemplo n.º 3
0
def host_drop(host_id):
    """ Drop a given site.
    """
    topic = 'host.deleted'
    hostobj = mmlib.get_host(SESSION, host_id)

    if hostobj is None:
        flask.abort(404, 'Site 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')

    site_id = hostobj.site.id
    form = forms.ConfirmationForm()
    if form.validate_on_submit():
        message = dict(site_id=hostobj.site_id,
                       host_id=host_id,
                       bandwidth=hostobj.bandwidth_int,
                       asn=hostobj.asn)

        SESSION.delete(hostobj)
        try:
            SESSION.commit()
            flask.flash('Host dropped')
            fedmsg_publish(topic, message)
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not delete this host')
            APP.logger.debug('Could not delete this host')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('site_view', site_id=site_id))
Exemplo n.º 4
0
def host_asn_delete(host_id, host_asn_id):
    """ Delete a host_peer_asn.
    """
    form = forms.ConfirmationForm()
    if form.validate_on_submit():
        hostobj = mmlib.get_host(SESSION, host_id)

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

        hostasnobj = mmlib.get_host_peer_asn(SESSION, host_asn_id)

        if hostasnobj is None:
            flask.abort(404, 'Host Peer ASN not found')
        else:
            SESSION.delete(hostasnobj)

        try:
            SESSION.commit()
            flask.flash('Host Peer ASN deleted')
        except SQLAlchemyError as err:  # pragma: no cover
            # We check everything before deleting so the only error we could
            # run in is DB server related, and that we can't fake in our
            # tests
            SESSION.rollback()
            flask.flash('Could not delete Peer ASN of the host')
            APP.logger.debug('Could not delete Peer ASN of the host')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('host_view', host_id=host_id))
Exemplo n.º 5
0
def host_category_delete(host_id, hc_id):
    """ Delete a host_category.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')
    else:
        for url in hcobj.urls:
            SESSION.delete(url)
        for dirs in hcobj.dirs:
            SESSION.delete(dirs)
        SESSION.delete(hcobj)

    try:
        SESSION.commit()
        flask.flash('Host Category deleted')
    except SQLAlchemyError as err:
        SESSION.rollback()
        flask.flash('Could not delete Category of the host')
        APP.logger.debug('Could not delete Category of the host')
        APP.logger.exception(err)

    return flask.redirect(flask.url_for('host_view', host_id=host_id))
Exemplo n.º 6
0
def host_category_url_delete(host_id, hc_id, host_category_url_id):
    """ Delete a host_category_url.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    hostcaturlobj = mmlib.get_host_category_url(SESSION, host_category_url_id)

    if hostcaturlobj is None:
        flask.abort(404, 'Host category URL not found')
    else:
        SESSION.delete(hostcaturlobj)

    try:
        SESSION.commit()
        flask.flash('Host category URL deleted')
    except SQLAlchemyError as err:
        SESSION.rollback()
        flask.flash('Could not delete category URL of the host')
        APP.logger.debug('Could not delete category URL of the host')
        APP.logger.exception(err)

    return flask.redirect(
        flask.url_for('host_category', host_id=hostobj.id, hc_id=hcobj.id))
Exemplo n.º 7
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,
    )
Exemplo n.º 8
0
def host_asn_delete(host_id, host_asn_id):
    """ Delete a host_peer_asn.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hostasnobj = mmlib.get_host_peer_asn(SESSION, host_asn_id)

    if hostasnobj is None:
        flask.abort(404, 'Host Peer ASN not found')
    else:
        SESSION.delete(hostasnobj)

    try:
        SESSION.commit()
        flask.flash('Host Peer ASN deleted')
    except SQLAlchemyError as err:
        SESSION.rollback()
        flask.flash('Could not delete Peer ASN of the host')
        APP.logger.debug('Could not delete Peer ASN of the host')
        APP.logger.exception(err)

    return flask.redirect(flask.url_for('host_view', host_id=host_id))
Exemplo n.º 9
0
def host_acl_ip_delete(host_id, host_acl_ip_id):
    """ Delete a host_acl_ip.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hostaclobj = mmlib.get_host_acl_ip(SESSION, host_acl_ip_id)

    if hostaclobj is None:
        flask.abort(404, 'Host ACL IP not found')
    else:
        SESSION.delete(hostaclobj)
    try:
        SESSION.flush()
        flask.flash('Host ACL IP deleted')
    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))
Exemplo n.º 10
0
def host_category_url_delete(host_id, hc_id, host_category_url_id):
    """ Delete a host_category_url.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    hostcaturlobj = mmlib.get_host_category_url(SESSION, host_category_url_id)

    if hostcaturlobj is None:
        flask.abort(404, 'Host category URL not found')
    else:
        SESSION.delete(hostcaturlobj)

    try:
        SESSION.commit()
        flask.flash('Host category URL deleted')
    except SQLAlchemyError as err:
        SESSION.rollback()
        flask.flash('Could not delete category URL of the host')
        APP.logger.debug('Could not delete category URL of the host')
        APP.logger.exception(err)

    return flask.redirect(
        flask.url_for('host_category', host_id=hostobj.id, hc_id=hcobj.id))
Exemplo n.º 11
0
def host_country_delete(host_id, host_country_id):
    """ Delete a host_country.
    """
    form = forms.ConfirmationForm()
    if form.validate_on_submit():
        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')

        hostcntobj = mmlib.get_host_country(SESSION, host_country_id)

        if hostcntobj is None:
            flask.abort(404, 'Host Country not found')
        else:
            SESSION.delete(hostcntobj)

        try:
            SESSION.commit()
            flask.flash('Host Country deleted')
        except SQLAlchemyError as err:  # pragma: no cover
            # We check everything before deleting so the only error we could
            # run in is DB server related, and that we can't fake in our
            # tests
            SESSION.rollback()
            flask.flash('Could not delete Country of the host')
            APP.logger.debug('Could not delete Country of the host')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('host_view', host_id=host_id))
Exemplo n.º 12
0
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,
    )
Exemplo n.º 13
0
def host_drop(host_id):
    """ Drop a given site.
    """
    topic = 'host.deleted'
    hostobj = mmlib.get_host(SESSION, host_id)

    if hostobj is None:
        flask.abort(404, 'Site 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')

    site_id = hostobj.site.id
    form = forms.ConfirmationForm()
    if form.validate_on_submit():
        message = dict(
            site_id=hostobj.site_id,
            host_id=host_id,
            bandwidth=hostobj.bandwidth_int,
            asn=hostobj.asn)

        SESSION.delete(hostobj)
        try:
            SESSION.commit()
            flask.flash('Host dropped')
            fedmsg_publish(topic, message)
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not delete this host')
            APP.logger.debug('Could not delete this host')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('site_view', site_id=site_id))
Exemplo n.º 14
0
def host_category_delete(host_id, hc_id):
    """ Delete a host_category.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')
    else:
        for url in hcobj.urls:
            SESSION.delete(url)
        for dirs in hcobj.dirs:
            SESSION.delete(dirs)
        SESSION.delete(hcobj)

    try:
        SESSION.commit()
        flask.flash('Host Category deleted')
    except SQLAlchemyError as err:
        SESSION.rollback()
        flask.flash('Could not delete Category of the host')
        APP.logger.debug('Could not delete Category of the host')
        APP.logger.exception(err)

    return flask.redirect(flask.url_for('host_view', host_id=host_id))
Exemplo n.º 15
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,
    )
Exemplo n.º 16
0
def host_asn_delete(host_id, host_asn_id):
    """ Delete a host_peer_asn.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hostasnobj = mmlib.get_host_peer_asn(SESSION, host_asn_id)

    if hostasnobj is None:
        flask.abort(404, 'Host Peer ASN not found')
    else:
        SESSION.delete(hostasnobj)

    try:
        SESSION.commit()
        flask.flash('Host Peer ASN deleted')
    except SQLAlchemyError as err:
        SESSION.rollback()
        flask.flash('Could not delete Peer ASN of the host')
        APP.logger.debug('Could not delete Peer ASN of the host')
        APP.logger.exception(err)

    return flask.redirect(flask.url_for('host_view', host_id=host_id))
Exemplo n.º 17
0
def host_view(host_id):
    """ Create a new host.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    form = forms.AddHostForm(obj=hostobj)
    if form.validate_on_submit():
        form.populate_obj(obj=host)
        host.bandwidth_int = int(host.bandwidth_int)
        host.asn = None if not host.asn else int(host.asn)

        try:
            SESSION.flush()
            flask.flash('Host updated')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not update the host')
            APP.logger.debug('Could not update 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.html',
        form=form,
        host=hostobj,
    )
Exemplo n.º 18
0
def host_acl_ip_delete(host_id, host_acl_ip_id):
    """ Delete a host_acl_ip.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hostaclobj = mmlib.get_host_acl_ip(SESSION, host_acl_ip_id)

    if hostaclobj is None:
        flask.abort(404, 'Host ACL IP not found')
    else:
        SESSION.delete(hostaclobj)
    try:
        SESSION.flush()
        flask.flash('Host ACL IP deleted')
    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))
Exemplo n.º 19
0
def host_view(host_id):
    """ Create a new host.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    form = forms.AddHostForm(obj=hostobj)
    if form.validate_on_submit():
        form.populate_obj(obj=host)
        host.bandwidth_int = int(host.bandwidth_int)
        host.asn = None if not host.asn else int(host.asn)

        try:
            SESSION.flush()
            flask.flash('Host updated')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not update the host')
            APP.logger.debug('Could not update 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.html',
        form=form,
        host=hostobj,
    )
Exemplo n.º 20
0
def host_asn_delete(host_id, host_asn_id):
    """ Delete a host_peer_asn.
    """
    form = forms.ConfirmationForm()
    if form.validate_on_submit():
        hostobj = mmlib.get_host(SESSION, host_id)

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

        hostasnobj = mmlib.get_host_peer_asn(SESSION, host_asn_id)

        if hostasnobj is None:
            flask.abort(404, 'Host Peer ASN not found')
        else:
            SESSION.delete(hostasnobj)

        try:
            SESSION.commit()
            flask.flash('Host Peer ASN deleted')
        except SQLAlchemyError as err:  # pragma: no cover
            # We check everything before deleting so the only error we could
            # run in is DB server related, and that we can't fake in our
            # tests
            SESSION.rollback()
            flask.flash('Could not delete Peer ASN of the host')
            APP.logger.debug('Could not delete Peer ASN of the host')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('host_view', host_id=host_id))
Exemplo n.º 21
0
def host_country_delete(host_id, host_country_id):
    """ Delete a host_country.
    """
    form = forms.ConfirmationForm()
    if form.validate_on_submit():
        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')

        hostcntobj = mmlib.get_host_country(SESSION, host_country_id)

        if hostcntobj is None:
            flask.abort(404, 'Host Country not found')
        else:
            SESSION.delete(hostcntobj)

        try:
            SESSION.commit()
            flask.flash('Host Country deleted')
        except SQLAlchemyError as err:  # pragma: no cover
            # We check everything before deleting so the only error we could
            # run in is DB server related, and that we can't fake in our
            # tests
            SESSION.rollback()
            flask.flash('Could not delete Country of the host')
            APP.logger.debug('Could not delete Country of the host')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('host_view', host_id=host_id))
Exemplo n.º 22
0
def host_category_url_new(host_id, hc_id):
    """ Create a new host_category_url.
    """
    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')

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    host_cat_ids = [cat.id for cat in hostobj.categories]

    if hcobj.id not in host_cat_ids:
        flask.abort(404, 'Category not associated with this host')

    categories = mmlib.get_categories(SESSION)

    form = forms.AddHostCategoryUrlForm()

    if form.validate_on_submit():

        host_category_u = model.HostCategoryUrl()
        host_category_u.host_category_id = hcobj.id
        form.populate_obj(obj=host_category_u)

        url = form.url.data.strip()
        if url.endswith('/'):
            url = url[:-1]
        host_category_u.url = url

        SESSION.add(host_category_u)

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

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

    return flask.render_template(
        'host_category_url_new.html',
        form=form,
        host=hostobj,
        hostcategory=hcobj,
    )
Exemplo n.º 23
0
def host_category_url_new(host_id, hc_id):
    """ Create a new host_category_url.
    """
    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')

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    host_cat_ids = [cat.id for cat in hostobj.categories]

    if hcobj.id not in host_cat_ids:
        flask.abort(404, 'Category not associated with this host')

    categories = mmlib.get_categories(SESSION)

    form = forms.AddHostCategoryUrlForm()

    if form.validate_on_submit():

        host_category_u = model.HostCategoryUrl()
        host_category_u.host_category_id = hcobj.id
        form.populate_obj(obj=host_category_u)

        url = form.url.data.strip()
        if url.endswith('/'):
            url = url[:-1]
        host_category_u.url = url

        SESSION.add(host_category_u)

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

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

    return flask.render_template(
        'host_category_url_new.html',
        form=form,
        host=hostobj,
        hostcategory=hcobj,
    )
Exemplo n.º 24
0
def host_view(host_id):
    """ Create a new host.
    """
    topic = 'host.updated'
    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.AddHostForm(obj=hostobj)
    if form.validate_on_submit():
        admin_active = hostobj.admin_active
        private = hostobj.private
        form.populate_obj(obj=hostobj)
        hostobj.bandwidth_int = int(hostobj.bandwidth_int)
        hostobj.asn = None if not hostobj.asn else int(hostobj.asn)

        # If the user is *not* an admin, keep the current admin_active flag
        if not is_mirrormanager_admin(flask.g.fas_user):
            hostobj.admin_active = admin_active

        # If the private flag has been changed, invalidate mirrors
        if hostobj.private != private:
            hostobj.set_not_up2date(SESSION)

        message = dict(
            site_id=hostobj.site_id,
            host_id=host_id,
            bandwidth=hostobj.bandwidth_int,
            asn=hostobj.asn)

        try:
            SESSION.flush()
            flask.flash('Host updated')
            fedmsg_publish(topic, message)
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code updates data therefore
            # the only situation where it could fail is a failure at the
            # DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update the host')
            APP.logger.debug('Could not update 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.html',
        form=form,
        host=hostobj,
    )
Exemplo n.º 25
0
def host_category(host_id, hc_id):
    """ View a host_category.
    """
    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')

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    host_cat_ids = [cat.id for cat in hostobj.categories]

    if hcobj.id not in host_cat_ids:
        flask.abort(404, 'Category not associated with this host')

    categories = mmlib.get_categories(SESSION)

    form = forms.EditHostCategoryForm(obj=hcobj)

    if form.validate_on_submit() and is_mirrormanager_admin(flask.g.fas_user):

        form.populate_obj(obj=hcobj)

        try:
            SESSION.flush()
            flask.flash('Host Category updated')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code check before updating
            # and therefore the only situation where it could fail is a
            # failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update Category to the host')
            APP.logger.debug('Could not update Category to the host')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(
            flask.url_for('host_category', host_id=hostobj.id, hc_id=hcobj.id))

    return flask.render_template(
        'host_category.html',
        form=form,
        host=hostobj,
        hostcategory=hcobj,
    )
Exemplo n.º 26
0
def host_view(host_id):
    """ Create a new host.
    """
    topic = 'host.updated'
    hostobj = mmlib.get_host(SESSION, host_id)

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

    form = forms.AddHostForm(obj=hostobj)
    if form.validate_on_submit():
        admin_active = hostobj.admin_active
        private = hostobj.private
        form.populate_obj(obj=hostobj)
        hostobj.bandwidth_int = int(hostobj.bandwidth_int)
        hostobj.asn = None if not hostobj.asn else int(hostobj.asn)

        # If the user is *not* an admin, keep the current admin_active flag
        if not is_mirrormanager_admin(flask.g.fas_user):
            hostobj.admin_active = admin_active

        # If the private flag has been changed, invalidate mirrors
        if hostobj.private != private:
            hostobj.set_not_up2date(SESSION)

        message = dict(
            site_id=hostobj.site_id,
            host_id=host_id,
            bandwidth=hostobj.bandwidth_int,
            asn=hostobj.asn)

        try:
            SESSION.flush()
            flask.flash('Host updated')
            fedmsg_publish(topic, message)
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code updates data therefore
            # the only situation where it could fail is a failure at the
            # DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update the host')
            APP.logger.debug('Could not update 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.html',
        form=form,
        host=hostobj,
    )
Exemplo n.º 27
0
def host_category(host_id, hc_id):
    """ View a host_category.
    """
    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')

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    host_cat_ids = [cat.id for cat in hostobj.categories]

    if hcobj.id not in host_cat_ids:
        flask.abort(404, 'Category not associated with this host')

    categories = mmlib.get_categories(SESSION)

    form = forms.EditHostCategoryForm(obj=hcobj)

    if form.validate_on_submit() and is_mirrormanager_admin(flask.g.fas_user):

        form.populate_obj(obj=hcobj)

        try:
            SESSION.flush()
            flask.flash('Host Category updated')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code check before updating
            # and therefore the only situation where it could fail is a
            # failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update Category to the host')
            APP.logger.debug('Could not update Category to the host')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(
            flask.url_for('host_category', host_id=hostobj.id, hc_id=hcobj.id))

    return flask.render_template(
        'host_category.html',
        form=form,
        host=hostobj,
        hostcategory=hcobj,
    )
Exemplo n.º 28
0
def host_category_url_delete(host_id, hc_id, host_category_url_id):
    """ Delete a host_category_url.
    """
    form = forms.ConfirmationForm()
    if form.validate_on_submit():
        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')

        hcobj = mmlib.get_host_category(SESSION, hc_id)

        if hcobj is None:
            flask.abort(404, 'Host/Category not found')

        host_cat_ids = [cat.id for cat in hostobj.categories]

        if hcobj.id not in host_cat_ids:
            flask.abort(404, 'Category not associated with this host')

        hostcaturlobj = mmlib.get_host_category_url_by_id(
            SESSION, host_category_url_id)

        if hostcaturlobj is None:
            flask.abort(404, 'Host category URL not found')

        host_cat_url_ids = [url.id for url in hcobj.urls]

        if hostcaturlobj.id not in host_cat_url_ids:
            flask.abort(404, 'Category URL not associated with this host')
        else:
            SESSION.delete(hostcaturlobj)

        try:
            SESSION.commit()
            flask.flash('Host category URL deleted')
        except SQLAlchemyError as err:  # pragma: no cover
            # We check everything before deleting so the only error we could
            # run in is DB server related, and that we can't fake in our
            # tests
            SESSION.rollback()
            flask.flash('Could not delete category URL of the host')
            APP.logger.debug('Could not delete category URL of the host')
            APP.logger.exception(err)

    return flask.redirect(
        flask.url_for('host_category', host_id=host_id, hc_id=hc_id))
Exemplo n.º 29
0
def host_category_url_delete(host_id, hc_id, host_category_url_id):
    """ Delete a host_category_url.
    """
    form = forms.ConfirmationForm()
    if form.validate_on_submit():
        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')

        hcobj = mmlib.get_host_category(SESSION, hc_id)

        if hcobj is None:
            flask.abort(404, 'Host/Category not found')

        host_cat_ids = [cat.id for cat in hostobj.categories]

        if hcobj.id not in host_cat_ids:
            flask.abort(404, 'Category not associated with this host')

        hostcaturlobj = mmlib.get_host_category_url_by_id(
            SESSION, host_category_url_id)

        if hostcaturlobj is None:
            flask.abort(404, 'Host category URL not found')

        host_cat_url_ids = [url.id for url in hcobj.urls]

        if hostcaturlobj.id not in host_cat_url_ids:
            flask.abort(404, 'Category URL not associated with this host')
        else:
            SESSION.delete(hostcaturlobj)

        try:
            SESSION.commit()
            flask.flash('Host category URL deleted')
        except SQLAlchemyError as err:  # pragma: no cover
            # We check everything before deleting so the only error we could
            # run in is DB server related, and that we can't fake in our
            # tests
            SESSION.rollback()
            flask.flash('Could not delete category URL of the host')
            APP.logger.debug('Could not delete category URL of the host')
            APP.logger.exception(err)

    return flask.redirect(
        flask.url_for('host_category', host_id=host_id, hc_id=hc_id))
Exemplo n.º 30
0
def host_category_new(host_id):
    """ Create a new host_category.
    """
    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')

    categories = mmlib.get_categories(SESSION)

    form = forms.AddHostCategoryForm(categories=categories)

    if flask.request.method == 'POST':
        try:
            form.category_id.data = int(form.category_id.data)
        except ValueError:
            pass

    if form.validate_on_submit():

        host_category = model.HostCategory()
        host_category.host_id = hostobj.id
        form.populate_obj(obj=host_category)
        host_category.category_id = int(host_category.category_id)
        SESSION.add(host_category)

        try:
            SESSION.commit()
            flask.flash('Host Category added')
            return flask.redirect(
                flask.url_for(
                    'host_category',
                    host_id=hostobj.id,
                    hc_id=host_category.id))
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not add Category to the host')
            APP.logger.debug('Could not add Category to the host')
            APP.logger.exception(err)

    return flask.render_template(
        'host_category_new.html',
        form=form,
        host=hostobj,
    )
Exemplo n.º 31
0
def host_category_new(host_id):
    """ Create a new host_category.
    """
    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')

    categories = mmlib.get_categories(SESSION)

    form = forms.AddHostCategoryForm(categories=categories)

    if flask.request.method == 'POST':
        try:
            form.category_id.data = int(form.category_id.data)
        except ValueError:
            pass

    if form.validate_on_submit():

        host_category = model.HostCategory()
        host_category.host_id = hostobj.id
        form.populate_obj(obj=host_category)
        host_category.category_id = int(host_category.category_id)
        SESSION.add(host_category)

        try:
            SESSION.commit()
            flask.flash('Host Category added')
            return flask.redirect(
                flask.url_for(
                    'host_category',
                    host_id=hostobj.id,
                    hc_id=host_category.id))
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not add Category to the host')
            APP.logger.debug('Could not add Category to the host')
            APP.logger.exception(err)

    return flask.render_template(
        'host_category_new.html',
        form=form,
        host=hostobj,
    )
Exemplo n.º 32
0
def host_country_new(host_id):
    """ Create a new host_country.
    """
    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.AddHostCountryForm()
    if form.validate_on_submit():
        country_name = form.country.data
        country = mmlib.get_country_by_name(SESSION, country_name)
        if country is None:
            flask.flash('Invalid country code')
            return flask.render_template(
                'host_country_new.html',
                form=form,
                host=hostobj,
            )

        host_country = model.HostCountry()
        host_country.host_id = hostobj.id
        host_country.country_id = country.id
        SESSION.add(host_country)

        try:
            SESSION.flush()
            flask.flash('Host Country 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 Country to the host')
            APP.logger.debug('Could not add Country 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_country_new.html',
        form=form,
        host=hostobj,
    )
Exemplo n.º 33
0
def host_country_new(host_id):
    """ Create a new host_country.
    """
    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.AddHostCountryForm()
    if form.validate_on_submit():
        country_name = form.country.data
        country = mmlib.get_country_by_name(SESSION, country_name)
        if country is None:
            flask.flash('Invalid country code')
            return flask.render_template(
                'host_country_new.html',
                form=form,
                host=hostobj,
            )

        host_country = model.HostCountry()
        host_country.host_id = hostobj.id
        host_country.country_id = country.id
        SESSION.add(host_country)

        try:
            SESSION.flush()
            flask.flash('Host Country 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 Country to the host')
            APP.logger.debug('Could not add Country 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_country_new.html',
        form=form,
        host=hostobj,
    )
Exemplo n.º 34
0
def host_category_url_new(host_id, hc_id):
    """ Create a new host_category_url.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    categories = mmlib.get_categories(SESSION)

    form = forms.AddHostCategoryUrlForm()

    if form.validate_on_submit():

        host_category_u = model.HostCategoryUrl()
        host_category_u.host_category_id = hcobj.id
        form.populate_obj(obj=host_category_u)
        SESSION.add(host_category_u)

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

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

    return flask.render_template(
        'host_category_url_new.html',
        form=form,
        host=hostobj,
        hostcategory=hcobj,
    )
Exemplo n.º 35
0
def host_category_url_new(host_id, hc_id):
    """ Create a new host_category_url.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    categories = mmlib.get_categories(SESSION)

    form = forms.AddHostCategoryUrlForm()

    if form.validate_on_submit():

        host_category_u = model.HostCategoryUrl()
        host_category_u.host_category_id = hcobj.id
        form.populate_obj(obj=host_category_u)
        SESSION.add(host_category_u)

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

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

    return flask.render_template(
        'host_category_url_new.html',
        form=form,
        host=hostobj,
        hostcategory=hcobj,
    )
Exemplo n.º 36
0
def host_country_new(host_id):
    """ Create a new host_country.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    form = forms.AddHostCountryForm()
    if form.validate_on_submit():
        country_name = form.country.data
        country = mmlib.get_country_by_name(SESSION, country_name)
        if country is None:
            flask.flash('Invalid country code')
            return flask.render_template(
                'host_country_new.html',
                form=form,
                host=hostobj,
            )

        host_country = model.HostCountry()
        host_country.host_id = hostobj.id
        host_country.country_id = country.id
        SESSION.add(host_country)

        try:
            SESSION.flush()
            flask.flash('Host Country added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not add Country to the host')
            APP.logger.debug('Could not add Country 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_country_new.html',
        form=form,
        host=hostobj,
    )
Exemplo n.º 37
0
def host_country_new(host_id):
    """ Create a new host_country.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    form = forms.AddHostCountryForm()
    if form.validate_on_submit():
        country_name = form.country.data
        country = mmlib.get_country_by_name(SESSION, country_name)
        if country is None:
            flask.flash('Invalid country code')
            return flask.render_template(
                'host_country_new.html',
                form=form,
                host=hostobj,
            )

        host_country = model.HostCountry()
        host_country.host_id = hostobj.id
        host_country.country_id = country.id
        SESSION.add(host_country)

        try:
            SESSION.flush()
            flask.flash('Host Country added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not add Country to the host')
            APP.logger.debug('Could not add Country 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_country_new.html',
        form=form,
        host=hostobj,
    )
Exemplo n.º 38
0
def host_category(host_id, hc_id):
    """ View a host_category.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    categories = mmlib.get_categories(SESSION)

    form = forms.EditHostCategoryForm(obj=hcobj)

    if form.validate_on_submit():

        form.populate_obj(obj=hcobj)

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

        SESSION.commit()
        return flask.redirect(
            flask.url_for('host_category', host_id=hostobj.id, hc_id=hcobj.id))

    return flask.render_template(
        'host_category.html',
        form=form,
        host=hostobj,
        hostcategory=hcobj,
    )
Exemplo n.º 39
0
def host_category(host_id, hc_id):
    """ View a host_category.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

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

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    categories = mmlib.get_categories(SESSION)

    form = forms.EditHostCategoryForm(obj=hcobj)

    if form.validate_on_submit():

        form.populate_obj(obj=hcobj)

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

        SESSION.commit()
        return flask.redirect(
            flask.url_for('host_category', host_id=hostobj.id, hc_id=hcobj.id))

    return flask.render_template(
        'host_category.html',
        form=form,
        host=hostobj,
        hostcategory=hcobj,
    )
Exemplo n.º 40
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,
    )
Exemplo n.º 41
0
def host_category_delete(host_id, hc_id):
    """ Delete a host_category.
    """
    form = forms.ConfirmationForm()
    if form.validate_on_submit():
        hostobj = mmlib.get_host(SESSION, host_id)

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

        hcobj = mmlib.get_host_category(SESSION, hc_id)

        if hcobj is None:
            flask.abort(404, 'Host/Category not found')
        host_cat_ids = [cat.id for cat in hostobj.categories]

        if hcobj.id not in host_cat_ids:
            flask.abort(404, 'Category not associated with this host')
        else:
            for url in hcobj.urls:
                SESSION.delete(url)
            for dirs in hcobj.directories:
                SESSION.delete(dirs)
            SESSION.delete(hcobj)

        try:
            SESSION.commit()
            flask.flash('Host Category deleted')
        except SQLAlchemyError as err:  # pragma: no cover
            # We check everything before deleting so the only error we could
            # run in is DB server related, and that we can't fake in our
            # tests
            SESSION.rollback()
            flask.flash('Could not delete Category of the host')
            APP.logger.debug('Could not delete Category of the host')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('host_view', host_id=host_id))
Exemplo n.º 42
0
def host_category_delete(host_id, hc_id):
    """ Delete a host_category.
    """
    form = forms.ConfirmationForm()
    if form.validate_on_submit():
        hostobj = mmlib.get_host(SESSION, host_id)

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

        hcobj = mmlib.get_host_category(SESSION, hc_id)

        if hcobj is None:
            flask.abort(404, 'Host/Category not found')
        host_cat_ids = [cat.id for cat in hostobj.categories]

        if hcobj.id not in host_cat_ids:
            flask.abort(404, 'Category not associated with this host')
        else:
            for url in hcobj.urls:
                SESSION.delete(url)
            for dirs in hcobj.directories:
                SESSION.delete(dirs)
            SESSION.delete(hcobj)

        try:
            SESSION.commit()
            flask.flash('Host Category deleted')
        except SQLAlchemyError as err:  # pragma: no cover
            # We check everything before deleting so the only error we could
            # run in is DB server related, and that we can't fake in our
            # tests
            SESSION.rollback()
            flask.flash('Could not delete Category of the host')
            APP.logger.debug('Could not delete Category of the host')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('host_view', host_id=host_id))
Exemplo n.º 43
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')

    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.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,
    )
Exemplo n.º 44
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')

    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.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,
    )