コード例 #1
0
ファイル: __init__.py プロジェクト: Flig/mirrormanager2
def create_hosts(session):
    ''' Create some hosts to play with for the tests
    '''
    item = model.Host(
        name='mirror.localhost',
        site_id=1,
        robot_email=None,
        admin_active=True,
        user_active=True,
        country='US',
        bandwidth_int=100,
        comment=None,
        private=False,
        internet2=False,
        internet2_clients=False,
        asn=None,
        asn_clients=False,
        max_connections=10,
    )
    session.add(item)
    item = model.Host(
        name='mirror2.localhost',
        site_id=2,
        robot_email=None,
        admin_active=True,
        user_active=True,
        country='FR',
        bandwidth_int=100,
        comment=None,
        private=False,
        internet2=False,
        internet2_clients=False,
        asn=100,
        asn_clients=True,
        max_connections=10,
    )
    session.add(item)
    item = model.Host(
        name='private.localhost',
        site_id=1,
        robot_email=None,
        admin_active=True,
        user_active=True,
        country='NL',
        bandwidth_int=100,
        comment='My own private mirror',
        private=True,
        internet2=False,
        internet2_clients=False,
        asn=None,
        asn_clients=False,
        max_connections=10,
    )
    session.add(item)

    session.commit()
コード例 #2
0
ファイル: __init__.py プロジェクト: yumsuresht/mirrormanager2
def host_new(site_id):
    """ Create a new host.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

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

    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.bandwidth_int = int(host.bandwidth_int)
        host.asn = None if not host.asn else int(host.asn)

        try:
            SESSION.flush()
            flask.flash('Host added')
        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,
    )
コード例 #3
0
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,
    )