~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2013-08-09 10:12:27 UTC
  • mfrom: (1.1.74)
  • Revision ID: package-import@ubuntu.com-20130809101227-4n60fzcgra8dzk3d
Tags: 1:2013.1.3-0ubuntu1
* Resynchronize with stable/grizzly (89c7ee4) (LP: #1210447):
  - [8e6edd2] Bump stable/grizzly next version to 2013.1.3
  - [61fc529] attach quantum security group to an existing vm failed
    LP: 1189059
  - [60774bd] nova-compute fails to start if quantum is down LP: 1186357
  - [8e6d4b6] asymmetric routes in nova network with external gateway and
    routing_source_ip LP: 1182143
  - [8849413] Failed VM's not set to error state on exception LP: 1182056
  - [ef10eee] Double healing of info_cache with cells LP: 1180304
  - [7422d83] Can't log into  VM after powervm is resized LP: 1169848
  - [49ab0e8] stack trace when instance_actions extension can not find
    instance in GET LP: 1182867
  - [e71247c] nova service-list returns illegal result with non db service
    heartbeat LP: 1168861
  - [3f60606] Volume IO usage gets reset to 0 after a reboot / crash
    LP: 1169097
  - [19c443b] unused method  list_interfaces in vmware driver can be removed
    LP: 1187251
  - [a8dab9f] No cleanup done when file transfer fails with powervm driver
    LP: 1173017
  - [fc98015] nova consoleauth depends on Conductor Service LP: 1186123
  - [1066418] VMware drivers are no longer passing quantum port-id to
    vCenter LP: 1183452
  - [b92075c] nova net-list fails on empty list with Quantum backend
    LP: 1189976
  - [3ba31f2] Create VM with no networks with Quantum Gives SecurityGroups
    Exception LP: 1191044
  - [89150b2] Periodic ValueErrors when using qpid LP: 1185465
  - [0e0d615] Libvirt pre-Grizzly instances cannot be block migrated
    LP: 1185588
  - [27960ef] ZMQ ipc socket file is created using un-sanitized network
    input LP: 1122763
  - [265b868] cannot block migrate old style instances libvirt complains
    LP: 1175286
  - [008a68a] code logical error exists in vmwareapi vif.py  LP: 1177635
  - [378c045] Instance IP addresses are re-used even when previous instance
    could not be powered off LP: 1180178
  - [48ddffe] Reboot of compute node breaks VMs with volumes LP: 1188326
  - [f427f01] Missing dashes from console-log LP: 1194032
  - [78ebf1a] network-create returns an internal error when network
    conflicts LP: 1158075
  - [767c850] Instance nics are reorder after reboot LP: 1187092
  - [0b45996] instance directory naming update to use uuid  LP: 1186944
  - [06cfad5] Disassociate failed dhcp fixed ip in deallocate_for_instance()
    method LP: 1180766
  - [cbcdfc5] Allow confirm_resize action on an instance in 'deleting'
    status LP: 1189391
  - [2563c44] aggregate_get_by_host returns aggregates from other hosts
    LP: 1201277
  - [109f3a9] nova libvirt driver requires iscsi initiator name regardless
    of using it in volume drivers LP: 1007084
  - [7f1c336] Host is always set to None in get_instance_nw_info(...)
    LP: 1194178
  - [1cf30a3] nova boot with colume should fail if the volume is already
    attached to another instance LP: 1166770
  - [9cb9361] Aggregate metadata filtering by key returns unrelated metadata
    LP: 1201283
  - [a61872b] Need clean up  ftp transfer faiure  in powervm driver
    LP: 1188884
  - [91bcd15] Race can cause soft deleted instance to be erased by mistake
    LP: 1186243
  - [c57fded] Nova fails to create a security group rule if ::0/0 is used as
    cidr LP: 1199943
  - [c698dd3] VMwareESXDriver and VMwareVCDriver report incorrect stat
    LP: 1180779
  - [e572faf] novnc fails when amqp_rpc_single_reply_queue=True LP: 1193031
  - [34ddd27] eventlet.monkey_patch() for spice and vnc proxy
  - [864837f] hypervisor_hostname not updated on evacuate LP: 1198284
  - [756a772] libvirt migrate/resize on shared storage can cause data loss
    LP: 1177247
  - [889b215] nova live-migration of volume-backed VM fails because of image
    is None LP: 1199811
  - [60712a4] VNC console does not work with VCDriver LP: 1178369
  - [e0aa0f5] metadata service throws error 500 when compute_driver is not
    set LP: 1184641
  - [340d337] Instance IP addresses are re-used even when previous instance
    could not be powered off LP: 1180178
  - [8247dc8] Resource limit circumvention in Nova private flavors
    (CVE-2013-2256) LP: 1194093
  - [bd7e467] Denial of Service in Nova network source security groups
    (CVE-2013-4185) LP: 1184041
  - [c3fddb7] Resize a VM when a volume is attached fails LP: 1190364
  - [01edbaa] Hyper-V versions before 2012 are not properly recognized
    LP: 1203059
  - [b18818a] driver libvirt doesn't honor vif quota LP: 1185030
  - [798984d] config drive not visible to windows LP: 1155842
  - [d18ceb1] nova live-migration failed due to exception.MigrationError
    LP: 1171526
  - [1934dbc] vmware Hyper for nova vnc console url parameters error
    LP: 1172177
  - [89c7ee4] [OSSA 2013-023] Potential unsafe XML usage (CVE-2013-4179,
    CVE-2013-4202) LP: 1190229
* debian/rules: Clean new setuptools-git cruft.
* debian/control: Update Vcs fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
from sqlalchemy import Integer
37
37
from sqlalchemy import MetaData
38
38
from sqlalchemy import or_
 
39
from sqlalchemy.orm import contains_eager
39
40
from sqlalchemy.orm import joinedload
40
41
from sqlalchemy.orm import joinedload_all
41
42
from sqlalchemy.schema import Table
1690
1691
    # For other filters that don't match this, we will do regexp matching
1691
1692
    exact_match_filter_names = ['project_id', 'user_id', 'image_ref',
1692
1693
                                'vm_state', 'instance_type_id', 'uuid',
1693
 
                                'metadata']
 
1694
                                'metadata', 'task_state']
1694
1695
 
1695
1696
    # Filter the query
1696
1697
    query_prefix = exact_filter(query_prefix, models.Instance,
3231
3232
            filter_by(parent_group_id=security_group_id).\
3232
3233
            options(joinedload_all('grantee_group.instances.'
3233
3234
                                   'system_metadata')).\
 
3235
            options(joinedload('grantee_group.instances.'
 
3236
                               'info_cache')).\
3234
3237
            all()
3235
3238
 
3236
3239
 
3556
3559
            pass
3557
3560
        try:
3558
3561
            instance_type_get_by_flavor_id(context, values['flavorid'],
3559
 
                                           session)
 
3562
                    read_deleted='no', session=session)
3560
3563
            raise exception.InstanceTypeIdExists(flavor_id=values['flavorid'])
3561
3564
        except exception.FlavorNotFound:
3562
3565
            pass
3598
3601
 
3599
3602
 
3600
3603
def _instance_type_get_query(context, session=None, read_deleted=None):
3601
 
    return model_query(context, models.InstanceTypes, session=session,
 
3604
    query = model_query(context, models.InstanceTypes, session=session,
3602
3605
                       read_deleted=read_deleted).\
3603
 
                     options(joinedload('extra_specs'))
 
3606
                       options(joinedload('extra_specs'))
 
3607
    if not context.is_admin:
 
3608
        the_filter = [models.InstanceTypes.is_public == True]
 
3609
        the_filter.extend([
 
3610
            models.InstanceTypes.projects.any(project_id=context.project_id)
 
3611
        ])
 
3612
        query = query.filter(or_(*the_filter))
 
3613
    return query
3604
3614
 
3605
3615
 
3606
3616
@require_context
3675
3685
 
3676
3686
 
3677
3687
@require_context
3678
 
def instance_type_get_by_flavor_id(context, flavor_id, session=None):
 
3688
def instance_type_get_by_flavor_id(context, flavor_id, read_deleted,
 
3689
                                   session=None):
3679
3690
    """Returns a dict describing specific flavor_id."""
3680
 
    result = _instance_type_get_query(context, session=session).\
 
3691
    result = _instance_type_get_query(context, read_deleted=read_deleted,
 
3692
                                      session=session).\
3681
3693
                    filter_by(flavorid=flavor_id).\
3682
3694
                    first()
3683
3695
 
3727
3739
    session = get_session()
3728
3740
    with session.begin():
3729
3741
        instance_type_ref = instance_type_get_by_flavor_id(context, flavor_id,
3730
 
                                                           session=session)
 
3742
                read_deleted='no', session=session)
3731
3743
        instance_type_id = instance_type_ref['id']
3732
3744
        access_ref = _instance_type_access_query(context, session=session).\
3733
3745
                        filter_by(instance_type_id=instance_type_id).\
3750
3762
    session = get_session()
3751
3763
    with session.begin():
3752
3764
        instance_type_ref = instance_type_get_by_flavor_id(context, flavor_id,
3753
 
                                                           session=session)
 
3765
                read_deleted='no', session=session)
3754
3766
        instance_type_id = instance_type_ref['id']
3755
3767
        count = _instance_type_access_query(context, session=session).\
3756
3768
                        filter_by(instance_type_id=instance_type_id).\
4187
4199
                      'curr_write_bytes': 0,
4188
4200
                      'instance_id': instance_id}
4189
4201
 
4190
 
        rows = model_query(context, models.VolumeUsage,
4191
 
                           session=session, read_deleted="yes").\
4192
 
                           filter_by(volume_id=id).\
4193
 
                           update(values, synchronize_session=False)
 
4202
        current_usage = model_query(context, models.VolumeUsage,
 
4203
                            session=session, read_deleted="yes").\
 
4204
                            filter_by(volume_id=id).\
 
4205
                            first()
 
4206
        if current_usage:
 
4207
            if (rd_req < current_usage['curr_reads'] or
 
4208
                rd_bytes < current_usage['curr_read_bytes'] or
 
4209
                wr_req < current_usage['curr_writes'] or
 
4210
                wr_bytes < current_usage['curr_write_bytes']):
 
4211
                LOG.info(_("Volume(%s) has lower stats then what is in "
 
4212
                           "the database. Instance must have been rebooted "
 
4213
                           "or crashed. Updating totals.") % id)
 
4214
                if not update_totals:
 
4215
                    values['tot_last_refreshed'] = last_refreshed
 
4216
                    values['tot_reads'] = (models.VolumeUsage.tot_reads +
 
4217
                                           current_usage['curr_reads'])
 
4218
                    values['tot_read_bytes'] = (
 
4219
                        models.VolumeUsage.tot_read_bytes +
 
4220
                        current_usage['curr_read_bytes'])
 
4221
                    values['tot_writes'] = (models.VolumeUsage.tot_writes +
 
4222
                                            current_usage['curr_writes'])
 
4223
                    values['tot_write_bytes'] = (
 
4224
                        models.VolumeUsage.tot_write_bytes +
 
4225
                        current_usage['curr_write_bytes'])
 
4226
                else:
 
4227
                    values['tot_reads'] = (models.VolumeUsage.tot_reads +
 
4228
                                           current_usage['curr_reads'] +
 
4229
                                           rd_req)
 
4230
                    values['tot_read_bytes'] = (
 
4231
                        models.VolumeUsage.tot_read_bytes +
 
4232
                        current_usage['curr_read_bytes'] + rd_bytes)
 
4233
                    values['tot_writes'] = (models.VolumeUsage.tot_writes +
 
4234
                                            current_usage['curr_writes'] +
 
4235
                                            wr_req)
 
4236
                    values['tot_write_bytes'] = (
 
4237
                        models.VolumeUsage.tot_write_bytes +
 
4238
                        current_usage['curr_write_bytes'] + wr_bytes)
4194
4239
 
4195
 
        if rows:
 
4240
            current_usage.update(values)
4196
4241
            return
4197
4242
 
4198
4243
        vol_usage = models.VolumeUsage()
4213
4258
 
4214
4259
        vol_usage.save(session=session)
4215
4260
 
4216
 
    return
4217
 
 
4218
4261
 
4219
4262
####################
4220
4263
 
4315
4358
 
4316
4359
@require_admin_context
4317
4360
def aggregate_get_by_host(context, host, key=None):
4318
 
    query = _aggregate_get_query(context, models.Aggregate,
4319
 
            models.AggregateHost.host, host)
 
4361
    """Return rows that match host (mandatory) and metadata key (optional).
 
4362
 
 
4363
    :param host matches host, and is required.
 
4364
    :param key Matches metadata key, if not None.
 
4365
    """
 
4366
    query = model_query(context, models.Aggregate)
 
4367
    query = query.options(joinedload('_hosts'))
 
4368
    query = query.options(joinedload('_metadata'))
 
4369
    query = query.join('_hosts')
 
4370
    query = query.filter(models.AggregateHost.host == host)
4320
4371
 
4321
4372
    if key:
4322
4373
        query = query.join("_metadata").filter(
4326
4377
 
4327
4378
@require_admin_context
4328
4379
def aggregate_metadata_get_by_host(context, host, key=None):
4329
 
    query = model_query(context, models.Aggregate).join(
4330
 
            "_hosts").filter(models.AggregateHost.host == host).join(
4331
 
            "_metadata")
 
4380
    query = model_query(context, models.Aggregate)
 
4381
    query = query.join("_hosts")
 
4382
    query = query.join("_metadata")
 
4383
    query = query.filter(models.AggregateHost.host == host)
 
4384
    query = query.options(contains_eager("_metadata"))
4332
4385
 
4333
4386
    if key:
4334
4387
        query = query.filter(models.AggregateMetadata.key == key)
4335
4388
    rows = query.all()
 
4389
 
4336
4390
    metadata = collections.defaultdict(set)
4337
4391
    for agg in rows:
4338
4392
        for kv in agg._metadata:
4342
4396
 
4343
4397
@require_admin_context
4344
4398
def aggregate_host_get_by_metadata_key(context, key):
4345
 
    query = model_query(context, models.Aggregate).join(
4346
 
            "_metadata").filter(models.AggregateMetadata.key == key)
 
4399
    query = model_query(context, models.Aggregate)
 
4400
    query = query.join("_metadata")
 
4401
    query = query.filter(models.AggregateMetadata.key == key)
 
4402
    query = query.options(contains_eager("_metadata"))
 
4403
    query = query.options(joinedload("_hosts"))
4347
4404
    rows = query.all()
 
4405
 
4348
4406
    metadata = collections.defaultdict(set)
4349
4407
    for agg in rows:
4350
4408
        for agghost in agg._hosts: