~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/db/api.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
               default='instance-%08x',
61
61
               help='Template string to be used to generate instance names'),
62
62
    cfg.StrOpt('volume_name_template',
63
 
               default='volume-%08x',
 
63
               default='volume-%s',
64
64
               help='Template string to be used to generate instance names'),
65
65
    cfg.StrOpt('snapshot_name_template',
66
 
               default='snapshot-%08x',
 
66
               default='snapshot-%s',
67
67
               help='Template string to be used to generate snapshot names'),
68
68
    ]
69
69
 
74
74
                           sqlalchemy='nova.db.sqlalchemy.api')
75
75
 
76
76
 
77
 
class NoMoreNetworks(exception.Error):
 
77
class NoMoreNetworks(exception.NovaException):
78
78
    """No more available networks."""
79
79
    pass
80
80
 
81
81
 
82
 
class NoMoreTargets(exception.Error):
 
82
class NoMoreTargets(exception.NovaException):
83
83
    """No more available targets"""
84
84
    pass
85
85
 
251
251
    return IMPL.floating_ip_create(context, values)
252
252
 
253
253
 
254
 
def floating_ip_count_by_project(context, project_id):
 
254
def floating_ip_count_by_project(context, project_id, session=None):
255
255
    """Count floating ips used by project."""
256
 
    return IMPL.floating_ip_count_by_project(context, project_id)
 
256
    return IMPL.floating_ip_count_by_project(context, project_id,
 
257
                                             session=session)
257
258
 
258
259
 
259
260
def floating_ip_deallocate(context, address):
520
521
    return IMPL.instance_create(context, values)
521
522
 
522
523
 
523
 
def instance_data_get_for_project(context, project_id):
 
524
def instance_data_get_for_project(context, project_id, session=None):
524
525
    """Get (instance_count, total_cores, total_ram) for project."""
525
 
    return IMPL.instance_data_get_for_project(context, project_id)
 
526
    return IMPL.instance_data_get_for_project(context, project_id,
 
527
                                              session=session)
526
528
 
527
529
 
528
530
def instance_destroy(context, instance_id):
623
625
                                            security_group_id)
624
626
 
625
627
 
626
 
def instance_action_create(context, values):
627
 
    """Create an instance action from the values dictionary."""
628
 
    return IMPL.instance_action_create(context, values)
629
 
 
630
 
 
631
 
def instance_get_actions(context, instance_uuid):
632
 
    """Get instance actions by instance uuid."""
633
 
    return IMPL.instance_get_actions(context, instance_uuid)
634
 
 
635
 
 
636
628
def instance_get_id_to_uuid_mapping(context, ids):
637
629
    """Return a dictionary containing 'ID: UUID' given the ids"""
638
630
    return IMPL.instance_get_id_to_uuid_mapping(context, ids)
703
695
    return IMPL.key_pair_get_all_by_user(context, user_id)
704
696
 
705
697
 
 
698
def key_pair_count_by_user(context, user_id):
 
699
    """Count number of key pairs for the given user ID."""
 
700
    return IMPL.key_pair_count_by_user(context, user_id)
 
701
 
 
702
 
706
703
####################
707
704
 
708
705
 
905
902
    return IMPL.quota_destroy(context, project_id, resource)
906
903
 
907
904
 
 
905
###################
 
906
 
 
907
 
 
908
def quota_class_create(context, class_name, resource, limit):
 
909
    """Create a quota class for the given name and resource."""
 
910
    return IMPL.quota_class_create(context, class_name, resource, limit)
 
911
 
 
912
 
 
913
def quota_class_get(context, class_name, resource):
 
914
    """Retrieve a quota class or raise if it does not exist."""
 
915
    return IMPL.quota_class_get(context, class_name, resource)
 
916
 
 
917
 
 
918
def quota_class_get_all_by_name(context, class_name):
 
919
    """Retrieve all quotas associated with a given quota class."""
 
920
    return IMPL.quota_class_get_all_by_name(context, class_name)
 
921
 
 
922
 
 
923
def quota_class_update(context, class_name, resource, limit):
 
924
    """Update a quota class or raise if it does not exist."""
 
925
    return IMPL.quota_class_update(context, class_name, resource, limit)
 
926
 
 
927
 
 
928
def quota_class_destroy(context, class_name, resource):
 
929
    """Destroy the quota class or raise if it does not exist."""
 
930
    return IMPL.quota_class_destroy(context, class_name, resource)
 
931
 
 
932
 
 
933
def quota_class_destroy_all_by_name(context, class_name):
 
934
    """Destroy all quotas associated with a given quota class."""
 
935
    return IMPL.quota_class_destroy_all_by_name(context, class_name)
 
936
 
 
937
 
 
938
###################
 
939
 
 
940
 
 
941
def quota_usage_create(context, project_id, resource, in_use, reserved,
 
942
                       until_refresh):
 
943
    """Create a quota usage for the given project and resource."""
 
944
    return IMPL.quota_usage_create(context, project_id, resource,
 
945
                                   in_use, reserved, until_refresh)
 
946
 
 
947
 
 
948
def quota_usage_get(context, project_id, resource):
 
949
    """Retrieve a quota usage or raise if it does not exist."""
 
950
    return IMPL.quota_usage_get(context, project_id, resource)
 
951
 
 
952
 
 
953
def quota_usage_get_all_by_project(context, project_id):
 
954
    """Retrieve all usage associated with a given resource."""
 
955
    return IMPL.quota_usage_get_all_by_project(context, project_id)
 
956
 
 
957
 
 
958
def quota_usage_update(context, class_name, resource, in_use, reserved,
 
959
                       until_refresh):
 
960
    """Update a quota usage or raise if it does not exist."""
 
961
    return IMPL.quota_usage_update(context, project_id, resource,
 
962
                                   in_use, reserved, until_refresh)
 
963
 
 
964
 
 
965
def quota_usage_destroy(context, project_id, resource):
 
966
    """Destroy the quota usage or raise if it does not exist."""
 
967
    return IMPL.quota_usage_destroy(context, project_id, resource)
 
968
 
 
969
 
 
970
###################
 
971
 
 
972
 
 
973
def reservation_create(context, uuid, usage, project_id, resource, delta,
 
974
                       expire):
 
975
    """Create a reservation for the given project and resource."""
 
976
    return IMPL.reservation_create(context, uuid, usage, project_id,
 
977
                                   resource, delta, expire)
 
978
 
 
979
 
 
980
def reservation_get(context, uuid):
 
981
    """Retrieve a reservation or raise if it does not exist."""
 
982
    return IMPL.reservation_get(context, uuid)
 
983
 
 
984
 
 
985
def reservation_get_all_by_project(context, project_id):
 
986
    """Retrieve all reservations associated with a given project."""
 
987
    return IMPL.reservation_get_all_by_project(context, project_id)
 
988
 
 
989
 
 
990
def reservation_destroy(context, uuid):
 
991
    """Destroy the reservation or raise if it does not exist."""
 
992
    return IMPL.reservation_destroy(context, uuid)
 
993
 
 
994
 
 
995
###################
 
996
 
 
997
 
 
998
def quota_reserve(context, resources, quotas, deltas, expire,
 
999
                  until_refresh, max_age):
 
1000
    """Check quotas and create appropriate reservations."""
 
1001
    return IMPL.quota_reserve(context, resources, quotas, deltas, expire,
 
1002
                              until_refresh, max_age)
 
1003
 
 
1004
 
 
1005
def reservation_commit(context, reservations):
 
1006
    """Commit quota reservations."""
 
1007
    return IMPL.reservation_commit(context, reservations)
 
1008
 
 
1009
 
 
1010
def reservation_rollback(context, reservations):
 
1011
    """Roll back quota reservations."""
 
1012
    return IMPL.reservation_rollback(context, reservations)
 
1013
 
 
1014
 
908
1015
def quota_destroy_all_by_project(context, project_id):
909
1016
    """Destroy all quotas associated with a given project."""
910
1017
    return IMPL.quota_get_all_by_project(context, project_id)
911
1018
 
912
1019
 
 
1020
def reservation_expire(context):
 
1021
    """Roll back any expired reservations."""
 
1022
    return IMPL.reservation_expire(context)
 
1023
 
 
1024
 
913
1025
###################
914
1026
 
915
1027
 
928
1040
    return IMPL.volume_create(context, values)
929
1041
 
930
1042
 
931
 
def volume_data_get_for_project(context, project_id):
 
1043
def volume_data_get_for_project(context, project_id, session=None):
932
1044
    """Get (volume_count, gigabytes) for project."""
933
 
    return IMPL.volume_data_get_for_project(context, project_id)
 
1045
    return IMPL.volume_data_get_for_project(context, project_id,
 
1046
                                            session=session)
934
1047
 
935
1048
 
936
1049
def volume_destroy(context, volume_id):
958
1071
    return IMPL.volume_get_all_by_host(context, host)
959
1072
 
960
1073
 
961
 
def volume_get_all_by_instance(context, instance_id):
 
1074
def volume_get_all_by_instance_uuid(context, instance_uuid):
962
1075
    """Get all volumes belonging to a instance."""
963
 
    return IMPL.volume_get_all_by_instance(context, instance_id)
 
1076
    return IMPL.volume_get_all_by_instance_uuid(context, instance_uuid)
964
1077
 
965
1078
 
966
1079
def volume_get_all_by_project(context, project_id):
973
1086
    return IMPL.volume_get_by_ec2_id(context, ec2_id)
974
1087
 
975
1088
 
976
 
def volume_get_instance(context, volume_id):
977
 
    """Get the instance that a volume is attached to."""
978
 
    return IMPL.volume_get_instance(context, volume_id)
979
 
 
980
 
 
981
1089
def volume_get_iscsi_target_num(context, volume_id):
982
1090
    """Get the target num (tid) allocated to the volume."""
983
1091
    return IMPL.volume_get_iscsi_target_num(context, volume_id)
992
1100
    return IMPL.volume_update(context, volume_id, values)
993
1101
 
994
1102
 
 
1103
def get_ec2_volume_id_by_uuid(context, volume_id):
 
1104
    return IMPL.get_ec2_volume_id_by_uuid(context, volume_id)
 
1105
 
 
1106
 
 
1107
def get_volume_uuid_by_ec2_id(context, ec2_id):
 
1108
    return IMPL.get_volume_uuid_by_ec2_id(context, ec2_id)
 
1109
 
 
1110
 
 
1111
def ec2_volume_create(context, volume_id, forced_id=None):
 
1112
    return IMPL.ec2_volume_create(context, volume_id, forced_id)
 
1113
 
 
1114
 
 
1115
def get_snapshot_uuid_by_ec2_id(context, ec2_id):
 
1116
    return IMPL.get_snapshot_uuid_by_ec2_id(context, ec2_id)
 
1117
 
 
1118
 
 
1119
def get_ec2_snapshot_id_by_uuid(context, snapshot_id):
 
1120
    return IMPL.get_ec2_snapshot_id_by_uuid(context, snapshot_id)
 
1121
 
995
1122
####################
996
1123
 
997
1124
 
1053
1180
    return IMPL.block_device_mapping_update_or_create(context, values)
1054
1181
 
1055
1182
 
1056
 
def block_device_mapping_get_all_by_instance(context, instance_id):
 
1183
def block_device_mapping_get_all_by_instance(context, instance_uuid):
1057
1184
    """Get all block device mapping belonging to a instance"""
1058
 
    return IMPL.block_device_mapping_get_all_by_instance(context, instance_id)
 
1185
    return IMPL.block_device_mapping_get_all_by_instance(context,
 
1186
                                                         instance_uuid)
1059
1187
 
1060
1188
 
1061
1189
def block_device_mapping_destroy(context, bdm_id):
1063
1191
    return IMPL.block_device_mapping_destroy(context, bdm_id)
1064
1192
 
1065
1193
 
1066
 
def block_device_mapping_destroy_by_instance_and_volume(context, instance_id,
 
1194
def block_device_mapping_destroy_by_instance_and_volume(context, instance_uuid,
1067
1195
                                                        volume_id):
1068
1196
    """Destroy the block device mapping or raise if it does not exist."""
1069
1197
    return IMPL.block_device_mapping_destroy_by_instance_and_volume(
1070
 
        context, instance_id, volume_id)
 
1198
        context, instance_uuid, volume_id)
1071
1199
 
1072
1200
 
1073
1201
####################
1118
1246
    return IMPL.security_group_destroy(context, security_group_id)
1119
1247
 
1120
1248
 
1121
 
def security_group_count_by_project(context, project_id):
 
1249
def security_group_count_by_project(context, project_id, session=None):
1122
1250
    """Count number of security groups in a project."""
1123
 
    return IMPL.security_group_count_by_project(context, project_id)
 
1251
    return IMPL.security_group_count_by_project(context, project_id,
 
1252
                                                session=session)
1124
1253
 
1125
1254
 
1126
1255
####################
1435
1564
####################
1436
1565
 
1437
1566
 
 
1567
def instance_system_metadata_get(context, instance_uuid):
 
1568
    """Get all system metadata for an instance."""
 
1569
    return IMPL.instance_system_metadata_get(context, instance_uuid)
 
1570
 
 
1571
 
 
1572
def instance_system_metadata_delete(context, instance_uuid, key):
 
1573
    """Delete the given system metadata item."""
 
1574
    IMPL.instance_system_metadata_delete(context, instance_uuid, key)
 
1575
 
 
1576
 
 
1577
def instance_system_metadata_update(context, instance_uuid, metadata, delete):
 
1578
    """Update metadata if it exists, otherwise create it."""
 
1579
    IMPL.instance_system_metadata_update(
 
1580
            context, instance_uuid, metadata, delete)
 
1581
 
 
1582
 
 
1583
####################
 
1584
 
 
1585
 
1438
1586
def agent_build_create(context, values):
1439
1587
    """Create a new agent build entry."""
1440
1588
    return IMPL.agent_build_create(context, values)
1464
1612
####################
1465
1613
 
1466
1614
 
1467
 
def bw_usage_get_by_macs(context, macs, start_period):
1468
 
    """Return bw usages for an instance in a given audit period."""
1469
 
    return IMPL.bw_usage_get_by_macs(context, macs, start_period)
 
1615
def bw_usage_get_by_uuids(context, uuids, start_period):
 
1616
    """Return bw usages for instance(s) in a given audit period."""
 
1617
    return IMPL.bw_usage_get_by_uuids(context, uuids, start_period)
1470
1618
 
1471
1619
 
1472
1620
def bw_usage_update(context,
 
1621
                    uuid,
1473
1622
                    mac,
1474
1623
                    start_period,
1475
1624
                    bw_in, bw_out):
1476
1625
    """Update cached bw usage for an instance and network
1477
1626
       Creates new record if needed."""
1478
1627
    return IMPL.bw_usage_update(context,
 
1628
                                uuid,
1479
1629
                                mac,
1480
1630
                                start_period,
1481
1631
                                bw_in, bw_out)
1548
1698
    return IMPL.volume_type_destroy(context, name)
1549
1699
 
1550
1700
 
 
1701
def volume_get_active_by_window(context, begin, end=None, project_id=None):
 
1702
    """Get all the volumes inside the window.
 
1703
 
 
1704
    Specifying a project_id will filter for a certain project."""
 
1705
    return IMPL.volume_get_active_by_window(context, begin, end, project_id)
 
1706
 
 
1707
 
1551
1708
####################
1552
1709
 
1553
1710
 
1684
1841
    return IMPL.aggregate_create(context, values, metadata)
1685
1842
 
1686
1843
 
1687
 
def aggregate_get(context, aggregate_id, read_deleted='no'):
 
1844
def aggregate_get(context, aggregate_id):
1688
1845
    """Get a specific aggregate by id."""
1689
 
    return IMPL.aggregate_get(context, aggregate_id, read_deleted)
1690
 
 
1691
 
 
1692
 
def aggregate_get_by_host(context, host, read_deleted='no'):
 
1846
    return IMPL.aggregate_get(context, aggregate_id)
 
1847
 
 
1848
 
 
1849
def aggregate_get_by_host(context, host):
1693
1850
    """Get a specific aggregate by host"""
1694
 
    return IMPL.aggregate_get_by_host(context, host, read_deleted)
 
1851
    return IMPL.aggregate_get_by_host(context, host)
1695
1852
 
1696
1853
 
1697
1854
def aggregate_update(context, aggregate_id, values):
1705
1862
    return IMPL.aggregate_delete(context, aggregate_id)
1706
1863
 
1707
1864
 
1708
 
def aggregate_get_all(context, read_deleted='yes'):
 
1865
def aggregate_get_all(context):
1709
1866
    """Get all aggregates."""
1710
 
    return IMPL.aggregate_get_all(context, read_deleted)
 
1867
    return IMPL.aggregate_get_all(context)
1711
1868
 
1712
1869
 
1713
1870
def aggregate_metadata_add(context, aggregate_id, metadata, set_delete=False):
1715
1872
    IMPL.aggregate_metadata_add(context, aggregate_id, metadata, set_delete)
1716
1873
 
1717
1874
 
1718
 
def aggregate_metadata_get(context, aggregate_id, read_deleted='no'):
 
1875
def aggregate_metadata_get(context, aggregate_id):
1719
1876
    """Get metadata for the specified aggregate."""
1720
 
    return IMPL.aggregate_metadata_get(context, aggregate_id, read_deleted)
 
1877
    return IMPL.aggregate_metadata_get(context, aggregate_id)
1721
1878
 
1722
1879
 
1723
1880
def aggregate_metadata_delete(context, aggregate_id, key):
1730
1887
    IMPL.aggregate_host_add(context, aggregate_id, host)
1731
1888
 
1732
1889
 
1733
 
def aggregate_host_get_all(context, aggregate_id, read_deleted='yes'):
 
1890
def aggregate_host_get_all(context, aggregate_id):
1734
1891
    """Get hosts for the specified aggregate."""
1735
 
    return IMPL.aggregate_host_get_all(context, aggregate_id, read_deleted)
 
1892
    return IMPL.aggregate_host_get_all(context, aggregate_id)
1736
1893
 
1737
1894
 
1738
1895
def aggregate_host_delete(context, aggregate_id, host):