~0x44/nova/bug838466

237.4.2 by andy
Data abstraction for compute service
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
237.1.27 by Vishvananda Ishaya
move volume code into datalayer and cleanup
3
# Copyright 2010 United States Government as represented by the
4
# Administrator of the National Aeronautics and Space Administration.
5
# All Rights Reserved.
6
#
7
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
8
#    not use this file except in compliance with the License. You may obtain
9
#    a copy of the License at
10
#
11
#         http://www.apache.org/licenses/LICENSE-2.0
12
#
13
#    Unless required by applicable law or agreed to in writing, software
14
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
#    License for the specific language governing permissions and limitations
17
#    under the License.
237.1.78 by Vishvananda Ishaya
rename node_name to host
18
"""
386.3.20 by Todd Willey
Pep-257 cleanups.
19
Defines interface for DB access.
386.3.27 by Todd Willey
Update database docs.
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`.
472.2.3 by Todd Willey
Add flag --enable_new_services to toggle default state of service when created.
30
31
:enable_new_services:  when adding a new service to the database, is it in the
472.2.4 by Todd Willey
Defualt services to enabled.
32
                       pool of available hardware (Default: True)
237.1.78 by Vishvananda Ishaya
rename node_name to host
33
"""
237.1.27 by Vishvananda Ishaya
move volume code into datalayer and cleanup
34
237.1.28 by andy
Alphabetize the methods in the db layer.
35
from nova import exception
237.4.2 by andy
Data abstraction for compute service
36
from nova import flags
37
from nova import utils
38
39
40
FLAGS = flags.FLAGS
41
flags.DEFINE_string('db_backend', 'sqlalchemy',
42
                    'The backend to use for db')
472.2.4 by Todd Willey
Defualt services to enabled.
43
flags.DEFINE_boolean('enable_new_services', True,
472.2.3 by Todd Willey
Add flag --enable_new_services to toggle default state of service when created.
44
                     'Services to be added to the available pool on create')
556.4.3 by Andy Smith
standardize on hex for ids, allow configurable instance names
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')
237.4.2 by andy
Data abstraction for compute service
49
50
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
51
IMPL = utils.LazyPluggable(FLAGS['db_backend'],
237.1.104 by Vishvananda Ishaya
review db code cleanup
52
                           sqlalchemy='nova.db.sqlalchemy.api')
53
54
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
55
class NoMoreAddresses(exception.Error):
386.3.20 by Todd Willey
Pep-257 cleanups.
56
    """No more available addresses."""
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
57
    pass
58
59
237.1.28 by andy
Alphabetize the methods in the db layer.
60
class NoMoreBlades(exception.Error):
386.3.20 by Todd Willey
Pep-257 cleanups.
61
    """No more available blades."""
237.1.28 by andy
Alphabetize the methods in the db layer.
62
    pass
63
64
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
65
class NoMoreNetworks(exception.Error):
386.3.20 by Todd Willey
Pep-257 cleanups.
66
    """No more available networks."""
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
67
    pass
68
69
379.3.1 by Vishvananda Ishaya
ISCSI Volume support
70
class NoMoreTargets(exception.Error):
71
    """No more available blades"""
72
    pass
73
237.1.28 by andy
Alphabetize the methods in the db layer.
74
###################
75
76
205.1.22 by Vishvananda Ishaya
merged orm branch
77
def service_destroy(context, instance_id):
78
    """Destroy the service or raise if it does not exist."""
79
    return IMPL.service_destroy(context, instance_id)
80
81
237.1.85 by Vishvananda Ishaya
renamed daemon to service and update db on create and destroy
82
def service_get(context, service_id):
569.1.9 by Cerberus
Added a bunch of stubbed out functionality
83
    """Get a service or raise if it does not exist."""
237.1.85 by Vishvananda Ishaya
renamed daemon to service and update db on create and destroy
84
    return IMPL.service_get(context, service_id)
85
86
569.1.9 by Cerberus
Added a bunch of stubbed out functionality
87
def service_get_by_host_and_topic(context, host, topic):
88
    """Get a service by host it's on and topic it listens to"""
569.1.29 by Cerberus
Forgot the metadata includes
89
    return IMPL.service_get_by_host_and_topic(context, host, topic)
569.1.9 by Cerberus
Added a bunch of stubbed out functionality
90
91
523.1.1 by Eldar Nugaev
merge
92
def service_get_all(context, disabled=False):
720.1.1 by Vishvananda Ishaya
fix describe_availability_zones
93
    """Get all services."""
94
    return IMPL.service_get_all(context, disabled)
523.1.1 by Eldar Nugaev
merge
95
96
205.1.22 by Vishvananda Ishaya
merged orm branch
97
def service_get_all_by_topic(context, topic):
523.1.1 by Eldar Nugaev
merge
98
    """Get all services for a given topic."""
205.1.22 by Vishvananda Ishaya
merged orm branch
99
    return IMPL.service_get_all_by_topic(context, topic)
100
101
523.1.1 by Eldar Nugaev
merge
102
def service_get_all_by_host(context, host):
103
    """Get all services for a given host."""
104
    return IMPL.service_get_all_by_host(context, host)
105
106
205.1.22 by Vishvananda Ishaya
merged orm branch
107
def service_get_all_compute_sorted(context):
386.3.20 by Todd Willey
Pep-257 cleanups.
108
    """Get all compute services sorted by instance count.
109
110
    Returns a list of (Service, instance_count) tuples.
111
205.1.22 by Vishvananda Ishaya
merged orm branch
112
    """
113
    return IMPL.service_get_all_compute_sorted(context)
114
115
205.1.24 by Vishvananda Ishaya
more scheduler tests
116
def service_get_all_network_sorted(context):
386.3.20 by Todd Willey
Pep-257 cleanups.
117
    """Get all network services sorted by network count.
118
119
    Returns a list of (Service, network_count) tuples.
120
205.1.24 by Vishvananda Ishaya
more scheduler tests
121
    """
122
    return IMPL.service_get_all_network_sorted(context)
123
124
125
def service_get_all_volume_sorted(context):
386.3.20 by Todd Willey
Pep-257 cleanups.
126
    """Get all volume services sorted by volume count.
127
128
    Returns a list of (Service, volume_count) tuples.
129
205.1.24 by Vishvananda Ishaya
more scheduler tests
130
    """
131
    return IMPL.service_get_all_volume_sorted(context)
132
133
237.1.85 by Vishvananda Ishaya
renamed daemon to service and update db on create and destroy
134
def service_get_by_args(context, host, binary):
135
    """Get the state of an service by node name and binary."""
136
    return IMPL.service_get_by_args(context, host, binary)
137
138
139
def service_create(context, values):
140
    """Create a service from the values dictionary."""
141
    return IMPL.service_create(context, values)
142
143
144
def service_update(context, service_id, values):
145
    """Set the given properties on an service and update it.
146
147
    Raises NotFound if service does not exist.
237.1.33 by Vishvananda Ishaya
fix daemons and move network code
148
149
    """
237.1.85 by Vishvananda Ishaya
renamed daemon to service and update db on create and destroy
150
    return IMPL.service_update(context, service_id, values)
237.1.29 by andy
Add db abstraction and unittets for service.py.
151
152
153
###################
154
155
396.6.1 by Vishvananda Ishaya
Per-project vpns, certificates, and revocation
156
def certificate_create(context, values):
157
    """Create a certificate from the values dictionary."""
158
    return IMPL.certificate_create(context, values)
159
160
161
def certificate_destroy(context, certificate_id):
162
    """Destroy the certificate or raise if it does not exist."""
163
    return IMPL.certificate_destroy(context, certificate_id)
164
165
166
def certificate_get_all_by_project(context, project_id):
167
    """Get all certificates for a project."""
168
    return IMPL.certificate_get_all_by_project(context, project_id)
169
170
171
def certificate_get_all_by_user(context, user_id):
172
    """Get all certificates for a user."""
173
    return IMPL.certificate_get_all_by_user(context, user_id)
174
175
176
def certificate_get_all_by_user_and_project(context, user_id, project_id):
177
    """Get all certificates for a user and project."""
178
    return IMPL.certificate_get_all_by_user_and_project(context,
179
                                                        user_id,
180
                                                        project_id)
181
182
183
def certificate_update(context, certificate_id, values):
184
    """Set the given properties on an certificate and update it.
185
186
    Raises NotFound if service does not exist.
187
188
    """
189
    return IMPL.service_update(context, certificate_id, values)
190
191
192
###################
193
194
237.1.78 by Vishvananda Ishaya
rename node_name to host
195
def floating_ip_allocate_address(context, host, project_id):
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
196
    """Allocate free floating ip and return the address.
197
198
    Raises if one is not available.
386.3.20 by Todd Willey
Pep-257 cleanups.
199
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
200
    """
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
201
    return IMPL.floating_ip_allocate_address(context, host, project_id)
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
202
203
237.1.95 by Vishvananda Ishaya
fix floating_ip to follow standard create pattern
204
def floating_ip_create(context, values):
205
    """Create a floating ip from the values dictionary."""
206
    return IMPL.floating_ip_create(context, values)
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
207
208
237.10.3 by Vishvananda Ishaya
merged orm, added database methods for getting volume and ip data for projects
209
def floating_ip_count_by_project(context, project_id):
210
    """Count floating ips used by project."""
211
    return IMPL.floating_ip_count_by_project(context, project_id)
212
213
237.7.1 by Vishvananda Ishaya
floating ip commands
214
def floating_ip_deallocate(context, address):
215
    """Deallocate an floating ip by address"""
216
    return IMPL.floating_ip_deallocate(context, address)
217
218
219
def floating_ip_destroy(context, address):
220
    """Destroy the floating_ip or raise if it does not exist."""
221
    return IMPL.floating_ip_destroy(context, address)
222
223
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
224
def floating_ip_disassociate(context, address):
225
    """Disassociate an floating ip from a fixed ip by address.
226
227
    Returns the address of the existing fixed ip.
386.3.20 by Todd Willey
Pep-257 cleanups.
228
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
229
    """
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
230
    return IMPL.floating_ip_disassociate(context, address)
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
231
232
237.1.51 by Vishvananda Ishaya
removed the last few references to models.py
233
def floating_ip_fixed_ip_associate(context, floating_address, fixed_address):
234
    """Associate an floating ip to a fixed_ip by address."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
235
    return IMPL.floating_ip_fixed_ip_associate(context,
237.1.51 by Vishvananda Ishaya
removed the last few references to models.py
236
                                               floating_address,
237
                                               fixed_address)
238
239
237.7.1 by Vishvananda Ishaya
floating ip commands
240
def floating_ip_get_all(context):
241
    """Get all floating ips."""
242
    return IMPL.floating_ip_get_all(context)
243
244
245
def floating_ip_get_all_by_host(context, host):
276.4.1 by Vishvananda Ishaya
implement floating_ip_get_all_by_project and renamed db methods that get more then one to get_all_by instead of get_by
246
    """Get all floating ips by host."""
237.7.1 by Vishvananda Ishaya
floating ip commands
247
    return IMPL.floating_ip_get_all_by_host(context, host)
248
249
276.4.1 by Vishvananda Ishaya
implement floating_ip_get_all_by_project and renamed db methods that get more then one to get_all_by instead of get_by
250
def floating_ip_get_all_by_project(context, project_id):
251
    """Get all floating ips by project."""
252
    return IMPL.floating_ip_get_all_by_project(context, project_id)
253
254
237.1.51 by Vishvananda Ishaya
removed the last few references to models.py
255
def floating_ip_get_by_address(context, address):
237.1.63 by Vishvananda Ishaya
all tests pass again
256
    """Get a floating ip by address or raise if it doesn't exist."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
257
    return IMPL.floating_ip_get_by_address(context, address)
237.1.51 by Vishvananda Ishaya
removed the last few references to models.py
258
259
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
260
####################
261
569.1.37 by Cerberus
More typos
262
def migration_update(context, id, values):
569.1.80 by Cerberus
Pep8 cleanup
263
    """Update a migration instance"""
569.1.37 by Cerberus
More typos
264
    return IMPL.migration_update(context, id, values)
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
265
569.1.80 by Cerberus
Pep8 cleanup
266
569.1.9 by Cerberus
Added a bunch of stubbed out functionality
267
def migration_create(context, values):
268
    """Create a migration record"""
269
    return IMPL.migration_create(context, values)
270
569.1.80 by Cerberus
Pep8 cleanup
271
569.1.9 by Cerberus
Added a bunch of stubbed out functionality
272
def migration_get(context, migration_id):
273
    """Finds a migration by the id"""
274
    return IMPL.migration_get(context, migration_id)
275
569.1.80 by Cerberus
Pep8 cleanup
276
569.1.68 by Cerberus
Better exceptions
277
def migration_get_by_instance_and_status(context, instance_id, status):
569.1.9 by Cerberus
Added a bunch of stubbed out functionality
278
    """Finds a migration by the instance id its migrating"""
569.1.69 by Cerberus
fixed
279
    return IMPL.migration_get_by_instance_and_status(context, instance_id,
280
            status)
569.1.9 by Cerberus
Added a bunch of stubbed out functionality
281
282
####################
283
284
237.1.140 by Vishvananda Ishaya
simplified network instance association
285
def fixed_ip_associate(context, address, instance_id):
286
    """Associate fixed ip to instance.
287
288
    Raises if fixed ip is not available.
386.3.20 by Todd Willey
Pep-257 cleanups.
289
237.1.140 by Vishvananda Ishaya
simplified network instance association
290
    """
237.1.141 by Vishvananda Ishaya
fixed tests, added a flag for updating dhcp on disassociate
291
    return IMPL.fixed_ip_associate(context, address, instance_id)
237.1.140 by Vishvananda Ishaya
simplified network instance association
292
293
294
def fixed_ip_associate_pool(context, network_id, instance_id):
295
    """Find free ip in network and associate it to instance.
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
296
297
    Raises if one is not available.
386.3.20 by Todd Willey
Pep-257 cleanups.
298
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
299
    """
237.1.141 by Vishvananda Ishaya
fixed tests, added a flag for updating dhcp on disassociate
300
    return IMPL.fixed_ip_associate_pool(context, network_id, instance_id)
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
301
302
237.1.72 by Vishvananda Ishaya
more cleanup and pylint fixes
303
def fixed_ip_create(context, values):
237.1.56 by Vishvananda Ishaya
tests pass
304
    """Create a fixed ip from the values dictionary."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
305
    return IMPL.fixed_ip_create(context, values)
237.1.56 by Vishvananda Ishaya
tests pass
306
307
237.1.140 by Vishvananda Ishaya
simplified network instance association
308
def fixed_ip_disassociate(context, address):
309
    """Disassociate a fixed ip from an instance by address."""
237.1.141 by Vishvananda Ishaya
fixed tests, added a flag for updating dhcp on disassociate
310
    return IMPL.fixed_ip_disassociate(context, address)
237.1.56 by Vishvananda Ishaya
tests pass
311
312
276.6.1 by Vishvananda Ishaya
Periodic callback for services and managers. Added code to automatically disassociate stale ip addresses
313
def fixed_ip_disassociate_all_by_timeout(context, host, time):
386.3.20 by Todd Willey
Pep-257 cleanups.
314
    """Disassociate old fixed ips from host."""
276.6.1 by Vishvananda Ishaya
Periodic callback for services and managers. Added code to automatically disassociate stale ip addresses
315
    return IMPL.fixed_ip_disassociate_all_by_timeout(context, host, time)
316
317
687.1.1 by Christian Berendt
added new functionality to list all defined fixed ips
318
def fixed_ip_get_all(context):
319
    """Get all defined fixed ips."""
320
    return IMPL.fixed_ip_get_all(context)
321
322
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
323
def fixed_ip_get_by_address(context, address):
237.1.63 by Vishvananda Ishaya
all tests pass again
324
    """Get a fixed ip by address or raise if it does not exist."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
325
    return IMPL.fixed_ip_get_by_address(context, address)
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
326
327
584.2.18 by Trey Morris
added get IPs by instance
328
def fixed_ip_get_all_by_instance(context, instance_id):
329
    """Get fixed ips by instance or raise if none exist."""
330
    return IMPL.fixed_ip_get_all_by_instance(context, instance_id)
331
332
237.1.63 by Vishvananda Ishaya
all tests pass again
333
def fixed_ip_get_instance(context, address):
334
    """Get an instance for a fixed ip by address."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
335
    return IMPL.fixed_ip_get_instance(context, address)
237.1.63 by Vishvananda Ishaya
all tests pass again
336
462.1.16 by Hisaharu Ishii
Fixed for pep8
337
462.1.1 by NTT PF Lab.
Support IPv6
338
def fixed_ip_get_instance_v6(context, address):
339
    return IMPL.fixed_ip_get_instance_v6(context, address)
340
237.1.63 by Vishvananda Ishaya
all tests pass again
341
237.1.40 by Vishvananda Ishaya
run instances works
342
def fixed_ip_get_network(context, address):
237.1.48 by Vishvananda Ishaya
network tests pass again
343
    """Get a network for a fixed ip by address."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
344
    return IMPL.fixed_ip_get_network(context, address)
237.1.40 by Vishvananda Ishaya
run instances works
345
237.1.55 by Vishvananda Ishaya
moved network code into business layer
346
237.1.56 by Vishvananda Ishaya
tests pass
347
def fixed_ip_update(context, address, values):
348
    """Create a fixed ip from the values dictionary."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
349
    return IMPL.fixed_ip_update(context, address, values)
237.1.56 by Vishvananda Ishaya
tests pass
350
351
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
352
####################
353
354
237.1.28 by andy
Alphabetize the methods in the db layer.
355
def instance_create(context, values):
356
    """Create an instance from the values dictionary."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
357
    return IMPL.instance_create(context, values)
237.1.28 by andy
Alphabetize the methods in the db layer.
358
359
237.10.2 by Vishvananda Ishaya
database support for quotas
360
def instance_data_get_for_project(context, project_id):
361
    """Get (instance_count, core_count) for project."""
362
    return IMPL.instance_data_get_for_project(context, project_id)
363
237.10.3 by Vishvananda Ishaya
merged orm, added database methods for getting volume and ip data for projects
364
237.4.2 by andy
Data abstraction for compute service
365
def instance_destroy(context, instance_id):
366
    """Destroy the instance or raise if it does not exist."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
367
    return IMPL.instance_destroy(context, instance_id)
237.4.2 by andy
Data abstraction for compute service
368
369
370
def instance_get(context, instance_id):
371
    """Get an instance or raise if it does not exist."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
372
    return IMPL.instance_get(context, instance_id)
237.4.2 by andy
Data abstraction for compute service
373
374
237.5.1 by Jesse Andrews
getting run/terminate/describe to work
375
def instance_get_all(context):
237.1.35 by Vishvananda Ishaya
moving network code and fixing run_instances
376
    """Get all instances."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
377
    return IMPL.instance_get_all(context)
237.5.1 by Jesse Andrews
getting run/terminate/describe to work
378
375.2.3 by Eric Day
PEP8 cleanup in nova/db. There should be no functional changes here, just style changes to get violations down.
379
267.2.12 by Cerberus
db api call to get instances by user and user checking in each of the server actions
380
def instance_get_all_by_user(context, user_id):
381
    """Get all instances."""
341.2.1 by Michael Gundlach
Fix several problems keeping AuthMiddleware from functioning in the OpenStack API.
382
    return IMPL.instance_get_all_by_user(context, user_id)
237.5.1 by Jesse Andrews
getting run/terminate/describe to work
383
375.2.3 by Eric Day
PEP8 cleanup in nova/db. There should be no functional changes here, just style changes to get violations down.
384
276.4.1 by Vishvananda Ishaya
implement floating_ip_get_all_by_project and renamed db methods that get more then one to get_all_by instead of get_by
385
def instance_get_all_by_project(context, project_id):
237.1.35 by Vishvananda Ishaya
moving network code and fixing run_instances
386
    """Get all instance belonging to a project."""
276.4.1 by Vishvananda Ishaya
implement floating_ip_get_all_by_project and renamed db methods that get more then one to get_all_by instead of get_by
387
    return IMPL.instance_get_all_by_project(context, project_id)
388
389
604.3.1 by Soren Hansen
Add a host argument to virt driver's init_host method. It will be set to the name of host it's running on.
390
def instance_get_all_by_host(context, host):
391
    """Get all instance belonging to a host."""
392
    return IMPL.instance_get_all_by_host(context, host)
393
394
276.4.1 by Vishvananda Ishaya
implement floating_ip_get_all_by_project and renamed db methods that get more then one to get_all_by instead of get_by
395
def instance_get_all_by_reservation(context, reservation_id):
237.1.35 by Vishvananda Ishaya
moving network code and fixing run_instances
396
    """Get all instance belonging to a reservation."""
276.4.1 by Vishvananda Ishaya
implement floating_ip_get_all_by_project and renamed db methods that get more then one to get_all_by instead of get_by
397
    return IMPL.instance_get_all_by_reservation(context, reservation_id)
237.5.1 by Jesse Andrews
getting run/terminate/describe to work
398
399
237.1.46 by Vishvananda Ishaya
more data layer breakouts, lots of fixes to cloud.py
400
def instance_get_fixed_address(context, instance_id):
401
    """Get the fixed ip address of an instance."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
402
    return IMPL.instance_get_fixed_address(context, instance_id)
237.1.46 by Vishvananda Ishaya
more data layer breakouts, lots of fixes to cloud.py
403
462.1.16 by Hisaharu Ishii
Fixed for pep8
404
462.1.1 by NTT PF Lab.
Support IPv6
405
def instance_get_fixed_address_v6(context, instance_id):
406
    return IMPL.instance_get_fixed_address_v6(context, instance_id)
407
237.1.46 by Vishvananda Ishaya
more data layer breakouts, lots of fixes to cloud.py
408
409
def instance_get_floating_address(context, instance_id):
410
    """Get the first floating ip address of an instance."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
411
    return IMPL.instance_get_floating_address(context, instance_id)
237.1.46 by Vishvananda Ishaya
more data layer breakouts, lots of fixes to cloud.py
412
413
396.6.5 by Vishvananda Ishaya
add vpn ping and optimize vpn list
414
def instance_get_project_vpn(context, project_id):
415
    """Get a vpn instance by project or return None."""
416
    return IMPL.instance_get_project_vpn(context, project_id)
417
418
237.1.36 by Vishvananda Ishaya
bunch more fixes
419
def instance_is_vpn(context, instance_id):
420
    """True if instance is a vpn."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
421
    return IMPL.instance_is_vpn(context, instance_id)
237.1.36 by Vishvananda Ishaya
bunch more fixes
422
423
237.1.113 by Vishvananda Ishaya
consistent naming for instance_set_state
424
def instance_set_state(context, instance_id, state, description=None):
237.1.28 by andy
Alphabetize the methods in the db layer.
425
    """Set the state of an instance."""
237.1.113 by Vishvananda Ishaya
consistent naming for instance_set_state
426
    return IMPL.instance_set_state(context, instance_id, state, description)
237.1.28 by andy
Alphabetize the methods in the db layer.
427
428
237.1.27 by Vishvananda Ishaya
move volume code into datalayer and cleanup
429
def instance_update(context, instance_id, values):
430
    """Set the given properties on an instance and update it.
431
432
    Raises NotFound if instance does not exist.
433
434
    """
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
435
    return IMPL.instance_update(context, instance_id, values)
237.1.27 by Vishvananda Ishaya
move volume code into datalayer and cleanup
436
437
265.2.12 by Soren Hansen
Filters all get defined when running an instance.
438
def instance_add_security_group(context, instance_id, security_group_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
439
    """Associate the given security group with the given instance."""
375.2.3 by Eric Day
PEP8 cleanup in nova/db. There should be no functional changes here, just style changes to get violations down.
440
    return IMPL.instance_add_security_group(context, instance_id,
441
                                            security_group_id)
265.2.12 by Soren Hansen
Filters all get defined when running an instance.
442
443
466.6.2 by Vishvananda Ishaya
merge trunk and upgrade to cheetah templating
444
def instance_action_create(context, values):
445
    """Create an instance action from the values dictionary."""
446
    return IMPL.instance_action_create(context, values)
447
448
466.3.22 by Josh Kearney
Added InstanceAction DB functions
449
def instance_get_actions(context, instance_id):
450
    """Get instance actions by instance id."""
451
    return IMPL.instance_get_actions(context, instance_id)
452
453
237.11.1 by Vishvananda Ishaya
moved keypairs to db using the same interface
454
###################
455
456
237.11.5 by Vishvananda Ishaya
fixed old key reference and made keypair name constistent -> key_pair
457
def key_pair_create(context, values):
458
    """Create a key_pair from the values dictionary."""
459
    return IMPL.key_pair_create(context, values)
460
461
462
def key_pair_destroy(context, user_id, name):
463
    """Destroy the key_pair or raise if it does not exist."""
464
    return IMPL.key_pair_destroy(context, user_id, name)
465
466
467
def key_pair_destroy_all_by_user(context, user_id):
468
    """Destroy all key_pairs by user."""
469
    return IMPL.key_pair_destroy_all_by_user(context, user_id)
470
471
472
def key_pair_get(context, user_id, name):
473
    """Get a key_pair or raise if it does not exist."""
474
    return IMPL.key_pair_get(context, user_id, name)
475
476
477
def key_pair_get_all_by_user(context, user_id):
478
    """Get all key_pairs by user."""
479
    return IMPL.key_pair_get_all_by_user(context, user_id)
237.11.1 by Vishvananda Ishaya
moved keypairs to db using the same interface
480
481
237.1.28 by andy
Alphabetize the methods in the db layer.
482
####################
483
484
292.8.3 by Vishvananda Ishaya
get rid of network indexes and make networks into a pool
485
def network_associate(context, project_id):
486
    """Associate a free network to a project."""
487
    return IMPL.network_associate(context, project_id)
488
489
237.1.51 by Vishvananda Ishaya
removed the last few references to models.py
490
def network_count(context):
491
    """Return the number of networks."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
492
    return IMPL.network_count(context)
237.1.51 by Vishvananda Ishaya
removed the last few references to models.py
493
494
495
def network_count_allocated_ips(context, network_id):
496
    """Return the number of allocated non-reserved ips in the network."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
497
    return IMPL.network_count_allocated_ips(context, network_id)
237.1.51 by Vishvananda Ishaya
removed the last few references to models.py
498
499
500
def network_count_available_ips(context, network_id):
501
    """Return the number of available ips in the network."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
502
    return IMPL.network_count_available_ips(context, network_id)
237.1.51 by Vishvananda Ishaya
removed the last few references to models.py
503
504
505
def network_count_reserved_ips(context, network_id):
506
    """Return the number of reserved ips in the network."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
507
    return IMPL.network_count_reserved_ips(context, network_id)
237.1.51 by Vishvananda Ishaya
removed the last few references to models.py
508
509
292.8.3 by Vishvananda Ishaya
get rid of network indexes and make networks into a pool
510
def network_create_safe(context, values):
386.3.20 by Todd Willey
Pep-257 cleanups.
511
    """Create a network from the values dict.
292.8.3 by Vishvananda Ishaya
get rid of network indexes and make networks into a pool
512
513
    The network is only returned if the create succeeds. If the create violates
386.3.20 by Todd Willey
Pep-257 cleanups.
514
    constraints because the network already exists, no exception is raised.
386.2.21 by Vishvananda Ishaya
pep8 whitespace and line length fixes
515
386.3.20 by Todd Willey
Pep-257 cleanups.
516
    """
292.8.3 by Vishvananda Ishaya
get rid of network indexes and make networks into a pool
517
    return IMPL.network_create_safe(context, values)
237.1.28 by andy
Alphabetize the methods in the db layer.
518
519
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
520
def network_create_fixed_ips(context, network_id, num_vpn_clients):
521
    """Create the ips for the network, reserving sepecified ips."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
522
    return IMPL.network_create_fixed_ips(context, network_id, num_vpn_clients)
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
523
524
292.8.3 by Vishvananda Ishaya
get rid of network indexes and make networks into a pool
525
def network_disassociate(context, network_id):
526
    """Disassociate the network from project or raise if it does not exist."""
527
    return IMPL.network_disassociate(context, network_id)
528
529
530
def network_disassociate_all(context):
531
    """Disassociate all networks from projects."""
532
    return IMPL.network_disassociate_all(context)
237.1.28 by andy
Alphabetize the methods in the db layer.
533
534
535
def network_get(context, network_id):
536
    """Get an network or raise if it does not exist."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
537
    return IMPL.network_get(context, network_id)
538
539
679.1.1 by Christian Berendt
added functionality to nova-manage to list created networks
540
def network_get_all(context):
541
    """Return all defined networks."""
542
    return IMPL.network_get_all(context)
543
544
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
545
# pylint: disable-msg=C0103
237.1.40 by Vishvananda Ishaya
run instances works
546
def network_get_associated_fixed_ips(context, network_id):
547
    """Get all network's ips that have been associated."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
548
    return IMPL.network_get_associated_fixed_ips(context, network_id)
237.1.40 by Vishvananda Ishaya
run instances works
549
237.1.48 by Vishvananda Ishaya
network tests pass again
550
237.1.40 by Vishvananda Ishaya
run instances works
551
def network_get_by_bridge(context, bridge):
292.8.6 by Vishvananda Ishaya
Fixed flat network manager with network index gone.
552
    """Get a network by bridge or raise if it does not exist."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
553
    return IMPL.network_get_by_bridge(context, bridge)
237.1.40 by Vishvananda Ishaya
run instances works
554
555
292.8.6 by Vishvananda Ishaya
Fixed flat network manager with network index gone.
556
def network_get_by_instance(context, instance_id):
557
    """Get a network by instance id or raise if it does not exist."""
558
    return IMPL.network_get_by_instance(context, instance_id)
559
560
584.2.15 by Trey Morris
forgot to add network_get_all_by_instance to db.api
561
def network_get_all_by_instance(context, instance_id):
584.2.28 by Trey Morris
comments + Englilish, changed copyright in migration, removed network_get_all from db.api (vestigial)
562
    """Get all networks by instance id or raise if none exist."""
584.2.15 by Trey Morris
forgot to add network_get_all_by_instance to db.api
563
    return IMPL.network_get_all_by_instance(context, instance_id)
564
565
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
566
def network_get_index(context, network_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
567
    """Get non-conflicting index for network."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
568
    return IMPL.network_get_index(context, network_id)
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
569
570
237.1.35 by Vishvananda Ishaya
moving network code and fixing run_instances
571
def network_get_vpn_ip(context, network_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
572
    """Get non-conflicting index for network."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
573
    return IMPL.network_get_vpn_ip(context, network_id)
237.1.35 by Vishvananda Ishaya
moving network code and fixing run_instances
574
575
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
576
def network_set_cidr(context, network_id, cidr):
386.3.20 by Todd Willey
Pep-257 cleanups.
577
    """Set the Classless Inner Domain Routing for the network."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
578
    return IMPL.network_set_cidr(context, network_id, cidr)
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
579
580
581
def network_set_host(context, network_id, host_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
582
    """Safely set the host for network."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
583
    return IMPL.network_set_host(context, network_id, host_id)
237.1.31 by Vishvananda Ishaya
Refactored network model access into data abstraction layer.
584
585
237.1.28 by andy
Alphabetize the methods in the db layer.
586
def network_update(context, network_id, values):
587
    """Set the given properties on an network and update it.
588
589
    Raises NotFound if network does not exist.
590
591
    """
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
592
    return IMPL.network_update(context, network_id, values)
237.1.28 by andy
Alphabetize the methods in the db layer.
593
594
595
###################
596
597
396.6.13 by Vishvananda Ishaya
update db/api.py as well
598
def project_get_network(context, project_id, associate=True):
316.8.1 by Ewan Mellor
Bug #654025: nova-manage project zip and nova-manage vpn list broken by change in DB semantics when networks are missing
599
    """Return the network associated with the project.
600
396.6.13 by Vishvananda Ishaya
update db/api.py as well
601
    If associate is true, it will attempt to associate a new
602
    network if one is not found, otherwise it returns None.
316.8.1 by Ewan Mellor
Bug #654025: nova-manage project zip and nova-manage vpn list broken by change in DB semantics when networks are missing
603
604
    """
396.6.13 by Vishvananda Ishaya
update db/api.py as well
605
696.1.1 by Vishvananda Ishaya
Correctly pass the associate paramater to project_get_network
606
    return IMPL.project_get_network(context, project_id, associate)
237.1.30 by andy
Moves auth.manager to the data layer.
607
462.1.16 by Hisaharu Ishii
Fixed for pep8
608
462.1.1 by NTT PF Lab.
Support IPv6
609
def project_get_network_v6(context, project_id):
610
    return IMPL.project_get_network_v6(context, project_id)
611
237.1.30 by andy
Moves auth.manager to the data layer.
612
613
###################
614
615
237.5.1 by Jesse Andrews
getting run/terminate/describe to work
616
def queue_get_for(context, topic, physical_node_id):
617
    """Return a channel to send a message to a node with a topic."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
618
    return IMPL.queue_get_for(context, topic, physical_node_id)
237.5.1 by Jesse Andrews
getting run/terminate/describe to work
619
620
621
###################
622
623
237.1.53 by Vishvananda Ishaya
split volume into service/manager/driver
624
def export_device_count(context):
625
    """Return count of export devices."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
626
    return IMPL.export_device_count(context)
237.1.53 by Vishvananda Ishaya
split volume into service/manager/driver
627
628
276.8.4 by Vishvananda Ishaya
allow multiple volumes to run ensure_blades without creating duplicates
629
def export_device_create_safe(context, values):
630
    """Create an export_device from the values dictionary.
631
632
    The device is not returned. If the create violates the unique
633
    constraints because the shelf_id and blade_id already exist,
386.3.20 by Todd Willey
Pep-257 cleanups.
634
    no exception is raised.
386.2.21 by Vishvananda Ishaya
pep8 whitespace and line length fixes
635
386.3.20 by Todd Willey
Pep-257 cleanups.
636
    """
276.8.4 by Vishvananda Ishaya
allow multiple volumes to run ensure_blades without creating duplicates
637
    return IMPL.export_device_create_safe(context, values)
276.2.2 by Cerberus
Refactored the auth branch based on review feedback
638
639
640
###################
641
237.1.53 by Vishvananda Ishaya
split volume into service/manager/driver
642
379.3.7 by Vishvananda Ishaya
renamed target_id to iscsi_target
643
def iscsi_target_count_by_host(context, host):
379.3.1 by Vishvananda Ishaya
ISCSI Volume support
644
    """Return count of export devices."""
379.3.7 by Vishvananda Ishaya
renamed target_id to iscsi_target
645
    return IMPL.iscsi_target_count_by_host(context, host)
646
647
648
def iscsi_target_create_safe(context, values):
649
    """Create an iscsi_target from the values dictionary.
379.3.1 by Vishvananda Ishaya
ISCSI Volume support
650
651
    The device is not returned. If the create violates the unique
379.3.7 by Vishvananda Ishaya
renamed target_id to iscsi_target
652
    constraints because the iscsi_target and host already exist,
379.3.1 by Vishvananda Ishaya
ISCSI Volume support
653
    no exception is raised."""
379.3.7 by Vishvananda Ishaya
renamed target_id to iscsi_target
654
    return IMPL.iscsi_target_create_safe(context, values)
379.3.1 by Vishvananda Ishaya
ISCSI Volume support
655
656
657
###############
658
659
738.1.2 by Todd Willey
Pass id of token to be deleted to the db api, not the actual object.
660
def auth_token_destroy(context, token_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
661
    """Destroy an auth token."""
738.1.2 by Todd Willey
Pass id of token to be deleted to the db api, not the actual object.
662
    return IMPL.auth_token_destroy(context, token_id)
738.1.1 by Todd Willey
Rename auth_token db methods to follow standard.
663
664
665
def auth_token_get(context, token_hash):
386.3.20 by Todd Willey
Pep-257 cleanups.
666
    """Retrieves a token given the hash representing it."""
738.1.1 by Todd Willey
Rename auth_token db methods to follow standard.
667
    return IMPL.auth_token_get(context, token_hash)
668
669
740.1.1 by Kevin L. Mitchell
Copy over to current trunk my tests, the 401/500 fix, and a couple of
670
def auth_token_update(context, token_hash, values):
671
    """Updates a token given the hash representing it."""
672
    return IMPL.auth_token_update(context, token_hash, values)
673
674
738.1.1 by Todd Willey
Rename auth_token db methods to follow standard.
675
def auth_token_create(context, token):
386.3.20 by Todd Willey
Pep-257 cleanups.
676
    """Creates a new token."""
738.1.1 by Todd Willey
Rename auth_token db methods to follow standard.
677
    return IMPL.auth_token_create(context, token)
276.2.2 by Cerberus
Refactored the auth branch based on review feedback
678
679
680
###################
681
237.1.53 by Vishvananda Ishaya
split volume into service/manager/driver
682
237.10.2 by Vishvananda Ishaya
database support for quotas
683
def quota_create(context, values):
684
    """Create a quota from the values dictionary."""
685
    return IMPL.quota_create(context, values)
686
687
688
def quota_get(context, project_id):
689
    """Retrieve a quota or raise if it does not exist."""
690
    return IMPL.quota_get(context, project_id)
691
692
693
def quota_update(context, project_id, values):
694
    """Update a quota from the values dictionary."""
695
    return IMPL.quota_update(context, project_id, values)
696
697
698
def quota_destroy(context, project_id):
699
    """Destroy the quota or raise if it does not exist."""
700
    return IMPL.quota_destroy(context, project_id)
701
702
703
###################
704
705
237.1.28 by andy
Alphabetize the methods in the db layer.
706
def volume_allocate_shelf_and_blade(context, volume_id):
707
    """Atomically allocate a free shelf and blade from the pool."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
708
    return IMPL.volume_allocate_shelf_and_blade(context, volume_id)
237.1.28 by andy
Alphabetize the methods in the db layer.
709
710
379.3.7 by Vishvananda Ishaya
renamed target_id to iscsi_target
711
def volume_allocate_iscsi_target(context, volume_id, host):
712
    """Atomically allocate a free iscsi_target from the pool."""
713
    return IMPL.volume_allocate_iscsi_target(context, volume_id, host)
379.3.1 by Vishvananda Ishaya
ISCSI Volume support
714
715
237.1.28 by andy
Alphabetize the methods in the db layer.
716
def volume_attached(context, volume_id, instance_id, mountpoint):
717
    """Ensure that a volume is set as attached."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
718
    return IMPL.volume_attached(context, volume_id, instance_id, mountpoint)
237.1.28 by andy
Alphabetize the methods in the db layer.
719
720
721
def volume_create(context, values):
722
    """Create a volume from the values dictionary."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
723
    return IMPL.volume_create(context, values)
237.4.2 by andy
Data abstraction for compute service
724
725
237.10.3 by Vishvananda Ishaya
merged orm, added database methods for getting volume and ip data for projects
726
def volume_data_get_for_project(context, project_id):
727
    """Get (volume_count, gigabytes) for project."""
728
    return IMPL.volume_data_get_for_project(context, project_id)
729
730
237.1.27 by Vishvananda Ishaya
move volume code into datalayer and cleanup
731
def volume_destroy(context, volume_id):
732
    """Destroy the volume or raise if it does not exist."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
733
    return IMPL.volume_destroy(context, volume_id)
237.4.2 by andy
Data abstraction for compute service
734
735
237.1.28 by andy
Alphabetize the methods in the db layer.
736
def volume_detached(context, volume_id):
737
    """Ensure that a volume is set as detached."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
738
    return IMPL.volume_detached(context, volume_id)
237.1.28 by andy
Alphabetize the methods in the db layer.
739
740
237.4.2 by andy
Data abstraction for compute service
741
def volume_get(context, volume_id):
742
    """Get a volume or raise if it does not exist."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
743
    return IMPL.volume_get(context, volume_id)
237.4.2 by andy
Data abstraction for compute service
744
745
237.5.9 by Jesse Andrews
work towards volumes using db layer
746
def volume_get_all(context):
747
    """Get all volumes."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
748
    return IMPL.volume_get_all(context)
237.5.9 by Jesse Andrews
work towards volumes using db layer
749
750
379.3.1 by Vishvananda Ishaya
ISCSI Volume support
751
def volume_get_all_by_host(context, host):
752
    """Get all volumes belonging to a host."""
753
    return IMPL.volume_get_all_by_host(context, host)
237.1.93 by Vishvananda Ishaya
Lots of fixes to make the nova commands work properly and make datamodel work with mysql properly
754
755
276.4.1 by Vishvananda Ishaya
implement floating_ip_get_all_by_project and renamed db methods that get more then one to get_all_by instead of get_by
756
def volume_get_all_by_project(context, project_id):
237.5.9 by Jesse Andrews
work towards volumes using db layer
757
    """Get all volumes belonging to a project."""
276.4.1 by Vishvananda Ishaya
implement floating_ip_get_all_by_project and renamed db methods that get more then one to get_all_by instead of get_by
758
    return IMPL.volume_get_all_by_project(context, project_id)
237.5.9 by Jesse Andrews
work towards volumes using db layer
759
760
292.3.1 by Devin Carlen
Implemented random instance and volume strings for ec2 api
761
def volume_get_by_ec2_id(context, ec2_id):
762
    """Get a volume by ec2 id."""
763
    return IMPL.volume_get_by_ec2_id(context, ec2_id)
237.1.46 by Vishvananda Ishaya
more data layer breakouts, lots of fixes to cloud.py
764
765
379.3.1 by Vishvananda Ishaya
ISCSI Volume support
766
def volume_get_instance(context, volume_id):
767
    """Get the instance that a volume is attached to."""
768
    return IMPL.volume_get_instance(context, volume_id)
769
770
237.1.28 by andy
Alphabetize the methods in the db layer.
771
def volume_get_shelf_and_blade(context, volume_id):
772
    """Get the shelf and blade allocated to the volume."""
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
773
    return IMPL.volume_get_shelf_and_blade(context, volume_id)
237.4.2 by andy
Data abstraction for compute service
774
237.1.27 by Vishvananda Ishaya
move volume code into datalayer and cleanup
775
379.3.7 by Vishvananda Ishaya
renamed target_id to iscsi_target
776
def volume_get_iscsi_target_num(context, volume_id):
777
    """Get the target num (tid) allocated to the volume."""
778
    return IMPL.volume_get_iscsi_target_num(context, volume_id)
379.3.1 by Vishvananda Ishaya
ISCSI Volume support
779
780
237.1.27 by Vishvananda Ishaya
move volume code into datalayer and cleanup
781
def volume_update(context, volume_id, values):
782
    """Set the given properties on an volume and update it.
783
784
    Raises NotFound if volume does not exist.
785
786
    """
237.1.79 by Vishvananda Ishaya
pylint cleanup of db classes
787
    return IMPL.volume_update(context, volume_id, values)
265.2.3 by Soren Hansen
Alright, first hole poked all the way through. We can now create security groups and read them back.
788
265.3.1 by Devin Carlen
Refactored to security group api to support projects
789
265.2.3 by Soren Hansen
Alright, first hole poked all the way through. We can now create security groups and read them back.
790
####################
791
792
265.3.1 by Devin Carlen
Refactored to security group api to support projects
793
def security_group_get_all(context):
386.3.20 by Todd Willey
Pep-257 cleanups.
794
    """Get all security groups."""
265.3.1 by Devin Carlen
Refactored to security group api to support projects
795
    return IMPL.security_group_get_all(context)
796
797
798
def security_group_get(context, security_group_id):
453.3.1 by Eric Day
Converted the instance table to use a uuid instead of a auto_increment ID and a random internal_id. I had to use a String(32) column with hex and not a String(16) with bytes because SQLAlchemy doesn't like non-unicode strings going in for String types. We could try another type, but I didn't want a primary_key on blob types.
799
    """Get security group by its id."""
265.3.1 by Devin Carlen
Refactored to security group api to support projects
800
    return IMPL.security_group_get(context, security_group_id)
801
802
803
def security_group_get_by_name(context, project_id, group_name):
386.3.20 by Todd Willey
Pep-257 cleanups.
804
    """Returns a security group with the specified name from a project."""
265.2.26 by Soren Hansen
Clean up use of ORM to remove the need for scoped_session.
805
    return IMPL.security_group_get_by_name(context, project_id, group_name)
265.3.1 by Devin Carlen
Refactored to security group api to support projects
806
807
808
def security_group_get_by_project(context, project_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
809
    """Get all security groups belonging to a project."""
265.2.26 by Soren Hansen
Clean up use of ORM to remove the need for scoped_session.
810
    return IMPL.security_group_get_by_project(context, project_id)
265.2.6 by Soren Hansen
Create and delete security groups works.
811
812
265.2.3 by Soren Hansen
Alright, first hole poked all the way through. We can now create security groups and read them back.
813
def security_group_get_by_instance(context, instance_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
814
    """Get security groups to which the instance is assigned."""
265.2.3 by Soren Hansen
Alright, first hole poked all the way through. We can now create security groups and read them back.
815
    return IMPL.security_group_get_by_instance(context, instance_id)
816
817
265.7.3 by Vishvananda Ishaya
fix join and misnamed method
818
def security_group_exists(context, project_id, group_name):
386.3.20 by Todd Willey
Pep-257 cleanups.
819
    """Indicates if a group name exists in a project."""
265.2.26 by Soren Hansen
Clean up use of ORM to remove the need for scoped_session.
820
    return IMPL.security_group_exists(context, project_id, group_name)
265.3.4 by Devin Carlen
Security Group API layer cleanup
821
822
265.3.1 by Devin Carlen
Refactored to security group api to support projects
823
def security_group_create(context, values):
386.3.20 by Todd Willey
Pep-257 cleanups.
824
    """Create a new security group."""
265.3.1 by Devin Carlen
Refactored to security group api to support projects
825
    return IMPL.security_group_create(context, values)
265.5.1 by Vishvananda Ishaya
merged trunk and fixed errors
826
265.2.4 by Soren Hansen
AuthorizeSecurityGroupIngress now works.
827
265.2.3 by Soren Hansen
Alright, first hole poked all the way through. We can now create security groups and read them back.
828
def security_group_destroy(context, security_group_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
829
    """Deletes a security group."""
265.2.3 by Soren Hansen
Alright, first hole poked all the way through. We can now create security groups and read them back.
830
    return IMPL.security_group_destroy(context, security_group_id)
265.2.4 by Soren Hansen
AuthorizeSecurityGroupIngress now works.
831
832
265.6.1 by Vishvananda Ishaya
move default group creation to api
833
def security_group_destroy_all(context):
386.3.20 by Todd Willey
Pep-257 cleanups.
834
    """Deletes a security group."""
265.6.1 by Vishvananda Ishaya
move default group creation to api
835
    return IMPL.security_group_destroy_all(context)
836
837
265.2.4 by Soren Hansen
AuthorizeSecurityGroupIngress now works.
838
####################
839
840
841
def security_group_rule_create(context, values):
386.3.20 by Todd Willey
Pep-257 cleanups.
842
    """Create a new security group."""
265.2.4 by Soren Hansen
AuthorizeSecurityGroupIngress now works.
843
    return IMPL.security_group_rule_create(context, values)
265.2.5 by Soren Hansen
Authorize and Revoke access now works.
844
845
846
def security_group_rule_get_by_security_group(context, security_group_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
847
    """Get all rules for a a given security group."""
375.2.3 by Eric Day
PEP8 cleanup in nova/db. There should be no functional changes here, just style changes to get violations down.
848
    return IMPL.security_group_rule_get_by_security_group(context,
849
                                                          security_group_id)
850
265.2.5 by Soren Hansen
Authorize and Revoke access now works.
851
430.3.8 by Soren Hansen
Move security group refresh logic into ComputeAPI.
852
def security_group_rule_get_by_security_group_grantee(context,
853
                                                      security_group_id):
854
    """Get all rules that grant access to the given security group."""
855
    return IMPL.security_group_rule_get_by_security_group_grantee(context,
430.3.11 by Soren Hansen
Lots of PEP-8 work.
856
                                                             security_group_id)
430.3.8 by Soren Hansen
Move security group refresh logic into ComputeAPI.
857
858
265.2.5 by Soren Hansen
Authorize and Revoke access now works.
859
def security_group_rule_destroy(context, security_group_rule_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
860
    """Deletes a security group rule."""
265.2.5 by Soren Hansen
Authorize and Revoke access now works.
861
    return IMPL.security_group_rule_destroy(context, security_group_rule_id)
265.2.49 by Soren Hansen
Merge trunk
862
863
292.7.2 by Soren Hansen
Add db api methods for retrieving the networks for which a host is the designated network host.
864
###################
865
866
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
867
def user_get(context, id):
386.3.20 by Todd Willey
Pep-257 cleanups.
868
    """Get user by id."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
869
    return IMPL.user_get(context, id)
870
871
872
def user_get_by_uid(context, uid):
386.3.20 by Todd Willey
Pep-257 cleanups.
873
    """Get user by uid."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
874
    return IMPL.user_get_by_uid(context, uid)
875
876
877
def user_get_by_access_key(context, access_key):
386.3.20 by Todd Willey
Pep-257 cleanups.
878
    """Get user by access key."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
879
    return IMPL.user_get_by_access_key(context, access_key)
880
881
882
def user_create(context, values):
386.3.20 by Todd Willey
Pep-257 cleanups.
883
    """Create a new user."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
884
    return IMPL.user_create(context, values)
885
886
887
def user_delete(context, id):
386.3.20 by Todd Willey
Pep-257 cleanups.
888
    """Delete a user."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
889
    return IMPL.user_delete(context, id)
890
891
892
def user_get_all(context):
386.3.20 by Todd Willey
Pep-257 cleanups.
893
    """Create a new user."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
894
    return IMPL.user_get_all(context)
895
896
897
def user_add_role(context, user_id, role):
386.3.20 by Todd Willey
Pep-257 cleanups.
898
    """Add another global role for user."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
899
    return IMPL.user_add_role(context, user_id, role)
900
901
902
def user_remove_role(context, user_id, role):
386.3.20 by Todd Willey
Pep-257 cleanups.
903
    """Remove global role from user."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
904
    return IMPL.user_remove_role(context, user_id, role)
905
906
907
def user_get_roles(context, user_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
908
    """Get global roles for user."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
909
    return IMPL.user_get_roles(context, user_id)
910
911
912
def user_add_project_role(context, user_id, project_id, role):
386.3.20 by Todd Willey
Pep-257 cleanups.
913
    """Add project role for user."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
914
    return IMPL.user_add_project_role(context, user_id, project_id, role)
915
916
917
def user_remove_project_role(context, user_id, project_id, role):
386.3.20 by Todd Willey
Pep-257 cleanups.
918
    """Remove project role from user."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
919
    return IMPL.user_remove_project_role(context, user_id, project_id, role)
920
921
922
def user_get_roles_for_project(context, user_id, project_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
923
    """Return list of roles a user holds on project."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
924
    return IMPL.user_get_roles_for_project(context, user_id, project_id)
925
926
927
def user_update(context, user_id, values):
386.3.20 by Todd Willey
Pep-257 cleanups.
928
    """Update user."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
929
    return IMPL.user_update(context, user_id, values)
930
931
932
def project_get(context, id):
386.3.20 by Todd Willey
Pep-257 cleanups.
933
    """Get project by id."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
934
    return IMPL.project_get(context, id)
935
936
937
def project_create(context, values):
386.3.20 by Todd Willey
Pep-257 cleanups.
938
    """Create a new project."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
939
    return IMPL.project_create(context, values)
940
941
942
def project_add_member(context, project_id, user_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
943
    """Add user to project."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
944
    return IMPL.project_add_member(context, project_id, user_id)
945
946
947
def project_get_all(context):
386.3.20 by Todd Willey
Pep-257 cleanups.
948
    """Get all projects."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
949
    return IMPL.project_get_all(context)
950
951
952
def project_get_by_user(context, user_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
953
    """Get all projects of which the given user is a member."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
954
    return IMPL.project_get_by_user(context, user_id)
955
956
957
def project_remove_member(context, project_id, user_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
958
    """Remove the given user from the given project."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
959
    return IMPL.project_remove_member(context, project_id, user_id)
960
961
962
def project_update(context, project_id, values):
386.3.20 by Todd Willey
Pep-257 cleanups.
963
    """Update Remove the given user from the given project."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
964
    return IMPL.project_update(context, project_id, values)
965
966
967
def project_delete(context, project_id):
386.3.20 by Todd Willey
Pep-257 cleanups.
968
    """Delete project."""
306.3.1 by Soren Hansen
Add a DB backend for auth manager.
969
    return IMPL.project_delete(context, project_id)
306.3.5 by Soren Hansen
Merge trunk. Again.
970
971
972
###################
973
974
292.7.2 by Soren Hansen
Add db api methods for retrieving the networks for which a host is the designated network host.
975
def host_get_networks(context, host):
976
    """Return all networks for which the given host is the designated
386.3.20 by Todd Willey
Pep-257 cleanups.
977
    network host.
978
292.7.2 by Soren Hansen
Add db api methods for retrieving the networks for which a host is the designated network host.
979
    """
980
    return IMPL.host_get_networks(context, host)
439.1.1 by masumotok
rev439ベースにライブマイグレーションの機能をマージ
981
982
498.3.1 by Monsyne Dragon
add in xs-console worker and tests.
983
##################
984
498.3.4 by Monsyne Dragon
Fix a bunch of pep8 stuff
985
498.3.1 by Monsyne Dragon
add in xs-console worker and tests.
986
def console_pool_create(context, values):
987
    """Create console pool."""
988
    return IMPL.console_pool_create(context, values)
989
498.3.4 by Monsyne Dragon
Fix a bunch of pep8 stuff
990
498.3.1 by Monsyne Dragon
add in xs-console worker and tests.
991
def console_pool_get(context, pool_id):
992
    """Get a console pool."""
993
    return IMPL.console_pool_get(context, pool_id)
994
995
996
def console_pool_get_by_host_type(context, compute_host, proxy_host,
997
                                  console_type):
998
    """Fetch a console pool for a given proxy host, compute host, and type."""
999
    return IMPL.console_pool_get_by_host_type(context,
1000
                                              compute_host,
1001
                                              proxy_host,
1002
                                              console_type)
1003
1004
1005
def console_pool_get_all_by_host_type(context, host, console_type):
1006
    """Fetch all pools for given proxy host and type."""
1007
    return IMPL.console_pool_get_all_by_host_type(context,
1008
                                                  host,
1009
                                                  console_type)
1010
1011
498.3.4 by Monsyne Dragon
Fix a bunch of pep8 stuff
1012
def console_create(context, values):
498.3.1 by Monsyne Dragon
add in xs-console worker and tests.
1013
    """Create a console."""
1014
    return IMPL.console_create(context, values)
1015
498.3.4 by Monsyne Dragon
Fix a bunch of pep8 stuff
1016
498.3.1 by Monsyne Dragon
add in xs-console worker and tests.
1017
def console_delete(context, console_id):
1018
    """Delete a console."""
1019
    return IMPL.console_delete(context, console_id)
1020
498.3.4 by Monsyne Dragon
Fix a bunch of pep8 stuff
1021
498.3.1 by Monsyne Dragon
add in xs-console worker and tests.
1022
def console_get_by_pool_instance(context, pool_id, instance_id):
1023
    """Get console entry for a given instance and pool."""
1024
    return IMPL.console_get_by_pool_instance(context, pool_id, instance_id)
1025
498.3.4 by Monsyne Dragon
Fix a bunch of pep8 stuff
1026
498.3.2 by Monsyne Dragon
pulled changes from trunk
1027
def console_get_all_by_instance(context, instance_id):
1028
    """Get consoles for a given instance."""
1029
    return IMPL.console_get_all_by_instance(context, instance_id)
1030
498.3.4 by Monsyne Dragon
Fix a bunch of pep8 stuff
1031
498.3.2 by Monsyne Dragon
pulled changes from trunk
1032
def console_get(context, console_id, instance_id=None):
1033
    """Get a specific console (possibly on a given instance)."""
1034
    return IMPL.console_get(context, console_id, instance_id)
635.2.1 by Sandy Walsh
Working on api / manager / db support for zones
1035
1036
1037
####################
1038
1039
635.2.5 by Sandy Walsh
template adjusted to NOVA_TOOLS, zone db & os api layers added
1040
def zone_create(context, values):
635.2.11 by Sandy Walsh
fixed nova-combined debug hack and renamed ChildZone to Zone
1041
    """Create a new child Zone entry."""
635.2.5 by Sandy Walsh
template adjusted to NOVA_TOOLS, zone db & os api layers added
1042
    return IMPL.zone_create(context, values)
1043
1044
1045
def zone_update(context, zone_id, values):
635.2.11 by Sandy Walsh
fixed nova-combined debug hack and renamed ChildZone to Zone
1046
    """Update a child Zone entry."""
635.2.5 by Sandy Walsh
template adjusted to NOVA_TOOLS, zone db & os api layers added
1047
    return IMPL.zone_update(context, values)
1048
1049
1050
def zone_delete(context, zone_id):
635.2.11 by Sandy Walsh
fixed nova-combined debug hack and renamed ChildZone to Zone
1051
    """Delete a child Zone."""
635.2.5 by Sandy Walsh
template adjusted to NOVA_TOOLS, zone db & os api layers added
1052
    return IMPL.zone_delete(context, zone_id)
1053
1054
1055
def zone_get(context, zone_id):
635.2.11 by Sandy Walsh
fixed nova-combined debug hack and renamed ChildZone to Zone
1056
    """Get a specific child Zone."""
635.2.5 by Sandy Walsh
template adjusted to NOVA_TOOLS, zone db & os api layers added
1057
    return IMPL.zone_get(context, zone_id)
1058
1059
1060
def zone_get_all(context):
635.2.11 by Sandy Walsh
fixed nova-combined debug hack and renamed ChildZone to Zone
1061
    """Get all child Zones."""
635.2.5 by Sandy Walsh
template adjusted to NOVA_TOOLS, zone db & os api layers added
1062
    return IMPL.zone_get_all(context)