~rlane/nova/ldapimprovements

« back to all changes in this revision

Viewing changes to nova/db/api.py

  • Committer: Ryan Lane
  • Date: 2010-11-24 15:46:32 UTC
  • mfrom: (382.48.1 trunk)
  • Revision ID: laner@controller-20101124154632-zh7kwjuyyd02a2lh
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#    License for the specific language governing permissions and limitations
17
17
#    under the License.
18
18
"""
19
 
Defines interface for DB access
 
19
Defines interface for DB access.
 
20
 
 
21
The underlying driver is loaded as a :class:`LazyPluggable`.
 
22
 
 
23
**Related Flags**
 
24
 
 
25
:db_backend:  string to lookup in the list of LazyPluggable backends.
 
26
              `sqlalchemy` is the only supported backend right now.
 
27
 
 
28
:sql_connection:  string specifying the sqlalchemy connection to use, like:
 
29
                  `sqlite:///var/lib/nova/nova.sqlite`.
20
30
"""
21
31
 
22
32
from nova import exception
34
44
 
35
45
 
36
46
class NoMoreAddresses(exception.Error):
37
 
    """No more available addresses"""
 
47
    """No more available addresses."""
38
48
    pass
39
49
 
40
50
 
41
51
class NoMoreBlades(exception.Error):
 
52
    """No more available blades."""
 
53
    pass
 
54
 
 
55
 
 
56
class NoMoreNetworks(exception.Error):
 
57
    """No more available networks."""
 
58
    pass
 
59
 
 
60
 
 
61
class NoMoreTargets(exception.Error):
42
62
    """No more available blades"""
43
63
    pass
44
64
 
45
65
 
46
 
class NoMoreNetworks(exception.Error):
47
 
    """No more available networks"""
48
 
    pass
49
 
 
50
 
 
51
66
###################
52
67
 
53
68
 
62
77
 
63
78
 
64
79
def service_get_all_by_topic(context, topic):
65
 
    """Get all compute services for a given topic """
 
80
    """Get all compute services for a given topic."""
66
81
    return IMPL.service_get_all_by_topic(context, topic)
67
82
 
68
83
 
69
84
def service_get_all_compute_sorted(context):
70
 
    """Get all compute services sorted by instance count
71
 
 
72
 
    Returns a list of (Service, instance_count) tuples
 
85
    """Get all compute services sorted by instance count.
 
86
 
 
87
    Returns a list of (Service, instance_count) tuples.
 
88
 
73
89
    """
74
90
    return IMPL.service_get_all_compute_sorted(context)
75
91
 
76
92
 
77
93
def service_get_all_network_sorted(context):
78
 
    """Get all network services sorted by network count
79
 
 
80
 
    Returns a list of (Service, network_count) tuples
 
94
    """Get all network services sorted by network count.
 
95
 
 
96
    Returns a list of (Service, network_count) tuples.
 
97
 
81
98
    """
82
99
    return IMPL.service_get_all_network_sorted(context)
83
100
 
84
101
 
85
102
def service_get_all_volume_sorted(context):
86
 
    """Get all volume services sorted by volume count
87
 
 
88
 
    Returns a list of (Service, volume_count) tuples
 
103
    """Get all volume services sorted by volume count.
 
104
 
 
105
    Returns a list of (Service, volume_count) tuples.
 
106
 
89
107
    """
90
108
    return IMPL.service_get_all_volume_sorted(context)
91
109
 
116
134
    """Allocate free floating ip and return the address.
117
135
 
118
136
    Raises if one is not available.
 
137
 
119
138
    """
120
139
    return IMPL.floating_ip_allocate_address(context, host, project_id)
121
140
 
144
163
    """Disassociate an floating ip from a fixed ip by address.
145
164
 
146
165
    Returns the address of the existing fixed ip.
 
166
 
147
167
    """
148
168
    return IMPL.floating_ip_disassociate(context, address)
149
169
 
182
202
    """Associate fixed ip to instance.
183
203
 
184
204
    Raises if fixed ip is not available.
 
205
 
185
206
    """
186
207
    return IMPL.fixed_ip_associate(context, address, instance_id)
187
208
 
190
211
    """Find free ip in network and associate it to instance.
191
212
 
192
213
    Raises if one is not available.
 
214
 
193
215
    """
194
216
    return IMPL.fixed_ip_associate_pool(context, network_id, instance_id)
195
217
 
205
227
 
206
228
 
207
229
def fixed_ip_disassociate_all_by_timeout(context, host, time):
208
 
    """Disassociate old fixed ips from host"""
 
230
    """Disassociate old fixed ips from host."""
209
231
    return IMPL.fixed_ip_disassociate_all_by_timeout(context, host, time)
210
232
 
211
233
 
283
305
 
284
306
 
285
307
def instance_get_by_internal_id(context, internal_id):
286
 
    """Get an instance by ec2 id."""
 
308
    """Get an instance by internal id."""
287
309
    return IMPL.instance_get_by_internal_id(context, internal_id)
288
310
 
289
311
 
307
329
 
308
330
 
309
331
def instance_add_security_group(context, instance_id, security_group_id):
310
 
    """Associate the given security group with the given instance"""
 
332
    """Associate the given security group with the given instance."""
311
333
    return IMPL.instance_add_security_group(context, instance_id,
312
334
                                            security_group_id)
313
335
 
369
391
 
370
392
 
371
393
def network_create_safe(context, values):
372
 
    """Create a network from the values dict
 
394
    """Create a network from the values dict.
373
395
 
374
396
    The network is only returned if the create succeeds. If the create violates
375
 
    constraints because the network already exists, no exception is raised."""
 
397
    constraints because the network already exists, no exception is raised.
 
398
 
 
399
    """
376
400
    return IMPL.network_create_safe(context, values)
377
401
 
378
402
 
413
437
 
414
438
 
415
439
def network_get_index(context, network_id):
416
 
    """Get non-conflicting index for network"""
 
440
    """Get non-conflicting index for network."""
417
441
    return IMPL.network_get_index(context, network_id)
418
442
 
419
443
 
420
444
def network_get_vpn_ip(context, network_id):
421
 
    """Get non-conflicting index for network"""
 
445
    """Get non-conflicting index for network."""
422
446
    return IMPL.network_get_vpn_ip(context, network_id)
423
447
 
424
448
 
425
449
def network_set_cidr(context, network_id, cidr):
426
 
    """Set the Classless Inner Domain Routing for the network"""
 
450
    """Set the Classless Inner Domain Routing for the network."""
427
451
    return IMPL.network_set_cidr(context, network_id, cidr)
428
452
 
429
453
 
430
454
def network_set_host(context, network_id, host_id):
431
 
    """Safely set the host for network"""
 
455
    """Safely set the host for network."""
432
456
    return IMPL.network_set_host(context, network_id, host_id)
433
457
 
434
458
 
474
498
 
475
499
    The device is not returned. If the create violates the unique
476
500
    constraints because the shelf_id and blade_id already exist,
 
501
    no exception is raised.
 
502
 
 
503
    """
 
504
    return IMPL.export_device_create_safe(context, values)
 
505
 
 
506
 
 
507
###################
 
508
 
 
509
 
 
510
def iscsi_target_count_by_host(context, host):
 
511
    """Return count of export devices."""
 
512
    return IMPL.iscsi_target_count_by_host(context, host)
 
513
 
 
514
 
 
515
def iscsi_target_create_safe(context, values):
 
516
    """Create an iscsi_target from the values dictionary.
 
517
 
 
518
    The device is not returned. If the create violates the unique
 
519
    constraints because the iscsi_target and host already exist,
477
520
    no exception is raised."""
478
 
    return IMPL.export_device_create_safe(context, values)
479
 
 
480
 
 
481
 
###################
 
521
    return IMPL.iscsi_target_create_safe(context, values)
 
522
 
 
523
 
 
524
###############
482
525
 
483
526
 
484
527
def auth_destroy_token(context, token):
485
 
    """Destroy an auth token"""
 
528
    """Destroy an auth token."""
486
529
    return IMPL.auth_destroy_token(context, token)
487
530
 
488
531
 
489
532
def auth_get_token(context, token_hash):
490
 
    """Retrieves a token given the hash representing it"""
 
533
    """Retrieves a token given the hash representing it."""
491
534
    return IMPL.auth_get_token(context, token_hash)
492
535
 
493
536
 
494
537
def auth_create_token(context, token):
495
 
    """Creates a new token"""
 
538
    """Creates a new token."""
496
539
    return IMPL.auth_create_token(context, token)
497
540
 
498
541
 
527
570
    return IMPL.volume_allocate_shelf_and_blade(context, volume_id)
528
571
 
529
572
 
 
573
def volume_allocate_iscsi_target(context, volume_id, host):
 
574
    """Atomically allocate a free iscsi_target from the pool."""
 
575
    return IMPL.volume_allocate_iscsi_target(context, volume_id, host)
 
576
 
 
577
 
530
578
def volume_attached(context, volume_id, instance_id, mountpoint):
531
579
    """Ensure that a volume is set as attached."""
532
580
    return IMPL.volume_attached(context, volume_id, instance_id, mountpoint)
562
610
    return IMPL.volume_get_all(context)
563
611
 
564
612
 
565
 
def volume_get_instance(context, volume_id):
566
 
    """Get the instance that a volume is attached to."""
567
 
    return IMPL.volume_get_instance(context, volume_id)
 
613
def volume_get_all_by_host(context, host):
 
614
    """Get all volumes belonging to a host."""
 
615
    return IMPL.volume_get_all_by_host(context, host)
568
616
 
569
617
 
570
618
def volume_get_all_by_project(context, project_id):
577
625
    return IMPL.volume_get_by_ec2_id(context, ec2_id)
578
626
 
579
627
 
 
628
def volume_get_instance(context, volume_id):
 
629
    """Get the instance that a volume is attached to."""
 
630
    return IMPL.volume_get_instance(context, volume_id)
 
631
 
 
632
 
580
633
def volume_get_shelf_and_blade(context, volume_id):
581
634
    """Get the shelf and blade allocated to the volume."""
582
635
    return IMPL.volume_get_shelf_and_blade(context, volume_id)
583
636
 
584
637
 
 
638
def volume_get_iscsi_target_num(context, volume_id):
 
639
    """Get the target num (tid) allocated to the volume."""
 
640
    return IMPL.volume_get_iscsi_target_num(context, volume_id)
 
641
 
 
642
 
585
643
def volume_update(context, volume_id, values):
586
644
    """Set the given properties on an volume and update it.
587
645
 
595
653
 
596
654
 
597
655
def security_group_get_all(context):
598
 
    """Get all security groups"""
 
656
    """Get all security groups."""
599
657
    return IMPL.security_group_get_all(context)
600
658
 
601
659
 
602
660
def security_group_get(context, security_group_id):
603
 
    """Get security group by its internal id"""
 
661
    """Get security group by its internal id."""
604
662
    return IMPL.security_group_get(context, security_group_id)
605
663
 
606
664
 
607
665
def security_group_get_by_name(context, project_id, group_name):
608
 
    """Returns a security group with the specified name from a project"""
 
666
    """Returns a security group with the specified name from a project."""
609
667
    return IMPL.security_group_get_by_name(context, project_id, group_name)
610
668
 
611
669
 
612
670
def security_group_get_by_project(context, project_id):
613
 
    """Get all security groups belonging to a project"""
 
671
    """Get all security groups belonging to a project."""
614
672
    return IMPL.security_group_get_by_project(context, project_id)
615
673
 
616
674
 
617
675
def security_group_get_by_instance(context, instance_id):
618
 
    """Get security groups to which the instance is assigned"""
 
676
    """Get security groups to which the instance is assigned."""
619
677
    return IMPL.security_group_get_by_instance(context, instance_id)
620
678
 
621
679
 
622
680
def security_group_exists(context, project_id, group_name):
623
 
    """Indicates if a group name exists in a project"""
 
681
    """Indicates if a group name exists in a project."""
624
682
    return IMPL.security_group_exists(context, project_id, group_name)
625
683
 
626
684
 
627
685
def security_group_create(context, values):
628
 
    """Create a new security group"""
 
686
    """Create a new security group."""
629
687
    return IMPL.security_group_create(context, values)
630
688
 
631
689
 
632
690
def security_group_destroy(context, security_group_id):
633
 
    """Deletes a security group"""
 
691
    """Deletes a security group."""
634
692
    return IMPL.security_group_destroy(context, security_group_id)
635
693
 
636
694
 
637
695
def security_group_destroy_all(context):
638
 
    """Deletes a security group"""
 
696
    """Deletes a security group."""
639
697
    return IMPL.security_group_destroy_all(context)
640
698
 
641
699
 
643
701
 
644
702
 
645
703
def security_group_rule_create(context, values):
646
 
    """Create a new security group"""
 
704
    """Create a new security group."""
647
705
    return IMPL.security_group_rule_create(context, values)
648
706
 
649
707
 
650
708
def security_group_rule_get_by_security_group(context, security_group_id):
651
 
    """Get all rules for a a given security group"""
 
709
    """Get all rules for a a given security group."""
652
710
    return IMPL.security_group_rule_get_by_security_group(context,
653
711
                                                          security_group_id)
654
712
 
655
713
 
656
714
def security_group_rule_destroy(context, security_group_rule_id):
657
 
    """Deletes a security group rule"""
 
715
    """Deletes a security group rule."""
658
716
    return IMPL.security_group_rule_destroy(context, security_group_rule_id)
659
717
 
660
718
 
662
720
 
663
721
 
664
722
def user_get(context, id):
665
 
    """Get user by id"""
 
723
    """Get user by id."""
666
724
    return IMPL.user_get(context, id)
667
725
 
668
726
 
669
727
def user_get_by_uid(context, uid):
670
 
    """Get user by uid"""
 
728
    """Get user by uid."""
671
729
    return IMPL.user_get_by_uid(context, uid)
672
730
 
673
731
 
674
732
def user_get_by_access_key(context, access_key):
675
 
    """Get user by access key"""
 
733
    """Get user by access key."""
676
734
    return IMPL.user_get_by_access_key(context, access_key)
677
735
 
678
736
 
679
737
def user_create(context, values):
680
 
    """Create a new user"""
 
738
    """Create a new user."""
681
739
    return IMPL.user_create(context, values)
682
740
 
683
741
 
684
742
def user_delete(context, id):
685
 
    """Delete a user"""
 
743
    """Delete a user."""
686
744
    return IMPL.user_delete(context, id)
687
745
 
688
746
 
689
747
def user_get_all(context):
690
 
    """Create a new user"""
 
748
    """Create a new user."""
691
749
    return IMPL.user_get_all(context)
692
750
 
693
751
 
694
752
def user_add_role(context, user_id, role):
695
 
    """Add another global role for user"""
 
753
    """Add another global role for user."""
696
754
    return IMPL.user_add_role(context, user_id, role)
697
755
 
698
756
 
699
757
def user_remove_role(context, user_id, role):
700
 
    """Remove global role from user"""
 
758
    """Remove global role from user."""
701
759
    return IMPL.user_remove_role(context, user_id, role)
702
760
 
703
761
 
704
762
def user_get_roles(context, user_id):
705
 
    """Get global roles for user"""
 
763
    """Get global roles for user."""
706
764
    return IMPL.user_get_roles(context, user_id)
707
765
 
708
766
 
709
767
def user_add_project_role(context, user_id, project_id, role):
710
 
    """Add project role for user"""
 
768
    """Add project role for user."""
711
769
    return IMPL.user_add_project_role(context, user_id, project_id, role)
712
770
 
713
771
 
714
772
def user_remove_project_role(context, user_id, project_id, role):
715
 
    """Remove project role from user"""
 
773
    """Remove project role from user."""
716
774
    return IMPL.user_remove_project_role(context, user_id, project_id, role)
717
775
 
718
776
 
719
777
def user_get_roles_for_project(context, user_id, project_id):
720
 
    """Return list of roles a user holds on project"""
 
778
    """Return list of roles a user holds on project."""
721
779
    return IMPL.user_get_roles_for_project(context, user_id, project_id)
722
780
 
723
781
 
724
782
def user_update(context, user_id, values):
725
 
    """Update user"""
 
783
    """Update user."""
726
784
    return IMPL.user_update(context, user_id, values)
727
785
 
728
786
 
729
787
def project_get(context, id):
730
 
    """Get project by id"""
 
788
    """Get project by id."""
731
789
    return IMPL.project_get(context, id)
732
790
 
733
791
 
734
792
def project_create(context, values):
735
 
    """Create a new project"""
 
793
    """Create a new project."""
736
794
    return IMPL.project_create(context, values)
737
795
 
738
796
 
739
797
def project_add_member(context, project_id, user_id):
740
 
    """Add user to project"""
 
798
    """Add user to project."""
741
799
    return IMPL.project_add_member(context, project_id, user_id)
742
800
 
743
801
 
744
802
def project_get_all(context):
745
 
    """Get all projects"""
 
803
    """Get all projects."""
746
804
    return IMPL.project_get_all(context)
747
805
 
748
806
 
749
807
def project_get_by_user(context, user_id):
750
 
    """Get all projects of which the given user is a member"""
 
808
    """Get all projects of which the given user is a member."""
751
809
    return IMPL.project_get_by_user(context, user_id)
752
810
 
753
811
 
754
812
def project_remove_member(context, project_id, user_id):
755
 
    """Remove the given user from the given project"""
 
813
    """Remove the given user from the given project."""
756
814
    return IMPL.project_remove_member(context, project_id, user_id)
757
815
 
758
816
 
759
817
def project_update(context, project_id, values):
760
 
    """Update Remove the given user from the given project"""
 
818
    """Update Remove the given user from the given project."""
761
819
    return IMPL.project_update(context, project_id, values)
762
820
 
763
821
 
764
822
def project_delete(context, project_id):
765
 
    """Delete project"""
 
823
    """Delete project."""
766
824
    return IMPL.project_delete(context, project_id)
767
825
 
768
826
 
771
829
 
772
830
def host_get_networks(context, host):
773
831
    """Return all networks for which the given host is the designated
774
 
    network host
 
832
    network host.
 
833
 
775
834
    """
776
835
    return IMPL.host_get_networks(context, host)