Beispiel #1
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))
Beispiel #2
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))
Beispiel #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))
Beispiel #4
0
def site_drop(site_id):
    """ Drop a given site.
    """
    topic = 'site.deleted'
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

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

    form = forms.ConfirmationForm()
    site_name = siteobj.name
    if form.validate_on_submit():
        message = dict(site_id=siteobj.id,
                       site_name=siteobj.name,
                       org_url=siteobj.org_url)

        SESSION.delete(siteobj)
        try:
            SESSION.commit()
            flask.flash('Site "%s" dropped' % site_name)
            fedmsg_publish(topic, message)
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not delete this site')
            APP.logger.debug('Could not delete this site')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('index'))
Beispiel #5
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))
Beispiel #6
0
def siteadmin_delete(site_id, admin_id):
    """ Delete a site_admin.
    """
    form = forms.ConfirmationForm()
    if form.validate_on_submit():

        siteobj = mmlib.get_site(SESSION, site_id)

        if siteobj is None:
            flask.abort(404, 'Site not found')

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

        siteadminobj = mmlib.get_siteadmin(SESSION, admin_id)

        if siteadminobj is None:
            flask.abort(404, 'Site Admin not found')

        if siteadminobj not in siteobj.admins:
            flask.abort(404, 'Site Admin not related to this Site')

        if len(siteobj.admins) <= 1:
            flask.flash('There is only one admin set, you cannot delete it.',
                        'error')
            return flask.redirect(flask.url_for('site_view', site_id=site_id))

        SESSION.delete(siteadminobj)

        try:
            SESSION.commit()
            flask.flash('Site Admin 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 Site Admin', 'error')
            APP.logger.debug('Could not delete Site Admin')
            APP.logger.exception(err)

    return flask.redirect(flask.url_for('site_view', site_id=site_id))
Beispiel #7
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))