~ubuntu-branches/ubuntu/quantal/nova/quantal-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-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
232
232
    return IMPL.compute_node_utilization_set(context, host, free_ram_mb,
233
233
                                             free_disk_gb, work, vms)
234
234
 
 
235
 
 
236
def compute_node_statistics(context):
 
237
    return IMPL.compute_node_statistics(context)
 
238
 
 
239
 
235
240
###################
236
241
 
237
242
 
277
282
    return IMPL.floating_ip_allocate_address(context, project_id, pool)
278
283
 
279
284
 
 
285
def floating_ip_bulk_create(context, ips):
 
286
    """Create a lot of floating ips from the values dictionary."""
 
287
    return IMPL.floating_ip_bulk_create(context, ips)
 
288
 
 
289
 
280
290
def floating_ip_create(context, values):
281
291
    """Create a floating ip from the values dictionary."""
282
292
    return IMPL.floating_ip_create(context, values)
405
415
            status)
406
416
 
407
417
 
408
 
def migration_get_all_unconfirmed(context, confirm_window):
409
 
    """Finds all unconfirmed migrations within the confirmation window."""
410
 
    return IMPL.migration_get_all_unconfirmed(context, confirm_window)
 
418
def migration_get_unconfirmed_by_dest_compute(context, confirm_window,
 
419
        dest_compute):
 
420
    """
 
421
    Finds all unconfirmed migrations within the confirmation window for
 
422
    a specific destination compute host.
 
423
    """
 
424
    return IMPL.migration_get_unconfirmed_by_dest_compute(context,
 
425
            confirm_window, dest_compute)
411
426
 
412
427
 
413
428
####################
414
429
 
415
430
 
416
 
def fixed_ip_associate(context, address, instance_id, network_id=None,
 
431
def fixed_ip_associate(context, address, instance_uuid, network_id=None,
417
432
                       reserved=False):
418
433
    """Associate fixed ip to instance.
419
434
 
420
435
    Raises if fixed ip is not available.
421
436
 
422
437
    """
423
 
    return IMPL.fixed_ip_associate(context, address, instance_id, network_id,
 
438
    return IMPL.fixed_ip_associate(context, address, instance_uuid, network_id,
424
439
                                   reserved)
425
440
 
426
441
 
427
 
def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None):
 
442
def fixed_ip_associate_pool(context, network_id, instance_uuid=None,
 
443
                            host=None):
428
444
    """Find free ip in network and associate it to instance or host.
429
445
 
430
446
    Raises if one is not available.
431
447
 
432
448
    """
433
449
    return IMPL.fixed_ip_associate_pool(context, network_id,
434
 
                                        instance_id, host)
 
450
                                        instance_uuid, host)
435
451
 
436
452
 
437
453
def fixed_ip_create(context, values):
469
485
    return IMPL.fixed_ip_get_by_address(context, address)
470
486
 
471
487
 
472
 
def fixed_ip_get_by_instance(context, instance_id):
 
488
def fixed_ip_get_by_instance(context, instance_uuid):
473
489
    """Get fixed ips by instance or raise if none exist."""
474
 
    return IMPL.fixed_ip_get_by_instance(context, instance_id)
475
 
 
476
 
 
477
 
def fixed_ip_get_by_network_host(context, network_id, host):
 
490
    return IMPL.fixed_ip_get_by_instance(context, instance_uuid)
 
491
 
 
492
 
 
493
def fixed_ip_get_by_network_host(context, network_uuid, host):
478
494
    """Get fixed ip for a host in a network."""
479
 
    return IMPL.fixed_ip_get_by_network_host(context, network_id, host)
 
495
    return IMPL.fixed_ip_get_by_network_host(context, network_uuid, host)
480
496
 
481
497
 
482
498
def fixed_ips_by_virtual_interface(context, vif_id):
585
601
                                            sort_dir)
586
602
 
587
603
 
588
 
def instance_get_active_by_window(context, begin, end=None, project_id=None):
 
604
def instance_get_active_by_window(context, begin, end=None, project_id=None,
 
605
                                  host=None):
589
606
    """Get instances active during a certain time window.
590
607
 
591
 
    Specifying a project_id will filter for a certain project."""
592
 
    return IMPL.instance_get_active_by_window(context, begin, end, project_id)
 
608
    Specifying a project_id will filter for a certain project.
 
609
    Specifying a host will filter for instances on a given compute host.
 
610
    """
 
611
    return IMPL.instance_get_active_by_window(context, begin, end,
 
612
                                              project_id, host)
593
613
 
594
614
 
595
615
def instance_get_active_by_window_joined(context, begin, end=None,
596
 
                                         project_id=None):
 
616
                                         project_id=None, host=None):
597
617
    """Get instances and joins active during a certain time window.
598
618
 
599
 
    Specifying a project_id will filter for a certain project."""
 
619
    Specifying a project_id will filter for a certain project.
 
620
    Specifying a host will filter for instances on a given compute host.
 
621
    """
600
622
    return IMPL.instance_get_active_by_window_joined(context, begin, end,
601
 
                                              project_id)
 
623
                                              project_id, host)
602
624
 
603
625
 
604
626
def instance_get_all_by_project(context, project_id):
756
778
####################
757
779
 
758
780
 
759
 
def network_associate(context, project_id, force=False):
 
781
def network_associate(context, project_id, network_id=None, force=False):
760
782
    """Associate a free network to a project."""
761
 
    return IMPL.network_associate(context, project_id, force)
 
783
    return IMPL.network_associate(context, project_id, network_id, force)
762
784
 
763
785
 
764
786
def network_count(context):
899
921
###############
900
922
 
901
923
 
902
 
def auth_token_destroy(context, token_id):
903
 
    """Destroy an auth token."""
904
 
    return IMPL.auth_token_destroy(context, token_id)
905
 
 
906
 
 
907
 
def auth_token_get(context, token_hash):
908
 
    """Retrieves a token given the hash representing it."""
909
 
    return IMPL.auth_token_get(context, token_hash)
910
 
 
911
 
 
912
 
def auth_token_update(context, token_hash, values):
913
 
    """Updates a token given the hash representing it."""
914
 
    return IMPL.auth_token_update(context, token_hash, values)
915
 
 
916
 
 
917
 
def auth_token_create(context, token):
918
 
    """Creates a new token."""
919
 
    return IMPL.auth_token_create(context, token)
920
 
 
921
 
 
922
 
###################
923
 
 
924
 
 
925
924
def quota_create(context, project_id, resource, limit):
926
925
    """Create a quota for the given project and resource."""
927
926
    return IMPL.quota_create(context, project_id, resource, limit)
1059
1058
 
1060
1059
def quota_destroy_all_by_project(context, project_id):
1061
1060
    """Destroy all quotas associated with a given project."""
1062
 
    return IMPL.quota_get_all_by_project(context, project_id)
 
1061
    return IMPL.quota_destroy_all_by_project(context, project_id)
1063
1062
 
1064
1063
 
1065
1064
def reservation_expire(context):
1241
1240
    return IMPL.block_device_mapping_destroy(context, bdm_id)
1242
1241
 
1243
1242
 
 
1243
def block_device_mapping_destroy_by_instance_and_device(context, instance_uuid,
 
1244
                                                        device_name):
 
1245
    """Destroy the block device mapping."""
 
1246
    return IMPL.block_device_mapping_destroy_by_instance_and_device(
 
1247
        context, instance_uuid, device_name)
 
1248
 
 
1249
 
1244
1250
def block_device_mapping_destroy_by_instance_and_volume(context, instance_uuid,
1245
1251
                                                        volume_id):
1246
 
    """Destroy the block device mapping or raise if it does not exist."""
 
1252
    """Destroy the block device mapping."""
1247
1253
    return IMPL.block_device_mapping_destroy_by_instance_and_volume(
1248
1254
        context, instance_uuid, volume_id)
1249
1255
 
1364
1370
###################
1365
1371
 
1366
1372
 
1367
 
def user_get(context, id):
1368
 
    """Get user by id."""
1369
 
    return IMPL.user_get(context, id)
1370
 
 
1371
 
 
1372
 
def user_get_by_access_key(context, access_key):
1373
 
    """Get user by access key."""
1374
 
    return IMPL.user_get_by_access_key(context, access_key)
1375
 
 
1376
 
 
1377
 
def user_create(context, values):
1378
 
    """Create a new user."""
1379
 
    return IMPL.user_create(context, values)
1380
 
 
1381
 
 
1382
 
def user_delete(context, id):
1383
 
    """Delete a user."""
1384
 
    return IMPL.user_delete(context, id)
1385
 
 
1386
 
 
1387
 
def user_get_all(context):
1388
 
    """Create a new user."""
1389
 
    return IMPL.user_get_all(context)
1390
 
 
1391
 
 
1392
 
def user_add_role(context, user_id, role):
1393
 
    """Add another global role for user."""
1394
 
    return IMPL.user_add_role(context, user_id, role)
1395
 
 
1396
 
 
1397
 
def user_remove_role(context, user_id, role):
1398
 
    """Remove global role from user."""
1399
 
    return IMPL.user_remove_role(context, user_id, role)
1400
 
 
1401
 
 
1402
 
def user_get_roles(context, user_id):
1403
 
    """Get global roles for user."""
1404
 
    return IMPL.user_get_roles(context, user_id)
1405
 
 
1406
 
 
1407
 
def user_add_project_role(context, user_id, project_id, role):
1408
 
    """Add project role for user."""
1409
 
    return IMPL.user_add_project_role(context, user_id, project_id, role)
1410
 
 
1411
 
 
1412
 
def user_remove_project_role(context, user_id, project_id, role):
1413
 
    """Remove project role from user."""
1414
 
    return IMPL.user_remove_project_role(context, user_id, project_id, role)
1415
 
 
1416
 
 
1417
 
def user_get_roles_for_project(context, user_id, project_id):
1418
 
    """Return list of roles a user holds on project."""
1419
 
    return IMPL.user_get_roles_for_project(context, user_id, project_id)
1420
 
 
1421
 
 
1422
 
def user_update(context, user_id, values):
1423
 
    """Update user."""
1424
 
    return IMPL.user_update(context, user_id, values)
1425
 
 
1426
 
 
1427
 
###################
1428
 
 
1429
 
 
1430
 
def project_get(context, id):
1431
 
    """Get project by id."""
1432
 
    return IMPL.project_get(context, id)
1433
 
 
1434
 
 
1435
 
def project_create(context, values):
1436
 
    """Create a new project."""
1437
 
    return IMPL.project_create(context, values)
1438
 
 
1439
 
 
1440
 
def project_add_member(context, project_id, user_id):
1441
 
    """Add user to project."""
1442
 
    return IMPL.project_add_member(context, project_id, user_id)
1443
 
 
1444
 
 
1445
 
def project_get_all(context):
1446
 
    """Get all projects."""
1447
 
    return IMPL.project_get_all(context)
1448
 
 
1449
 
 
1450
 
def project_get_by_user(context, user_id):
1451
 
    """Get all projects of which the given user is a member."""
1452
 
    return IMPL.project_get_by_user(context, user_id)
1453
 
 
1454
 
 
1455
 
def project_remove_member(context, project_id, user_id):
1456
 
    """Remove the given user from the given project."""
1457
 
    return IMPL.project_remove_member(context, project_id, user_id)
1458
 
 
1459
 
 
1460
 
def project_update(context, project_id, values):
1461
 
    """Update Remove the given user from the given project."""
1462
 
    return IMPL.project_update(context, project_id, values)
1463
 
 
1464
 
 
1465
 
def project_delete(context, project_id):
1466
 
    """Delete project."""
1467
 
    return IMPL.project_delete(context, project_id)
1468
 
 
1469
 
 
1470
1373
def project_get_networks(context, project_id, associate=True):
1471
1374
    """Return the network associated with the project.
1472
1375
 
1551
1454
 
1552
1455
 
1553
1456
def instance_type_get_by_flavor_id(context, id):
1554
 
    """Get instance type by name."""
 
1457
    """Get instance type by flavor id."""
1555
1458
    return IMPL.instance_type_get_by_flavor_id(context, id)
1556
1459
 
1557
1460
 
1634
1537
    return IMPL.bw_usage_get_by_uuids(context, uuids, start_period)
1635
1538
 
1636
1539
 
1637
 
def bw_usage_update(context,
1638
 
                    uuid,
1639
 
                    mac,
1640
 
                    start_period,
1641
 
                    bw_in, bw_out):
1642
 
    """Update cached bw usage for an instance and network
1643
 
       Creates new record if needed."""
1644
 
    return IMPL.bw_usage_update(context,
1645
 
                                uuid,
1646
 
                                mac,
1647
 
                                start_period,
1648
 
                                bw_in, bw_out)
 
1540
def bw_usage_update(context, uuid, mac, start_period, bw_in, bw_out,
 
1541
                    last_refreshed=None):
 
1542
    """Update cached bandwidth usage for an instance's network based on mac
 
1543
    address.  Creates new record if needed.
 
1544
    """
 
1545
    return IMPL.bw_usage_update(context, uuid, mac, start_period, bw_in,
 
1546
            bw_out, last_refreshed=last_refreshed)
1649
1547
 
1650
1548
 
1651
1549
####################
1652
1550
 
1653
1551
 
1654
 
def instance_type_extra_specs_get(context, instance_type_id):
 
1552
def instance_type_extra_specs_get(context, flavor_id):
1655
1553
    """Get all extra specs for an instance type."""
1656
 
    return IMPL.instance_type_extra_specs_get(context, instance_type_id)
1657
 
 
1658
 
 
1659
 
def instance_type_extra_specs_delete(context, instance_type_id, key):
 
1554
    return IMPL.instance_type_extra_specs_get(context, flavor_id)
 
1555
 
 
1556
 
 
1557
def instance_type_extra_specs_delete(context, flavor_id, key):
1660
1558
    """Delete the given extra specs item."""
1661
 
    IMPL.instance_type_extra_specs_delete(context, instance_type_id, key)
1662
 
 
1663
 
 
1664
 
def instance_type_extra_specs_update_or_create(context, instance_type_id,
 
1559
    IMPL.instance_type_extra_specs_delete(context, flavor_id, key)
 
1560
 
 
1561
 
 
1562
def instance_type_extra_specs_update_or_create(context, flavor_id,
1665
1563
                                               extra_specs):
1666
1564
    """Create or update instance type extra specs. This adds or modifies the
1667
1565
    key/value pairs specified in the extra specs dict argument"""
1668
 
    IMPL.instance_type_extra_specs_update_or_create(context, instance_type_id,
 
1566
    IMPL.instance_type_extra_specs_update_or_create(context, flavor_id,
1669
1567
                                                    extra_specs)
1670
1568
 
1671
1569
 
1868
1766
    return IMPL.aggregate_get(context, aggregate_id)
1869
1767
 
1870
1768
 
1871
 
def aggregate_get_by_host(context, host):
1872
 
    """Get a specific aggregate by host"""
1873
 
    return IMPL.aggregate_get_by_host(context, host)
 
1769
def aggregate_get_by_host(context, host, key=None):
 
1770
    """Get a list of aggregates that host belongs to"""
 
1771
    return IMPL.aggregate_get_by_host(context, host, key)
 
1772
 
 
1773
 
 
1774
def aggregate_metadata_get_by_host(context, host, key=None):
 
1775
    """Get metadata for all aggregates that host belongs to.
 
1776
 
 
1777
    Returns a dictionary where each value is a set, this is to cover the case
 
1778
    where there two aggregates have different values for the same key.
 
1779
    Optional key filter"""
 
1780
    return IMPL.aggregate_metadata_get_by_host(context, host, key)
1874
1781
 
1875
1782
 
1876
1783
def aggregate_update(context, aggregate_id, values):
1940
1847
    return IMPL.get_ec2_instance_id_by_uuid(context, instance_id)
1941
1848
 
1942
1849
 
1943
 
def get_instance_uuid_by_ec2_id(context, instance_id):
 
1850
def get_instance_uuid_by_ec2_id(context, ec2_id):
1944
1851
    """Get uuid through ec2 id from instance_id_mappings table"""
1945
 
    return IMPL.get_instance_uuid_by_ec2_id(context, instance_id)
 
1852
    return IMPL.get_instance_uuid_by_ec2_id(context, ec2_id)
1946
1853
 
1947
1854
 
1948
1855
def ec2_instance_create(context, instance_ec2_id):
1949
1856
    """Create the ec2 id to instance uuid mapping on demand"""
1950
1857
    return IMPL.ec2_instance_create(context, instance_ec2_id)
 
1858
 
 
1859
 
 
1860
####################
 
1861
 
 
1862
 
 
1863
def task_log_end_task(context, task_name,
 
1864
                        period_beginning,
 
1865
                        period_ending,
 
1866
                        host,
 
1867
                        errors,
 
1868
                        message=None,
 
1869
                        session=None):
 
1870
    """Mark a task as complete for a given host/time period"""
 
1871
    return IMPL.task_log_end_task(context, task_name,
 
1872
                                  period_beginning,
 
1873
                                  period_ending,
 
1874
                                  host,
 
1875
                                  errors,
 
1876
                                  message,
 
1877
                                  session)
 
1878
 
 
1879
 
 
1880
def task_log_begin_task(context, task_name,
 
1881
                        period_beginning,
 
1882
                        period_ending,
 
1883
                        host,
 
1884
                        task_items=None,
 
1885
                        message=None,
 
1886
                        session=None):
 
1887
    """Mark a task as started for a given host/time period"""
 
1888
    return IMPL.task_log_begin_task(context, task_name,
 
1889
                                    period_beginning,
 
1890
                                    period_ending,
 
1891
                                    host,
 
1892
                                    task_items,
 
1893
                                    message,
 
1894
                                    session)
 
1895
 
 
1896
 
 
1897
def task_log_get_all(context, task_name, period_beginning,
 
1898
                 period_ending, host=None, state=None, session=None):
 
1899
    return IMPL.task_log_get_all(context, task_name, period_beginning,
 
1900
                 period_ending, host, state, session)
 
1901
 
 
1902
 
 
1903
def task_log_get(context, task_name, period_beginning,
 
1904
                 period_ending, host, state=None, session=None):
 
1905
    return IMPL.task_log_get(context, task_name, period_beginning,
 
1906
                 period_ending, host, state, session)