示例#1
0
def get_resource_mgr_properties(context, parent_id, key=None, session=None):
    """Get properties from the properties table for a Resource Manager

    :param parent_id: ID of the Resource Managers
    :param key: key of the property. When not specified returns all the
     properties associated with parent_id
    :return: List of property objects
    """
    session = session or _get_session()
    with session.begin(subtransactions=True):
        try:
            if key:
                query = (session.query(
                    models.ResourceManagerProperties).filter_by(
                        parent_id=parent_id).filter_by(key=key).filter_by(
                            deleted=False))
                prop = query.one()
                return [prop]
            else:
                query = (session.query(
                    models.ResourceManagerProperties).filter_by(
                        parent_id=parent_id).filter_by(deleted=False))
                props = query.all()
                return props
        except sa_orm.exc.NoResultFound:
            msg = _("No Property found for Parent ID %s") % parent_id
            log_msg = ("No Property found for Parent ID %s") % parent_id
            LOG.error(log_msg)
            raise exception.NotFound(msg)
示例#2
0
def _ippool_get(pool_id, context=None, session=None, force_show_deleted=False):
    """Get an esx proxy ip pool or raise if it does not exist."""
    session = session or _get_session()

    if pool_id not in session['ippools']:
        msg = (_("No ESX Proxy IP Pool found with ID %s" % pool_id))
        LOG.error(msg)
        raise exception.NotFound(msg)

    ippool_ref = session['ippools'][pool_id]

    if ippool_ref['deleted'] != force_show_deleted:
        msg = (_("No ESX Proxy IP Pool found with ID %s" % pool_id))
        LOG.error(msg)
        raise exception.NotFound(msg)

    return ippool_ref
示例#3
0
def _resource_entity_get(context, resource_entity_id, session=None):
    """Get an resource_entity or raise if it does not exist."""
    session = session or _get_session()
    if resource_entity_id not in session['resource_entity']:
        msg = (_("No Resource found with ID %s" % resource_entity_id))
        LOG.error(msg)
        raise exception.NotFound(msg)

    res_entity_ref = session['resource_entity'][resource_entity_id]
    return res_entity_ref
示例#4
0
def _esx_proxy_get(context,
                   esx_proxy_id,
                   session=None,
                   force_show_deleted=False,
                   force_show_active_only=True):
    """Get an esx_proxy or raise if it does not exist."""
    session = session or _get_session()

    if esx_proxy_id not in session['esx_proxys']:
        raise exception.NotFound("No Esx-Proxy found (ID %s)" % esx_proxy_id)

    esx_proxy_ref = session['esx_proxys'][esx_proxy_id]
    if not force_show_deleted and esx_proxy_ref['deleted']:
        raise exception.NotFound("No Esx-Proxy found (ID %s)" % esx_proxy_id)

    if force_show_active_only and not esx_proxy_ref['active']:
        raise exception.NotFound("No Esx-Proxy found (ID %s)" % esx_proxy_id)

    return esx_proxy_ref
示例#5
0
def _vcenter_get(context, vcenter_id, session=None, force_show_deleted=False):
    """Get an vcenter or raise if it does not exist."""
    session = session or _get_session()

    if vcenter_id not in session['vcenters']:
        msg = (_("No vCenter found with ID %s" % vcenter_id))
        LOG.error(msg)
        raise exception.NotFound(msg)

    vcenter_ref = session['vcenters'][vcenter_id]
    return vcenter_ref
示例#6
0
def _ip_get(ip_id, context=None, session=None, force_show_deleted=False):
    """
    Get EsxProxyIP object.
    """
    session = session or _get_session()
    try:
        ip = session['esx_proxy_ips'][ip_id]

    except KeyError:
        msg = (_("No ESX Proxy IP found with ID %s" % ip_id))
        LOG.info(msg)
        raise exception.NotFound(msg)

    if ip['deleted'] and\
            not (force_show_deleted or context.show_deleted):
        msg = (_("No ESX Proxy IP found with ID %s" % ip_id))
        LOG.info(msg)
        raise exception.NotFound(msg)

    return ip
示例#7
0
def _get(context, _id, session, db_model):
    with session.begin(subtransactions=True):
        try:
            query = session.query(db_model).filter_by(id=_id)
            instance = query.one()
            return instance
        except sa_orm.exc.NoResultFound:
            msg = _("No %s found with ID %s") % (db_model.__tablename__, _id)
            log_msg = ("No %s found with ID %s") % (db_model.__tablename__,
                                                    _id)
            LOG.error(log_msg)
            raise exception.NotFound(msg)