当前位置: 首页>>代码示例>>Python>>正文


Python lib.get_host函数代码示例

本文整理汇总了Python中mirrormanager2.lib.get_host函数的典型用法代码示例。如果您正苦于以下问题:Python get_host函数的具体用法?Python get_host怎么用?Python get_host使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_host函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: host_category_url_delete

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))
开发者ID:yumsuresht,项目名称:mirrormanager2,代码行数:31,代码来源:__init__.py

示例2: host_drop

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))
开发者ID:TroJan,项目名称:mirrormanager2,代码行数:34,代码来源:app.py

示例3: host_netblock_new

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,
    )
开发者ID:Devyani-Divs,项目名称:mirrormanager2,代码行数:35,代码来源:app.py

示例4: host_asn_delete

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))
开发者ID:TroJan,项目名称:mirrormanager2,代码行数:30,代码来源:app.py

示例5: host_category_delete

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))
开发者ID:yumsuresht,项目名称:mirrormanager2,代码行数:29,代码来源:__init__.py

示例6: host_asn_new

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,
    )
开发者ID:yumsuresht,项目名称:mirrormanager2,代码行数:33,代码来源:__init__.py

示例7: host_asn_delete

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))
开发者ID:yumsuresht,项目名称:mirrormanager2,代码行数:25,代码来源:__init__.py

示例8: host_acl_ip_delete

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))
开发者ID:yumsuresht,项目名称:mirrormanager2,代码行数:25,代码来源:__init__.py

示例9: host_view

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,
    )
开发者ID:yumsuresht,项目名称:mirrormanager2,代码行数:31,代码来源:__init__.py

示例10: host_country_delete

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))
开发者ID:TroJan,项目名称:mirrormanager2,代码行数:34,代码来源:app.py

示例11: host_category_url_new

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,
    )
开发者ID:TroJan,项目名称:mirrormanager2,代码行数:58,代码来源:app.py

示例12: host_category

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,
    )
开发者ID:TroJan,项目名称:mirrormanager2,代码行数:52,代码来源:app.py

示例13: host_view

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,
    )
开发者ID:fedora-infra,项目名称:mirrormanager2,代码行数:52,代码来源:app.py

示例14: host_category_url_delete

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))
开发者ID:TroJan,项目名称:mirrormanager2,代码行数:51,代码来源:app.py

示例15: host_category_new

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,
    )
开发者ID:TroJan,项目名称:mirrormanager2,代码行数:49,代码来源:app.py


注:本文中的mirrormanager2.lib.get_host函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。