~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to nova/db/sqlalchemy/api.py

  • Committer: Tarmac
  • Author(s): Rick Harris
  • Date: 2011-09-22 16:42:20 UTC
  • mfrom: (1590.1.11 flavor_min_filter)
  • Revision ID: tarmac-20110922164220-ndscikwberuj3c7f
This patch adds flavor filtering, specifically the ability to flavor on minRam, minDisk, or both, per the 1.1 OSAPI spec.

In addition, this patch refactors instance_type_get_all to return a *list* of instance_types instead of a *dict*. This makes it more consistent with the rest of the DB API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3323
3323
 
3324
3324
 
3325
3325
@require_context
3326
 
def instance_type_get_all(context, inactive=False):
3327
 
    """
3328
 
    Returns a dict describing all instance_types with name as key.
3329
 
    """
 
3326
def instance_type_get_all(context, inactive=False, filters=None):
 
3327
    """
 
3328
    Returns all instance types.
 
3329
    """
 
3330
    filters = filters or {}
3330
3331
    session = get_session()
3331
 
    if inactive:
3332
 
        inst_types = session.query(models.InstanceTypes).\
3333
 
                        options(joinedload('extra_specs')).\
3334
 
                        order_by("name").\
3335
 
                        all()
3336
 
    else:
3337
 
        inst_types = session.query(models.InstanceTypes).\
3338
 
                        options(joinedload('extra_specs')).\
3339
 
                        filter_by(deleted=False).\
3340
 
                        order_by("name").\
3341
 
                        all()
3342
 
    inst_dict = {}
3343
 
    if inst_types:
3344
 
        for i in inst_types:
3345
 
            inst_dict[i['name']] = _dict_with_extra_specs(i)
3346
 
    return inst_dict
 
3332
    partial = session.query(models.InstanceTypes)\
 
3333
                     .options(joinedload('extra_specs'))
 
3334
    if not inactive:
 
3335
        partial = partial.filter_by(deleted=False)
 
3336
 
 
3337
    if 'min_memory_mb' in filters:
 
3338
        partial = partial.filter(
 
3339
                models.InstanceTypes.memory_mb >= filters['min_memory_mb'])
 
3340
    if 'min_local_gb' in filters:
 
3341
        partial = partial.filter(
 
3342
                models.InstanceTypes.local_gb >= filters['min_local_gb'])
 
3343
 
 
3344
    inst_types = partial.order_by("name").all()
 
3345
 
 
3346
    return [_dict_with_extra_specs(i) for i in inst_types]
3347
3347
 
3348
3348
 
3349
3349
@require_context