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'))
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))
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))
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'))
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 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 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, )
def host_new(site_id): """ Create a new host. """ topic = 'host.added' 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.AddHostForm() if form.validate_on_submit(): host = model.Host() SESSION.add(host) host.site_id = siteobj.id form.populate_obj(obj=host) host.admin_active = True host.bandwidth_int = int(host.bandwidth_int) host.asn = None if not host.asn else int(host.asn) message = dict( site_id=host.site_id, bandwidth=host.bandwidth_int, asn=host.asn) try: SESSION.flush() flask.flash('Host added') fedmsg_publish(topic, message) except SQLAlchemyError as err: SESSION.rollback() flask.flash('Could not create the new host') APP.logger.debug('Could not create the new host') APP.logger.exception(err) SESSION.commit() return flask.redirect(flask.url_for('site_view', site_id=site_id)) return flask.render_template( 'host_new.html', form=form, site=siteobj, )
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 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 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, )
def host_new(site_id): """ Create a new host. """ topic = 'host.added' 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.AddHostForm() if form.validate_on_submit(): host = model.Host() SESSION.add(host) host.site_id = siteobj.id form.populate_obj(obj=host) host.admin_active = True host.bandwidth_int = int(host.bandwidth_int) host.asn = None if not host.asn else int(host.asn) message = dict(site_id=host.site_id, bandwidth=host.bandwidth_int, asn=host.asn) try: SESSION.flush() flask.flash('Host added') fedmsg_publish(topic, message) except SQLAlchemyError as err: SESSION.rollback() flask.flash('Could not create the new host') APP.logger.debug('Could not create the new host') APP.logger.exception(err) SESSION.commit() return flask.redirect(flask.url_for('site_view', site_id=site_id)) return flask.render_template( 'host_new.html', form=form, site=siteobj, )