~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/db/api.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-01-21 11:48:06 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110121114806-v8fvnnl6az4m4ohv
Tags: upstream-2011.1~bzr597
ImportĀ upstreamĀ versionĀ 2011.1~bzr597

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
:sql_connection:  string specifying the sqlalchemy connection to use, like:
29
29
                  `sqlite:///var/lib/nova/nova.sqlite`.
 
30
 
 
31
:enable_new_services:  when adding a new service to the database, is it in the
 
32
                       pool of available hardware (Default: True)
30
33
"""
31
34
 
32
35
from nova import exception
37
40
FLAGS = flags.FLAGS
38
41
flags.DEFINE_string('db_backend', 'sqlalchemy',
39
42
                    'The backend to use for db')
 
43
flags.DEFINE_boolean('enable_new_services', True,
 
44
                     'Services to be added to the available pool on create')
 
45
flags.DEFINE_string('instance_name_template', 'instance-%08x',
 
46
                    'Template string to be used to generate instance names')
 
47
flags.DEFINE_string('volume_name_template', 'volume-%08x',
 
48
                    'Template string to be used to generate instance names')
40
49
 
41
50
 
42
51
IMPL = utils.LazyPluggable(FLAGS['db_backend'],
76
85
    return IMPL.service_get(context, service_id)
77
86
 
78
87
 
 
88
def service_get_all(context, disabled=False):
 
89
    """Get all service."""
 
90
    return IMPL.service_get_all(context, None, disabled)
 
91
 
 
92
 
79
93
def service_get_all_by_topic(context, topic):
80
 
    """Get all compute services for a given topic."""
 
94
    """Get all services for a given topic."""
81
95
    return IMPL.service_get_all_by_topic(context, topic)
82
96
 
83
97
 
 
98
def service_get_all_by_host(context, host):
 
99
    """Get all services for a given host."""
 
100
    return IMPL.service_get_all_by_host(context, host)
 
101
 
 
102
 
84
103
def service_get_all_compute_sorted(context):
85
104
    """Get all compute services sorted by instance count.
86
105
 
130
149
###################
131
150
 
132
151
 
 
152
def certificate_create(context, values):
 
153
    """Create a certificate from the values dictionary."""
 
154
    return IMPL.certificate_create(context, values)
 
155
 
 
156
 
 
157
def certificate_destroy(context, certificate_id):
 
158
    """Destroy the certificate or raise if it does not exist."""
 
159
    return IMPL.certificate_destroy(context, certificate_id)
 
160
 
 
161
 
 
162
def certificate_get_all_by_project(context, project_id):
 
163
    """Get all certificates for a project."""
 
164
    return IMPL.certificate_get_all_by_project(context, project_id)
 
165
 
 
166
 
 
167
def certificate_get_all_by_user(context, user_id):
 
168
    """Get all certificates for a user."""
 
169
    return IMPL.certificate_get_all_by_user(context, user_id)
 
170
 
 
171
 
 
172
def certificate_get_all_by_user_and_project(context, user_id, project_id):
 
173
    """Get all certificates for a user and project."""
 
174
    return IMPL.certificate_get_all_by_user_and_project(context,
 
175
                                                        user_id,
 
176
                                                        project_id)
 
177
 
 
178
 
 
179
def certificate_update(context, certificate_id, values):
 
180
    """Set the given properties on an certificate and update it.
 
181
 
 
182
    Raises NotFound if service does not exist.
 
183
 
 
184
    """
 
185
    return IMPL.service_update(context, certificate_id, values)
 
186
 
 
187
 
 
188
###################
 
189
 
 
190
 
133
191
def floating_ip_allocate_address(context, host, project_id):
134
192
    """Allocate free floating ip and return the address.
135
193
 
241
299
    return IMPL.fixed_ip_get_instance(context, address)
242
300
 
243
301
 
 
302
def fixed_ip_get_instance_v6(context, address):
 
303
    return IMPL.fixed_ip_get_instance_v6(context, address)
 
304
 
 
305
 
244
306
def fixed_ip_get_network(context, address):
245
307
    """Get a network for a fixed ip by address."""
246
308
    return IMPL.fixed_ip_get_network(context, address)
299
361
    return IMPL.instance_get_fixed_address(context, instance_id)
300
362
 
301
363
 
 
364
def instance_get_fixed_address_v6(context, instance_id):
 
365
    return IMPL.instance_get_fixed_address_v6(context, instance_id)
 
366
 
 
367
 
302
368
def instance_get_floating_address(context, instance_id):
303
369
    """Get the first floating ip address of an instance."""
304
370
    return IMPL.instance_get_floating_address(context, instance_id)
305
371
 
306
372
 
307
 
def instance_get_by_internal_id(context, internal_id):
308
 
    """Get an instance by internal id."""
309
 
    return IMPL.instance_get_by_internal_id(context, internal_id)
 
373
def instance_get_project_vpn(context, project_id):
 
374
    """Get a vpn instance by project or return None."""
 
375
    return IMPL.instance_get_project_vpn(context, project_id)
 
376
 
 
377
 
 
378
def instance_get_by_id(context, instance_id):
 
379
    """Get an instance by id."""
 
380
    return IMPL.instance_get_by_id(context, instance_id)
310
381
 
311
382
 
312
383
def instance_is_vpn(context, instance_id):
334
405
                                            security_group_id)
335
406
 
336
407
 
 
408
def instance_action_create(context, values):
 
409
    """Create an instance action from the values dictionary."""
 
410
    return IMPL.instance_action_create(context, values)
 
411
 
 
412
 
 
413
def instance_get_actions(context, instance_id):
 
414
    """Get instance actions by instance id."""
 
415
    return IMPL.instance_get_actions(context, instance_id)
 
416
 
 
417
 
337
418
###################
338
419
 
339
420
 
468
549
###################
469
550
 
470
551
 
471
 
def project_get_network(context, project_id):
 
552
def project_get_network(context, project_id, associate=True):
472
553
    """Return the network associated with the project.
473
554
 
474
 
    Raises NotFound if no such network can be found.
 
555
    If associate is true, it will attempt to associate a new
 
556
    network if one is not found, otherwise it returns None.
475
557
 
476
558
    """
 
559
 
477
560
    return IMPL.project_get_network(context, project_id)
478
561
 
479
562
 
 
563
def project_get_network_v6(context, project_id):
 
564
    return IMPL.project_get_network_v6(context, project_id)
 
565
 
 
566
 
480
567
###################
481
568
 
482
569
 
658
745
 
659
746
 
660
747
def security_group_get(context, security_group_id):
661
 
    """Get security group by its internal id."""
 
748
    """Get security group by its id."""
662
749
    return IMPL.security_group_get(context, security_group_id)
663
750
 
664
751
 
711
798
                                                          security_group_id)
712
799
 
713
800
 
 
801
def security_group_rule_get_by_security_group_grantee(context,
 
802
                                                      security_group_id):
 
803
    """Get all rules that grant access to the given security group."""
 
804
    return IMPL.security_group_rule_get_by_security_group_grantee(context,
 
805
                                                             security_group_id)
 
806
 
 
807
 
714
808
def security_group_rule_destroy(context, security_group_rule_id):
715
809
    """Deletes a security group rule."""
716
810
    return IMPL.security_group_rule_destroy(context, security_group_rule_id)
833
927
 
834
928
    """
835
929
    return IMPL.host_get_networks(context, host)
 
930
 
 
931
 
 
932
##################
 
933
 
 
934
 
 
935
def console_pool_create(context, values):
 
936
    """Create console pool."""
 
937
    return IMPL.console_pool_create(context, values)
 
938
 
 
939
 
 
940
def console_pool_get(context, pool_id):
 
941
    """Get a console pool."""
 
942
    return IMPL.console_pool_get(context, pool_id)
 
943
 
 
944
 
 
945
def console_pool_get_by_host_type(context, compute_host, proxy_host,
 
946
                                  console_type):
 
947
    """Fetch a console pool for a given proxy host, compute host, and type."""
 
948
    return IMPL.console_pool_get_by_host_type(context,
 
949
                                              compute_host,
 
950
                                              proxy_host,
 
951
                                              console_type)
 
952
 
 
953
 
 
954
def console_pool_get_all_by_host_type(context, host, console_type):
 
955
    """Fetch all pools for given proxy host and type."""
 
956
    return IMPL.console_pool_get_all_by_host_type(context,
 
957
                                                  host,
 
958
                                                  console_type)
 
959
 
 
960
 
 
961
def console_create(context, values):
 
962
    """Create a console."""
 
963
    return IMPL.console_create(context, values)
 
964
 
 
965
 
 
966
def console_delete(context, console_id):
 
967
    """Delete a console."""
 
968
    return IMPL.console_delete(context, console_id)
 
969
 
 
970
 
 
971
def console_get_by_pool_instance(context, pool_id, instance_id):
 
972
    """Get console entry for a given instance and pool."""
 
973
    return IMPL.console_get_by_pool_instance(context, pool_id, instance_id)
 
974
 
 
975
 
 
976
def console_get_all_by_instance(context, instance_id):
 
977
    """Get consoles for a given instance."""
 
978
    return IMPL.console_get_all_by_instance(context, instance_id)
 
979
 
 
980
 
 
981
def console_get(context, console_id, instance_id=None):
 
982
    """Get a specific console (possibly on a given instance)."""
 
983
    return IMPL.console_get(context, console_id, instance_id)