~tr3buchet/nova/lock

« back to all changes in this revision

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

  • Committer: Vishvananda Ishaya
  • Date: 2010-12-22 20:59:53 UTC
  • mto: This revision was merged to the branch mainline in revision 482.
  • Revision ID: vishvananda@gmail.com-20101222205953-j2j5t0qjwlcd0t2s
merge trunk and upgrade to cheetah templating

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
def is_admin_context(context):
42
42
    """Indicates if the request context is an administrator."""
43
43
    if not context:
44
 
        warnings.warn('Use of empty request context is deprecated',
 
44
        warnings.warn(_('Use of empty request context is deprecated'),
45
45
                      DeprecationWarning)
46
46
        raise Exception('die')
47
47
    return context.is_admin
130
130
                     first()
131
131
 
132
132
    if not result:
133
 
        raise exception.NotFound('No service for id %s' % service_id)
 
133
        raise exception.NotFound(_('No service for id %s') % service_id)
134
134
 
135
135
    return result
136
136
 
227
227
                     filter_by(deleted=can_read_deleted(context)).\
228
228
                     first()
229
229
    if not result:
230
 
        raise exception.NotFound('No service for %s, %s' % (host, binary))
 
230
        raise exception.NotFound(_('No service for %s, %s') % (host, binary))
231
231
 
232
232
    return result
233
233
 
491
491
                     options(joinedload('instance')).\
492
492
                     first()
493
493
    if not result:
494
 
        raise exception.NotFound('No floating ip for address %s' % address)
 
494
        raise exception.NotFound(_('No floating ip for address %s') % address)
495
495
 
496
496
    if is_user_context(context):
497
497
        authorize_project_context(context, result.instance.project_id)
528
528
#TODO(gundlach): instance_create and volume_create are nearly identical
529
529
#and should be refactored.  I expect there are other copy-and-paste
530
530
#functions between the two of them as well.
 
531
 
 
532
 
531
533
@require_context
532
534
def instance_create(context, values):
533
535
    """Create a new Instance record in the database.
591
593
                         filter_by(deleted=False).\
592
594
                         first()
593
595
    if not result:
594
 
        raise exception.NotFound('No instance for id %s' % instance_id)
 
596
        raise exception.NotFound(_('No instance for id %s') % instance_id)
595
597
 
596
598
    return result
597
599
 
669
671
                         filter_by(deleted=False).\
670
672
                         first()
671
673
    if not result:
672
 
        raise exception.NotFound('Instance %s not found' % (internal_id))
 
674
        raise exception.NotFound(_('Instance %s not found') % (internal_id))
673
675
 
674
676
    return result
675
677
 
747
749
        instance_ref.save(session=session)
748
750
 
749
751
 
 
752
@require_context
 
753
def instance_action_create(context, values):
 
754
    """Create an instance action from the values dictionary."""
 
755
    action_ref = models.InstanceActions()
 
756
    action_ref.update(values)
 
757
 
 
758
    session = get_session()
 
759
    with session.begin():
 
760
        action_ref.save(session=session)
 
761
    return action_ref
 
762
 
 
763
 
750
764
###################
751
765
 
752
766
 
790
804
                     filter_by(deleted=can_read_deleted(context)).\
791
805
                     first()
792
806
    if not result:
793
 
        raise exception.NotFound('no keypair for user %s, name %s' %
 
807
        raise exception.NotFound(_('no keypair for user %s, name %s') %
794
808
                                 (user_id, name))
795
809
    return result
796
810
 
905
919
                         filter_by(deleted=False).\
906
920
                         first()
907
921
    if not result:
908
 
        raise exception.NotFound('No network for id %s' % network_id)
 
922
        raise exception.NotFound(_('No network for id %s') % network_id)
909
923
 
910
924
    return result
911
925
 
913
927
# NOTE(vish): pylint complains because of the long method name, but
914
928
#             it fits with the names of the rest of the methods
915
929
# pylint: disable-msg=C0103
 
930
 
 
931
 
916
932
@require_admin_context
917
933
def network_get_associated_fixed_ips(context, network_id):
918
934
    session = get_session()
933
949
                 first()
934
950
 
935
951
    if not result:
936
 
        raise exception.NotFound('No network for bridge %s' % bridge)
 
952
        raise exception.NotFound(_('No network for bridge %s') % bridge)
937
953
    return result
938
954
 
939
955
 
947
963
                 filter_by(deleted=False).\
948
964
                 first()
949
965
    if not rv:
950
 
        raise exception.NotFound('No network for instance %s' % instance_id)
 
966
        raise exception.NotFound(_('No network for instance %s') % instance_id)
951
967
    return rv
952
968
 
953
969
 
961
977
                              with_lockmode('update').\
962
978
                              first()
963
979
        if not network_ref:
964
 
            raise exception.NotFound('No network for id %s' % network_id)
 
980
            raise exception.NotFound(_('No network for id %s') % network_id)
965
981
 
966
982
        # NOTE(vish): if with_lockmode isn't supported, as in sqlite,
967
983
        #             then this has concurrency issues
1073
1089
                  filter_by(token_hash=token_hash).\
1074
1090
                  first()
1075
1091
    if not tk:
1076
 
        raise exception.NotFound('Token %s does not exist' % token_hash)
 
1092
        raise exception.NotFound(_('Token %s does not exist') % token_hash)
1077
1093
    return tk
1078
1094
 
1079
1095
 
1097
1113
                     filter_by(deleted=can_read_deleted(context)).\
1098
1114
                     first()
1099
1115
    if not result:
1100
 
        raise exception.NotFound('No quota for project_id %s' % project_id)
 
1116
        raise exception.NotFound(_('No quota for project_id %s') % project_id)
1101
1117
 
1102
1118
    return result
1103
1119
 
1252
1268
                         filter_by(deleted=False).\
1253
1269
                         first()
1254
1270
    if not result:
1255
 
        raise exception.NotFound('No volume for id %s' % volume_id)
 
1271
        raise exception.NotFound(_('No volume for id %s') % volume_id)
1256
1272
 
1257
1273
    return result
1258
1274
 
1308
1324
        raise exception.NotAuthorized()
1309
1325
 
1310
1326
    if not result:
1311
 
        raise exception.NotFound('Volume %s not found' % ec2_id)
 
1327
        raise exception.NotFound(_('Volume %s not found') % ec2_id)
1312
1328
 
1313
1329
    return result
1314
1330
 
1332
1348
                     options(joinedload('instance')).\
1333
1349
                     first()
1334
1350
    if not result:
1335
 
        raise exception.NotFound('Volume %s not found' % ec2_id)
 
1351
        raise exception.NotFound(_('Volume %s not found') % ec2_id)
1336
1352
 
1337
1353
    return result.instance
1338
1354
 
1344
1360
                     filter_by(volume_id=volume_id).\
1345
1361
                     first()
1346
1362
    if not result:
1347
 
        raise exception.NotFound('No export device found for volume %s' %
 
1363
        raise exception.NotFound(_('No export device found for volume %s') %
1348
1364
                                 volume_id)
1349
1365
 
1350
1366
    return (result.shelf_id, result.blade_id)
1357
1373
                     filter_by(volume_id=volume_id).\
1358
1374
                     first()
1359
1375
    if not result:
1360
 
        raise exception.NotFound('No target id found for volume %s' %
 
1376
        raise exception.NotFound(_('No target id found for volume %s') %
1361
1377
                                 volume_id)
1362
1378
 
1363
1379
    return result.target_num
1402
1418
                         options(joinedload_all('rules')).\
1403
1419
                         first()
1404
1420
    if not result:
1405
 
        raise exception.NotFound("No secuity group with id %s" %
 
1421
        raise exception.NotFound(_("No security group with id %s") %
1406
1422
                                 security_group_id)
1407
1423
    return result
1408
1424
 
1419
1435
                        first()
1420
1436
    if not result:
1421
1437
        raise exception.NotFound(
1422
 
            'No security group named %s for project: %s' \
 
1438
            _('No security group named %s for project: %s')
1423
1439
             % (group_name, project_id))
1424
1440
    return result
1425
1441
 
1507
1523
                         filter_by(id=security_group_rule_id).\
1508
1524
                         first()
1509
1525
    if not result:
1510
 
        raise exception.NotFound("No secuity group rule with id %s" %
 
1526
        raise exception.NotFound(_("No secuity group rule with id %s") %
1511
1527
                                 security_group_rule_id)
1512
1528
    return result
1513
1529
 
1543
1559
                     first()
1544
1560
 
1545
1561
    if not result:
1546
 
        raise exception.NotFound('No user for id %s' % id)
 
1562
        raise exception.NotFound(_('No user for id %s') % id)
1547
1563
 
1548
1564
    return result
1549
1565
 
1559
1575
                   first()
1560
1576
 
1561
1577
    if not result:
1562
 
        raise exception.NotFound('No user for access key %s' % access_key)
 
1578
        raise exception.NotFound(_('No user for access key %s') % access_key)
1563
1579
 
1564
1580
    return result
1565
1581
 
1621
1637
                     first()
1622
1638
 
1623
1639
    if not result:
1624
 
        raise exception.NotFound("No project with id %s" % id)
 
1640
        raise exception.NotFound(_("No project with id %s") % id)
1625
1641
 
1626
1642
    return result
1627
1643