~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to cinder/quota.py

  • Committer: Package Import Robot
  • Author(s): Chris J Arges
  • Date: 2013-01-15 10:10:28 UTC
  • mfrom: (7.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130115101028-i1jf2lyewii1xf2e
Tags: 2013.1~g2-0ubuntu2
debian/patches/series: Enable skip_failed_tests to fix FTBFS. 

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
 
"""Quotas for instances, volumes, and floating ips."""
 
19
"""Quotas for volumes."""
20
20
 
21
21
import datetime
22
22
 
49
49
               help='number of seconds between subsequent usage refreshes'),
50
50
    cfg.StrOpt('quota_driver',
51
51
               default='cinder.quota.DbQuotaDriver',
52
 
               help='default driver to use for quota checks'),
53
 
    ]
 
52
               help='default driver to use for quota checks'), ]
54
53
 
55
54
FLAGS = flags.FLAGS
56
55
FLAGS.register_opts(quota_opts)
156
155
                continue
157
156
 
158
157
            quotas[resource.name] = dict(
159
 
                limit=project_quotas.get(resource.name, class_quotas.get(
160
 
                        resource.name, resource.default)),
161
 
                )
 
158
                limit=project_quotas.get(resource.name,
 
159
                                         class_quotas.get(resource.name,
 
160
                                                          resource.default)), )
162
161
 
163
162
            # Include usages if desired.  This is optional because one
164
163
            # internal consumer of this interface wants to access the
167
166
                usage = project_usages.get(resource.name, {})
168
167
                quotas[resource.name].update(
169
168
                    in_use=usage.get('in_use', 0),
170
 
                    reserved=usage.get('reserved', 0),
171
 
                    )
 
169
                    reserved=usage.get('reserved', 0), )
172
170
 
173
171
        return quotas
174
172
 
353
351
        """
354
352
        Initializes a Resource.
355
353
 
356
 
        :param name: The name of the resource, i.e., "instances".
 
354
        :param name: The name of the resource, i.e., "volumes".
357
355
        :param flag: The name of the flag or configuration option
358
356
                     which specifies the default value of the quota
359
357
                     for this resource.
424
422
        Initializes a ReservableResource.
425
423
 
426
424
        Reservable resources are those resources which directly
427
 
        correspond to objects in the database, i.e., instances, cores,
 
425
        correspond to objects in the database, i.e., volumes, gigabytes,
428
426
        etc.  A ReservableResource must be constructed with a usage
429
427
        synchronization function, which will be called to determine the
430
428
        current counts of one or more resources.
439
437
        synchronization functions may be associated with more than one
440
438
        ReservableResource.
441
439
 
442
 
        :param name: The name of the resource, i.e., "instances".
 
440
        :param name: The name of the resource, i.e., "volumes".
443
441
        :param sync: A callable which returns a dictionary to
444
442
                     resynchronize the in_use count for one or more
445
443
                     resources, as described above.
469
467
        Initializes a CountableResource.
470
468
 
471
469
        Countable resources are those resources which directly
472
 
        correspond to objects in the database, i.e., instances, cores,
 
470
        correspond to objects in the database, i.e., volumes, gigabytes,
473
471
        etc., but for which a count by project ID is inappropriate.  A
474
472
        CountableResource must be constructed with a counting
475
473
        function, which will be called to determine the current counts
485
483
        required functionality, until a better approach to solving
486
484
        this problem can be evolved.
487
485
 
488
 
        :param name: The name of the resource, i.e., "instances".
 
486
        :param name: The name of the resource, i.e., "volumes".
489
487
        :param count: A callable which returns the count of the
490
488
                      resource.  The arguments passed are as described
491
489
                      above.
577
575
        """
578
576
 
579
577
        return self._driver.get_project_quotas(context, self._resources,
580
 
                                              project_id,
581
 
                                              quota_class=quota_class,
582
 
                                              defaults=defaults,
583
 
                                              usages=usages)
 
578
                                               project_id,
 
579
                                               quota_class=quota_class,
 
580
                                               defaults=defaults,
 
581
                                               usages=usages)
584
582
 
585
583
    def count(self, context, resource, *args, **kwargs):
586
584
        """Count a resource.
727
725
        return sorted(self._resources.keys())
728
726
 
729
727
 
730
 
def _sync_instances(context, project_id, session):
731
 
    return dict(zip(('instances', 'cores', 'ram'),
732
 
                    db.instance_data_get_for_project(
733
 
                context, project_id, session=session)))
734
 
 
735
 
 
736
728
def _sync_volumes(context, project_id, session):
737
729
    return dict(zip(('volumes', 'gigabytes'),
738
 
                    db.volume_data_get_for_project(
739
 
                context, project_id, session=session)))
 
730
                db.volume_data_get_for_project(context,
 
731
                                               project_id,
 
732
                                               session=session)))
740
733
 
741
734
 
742
735
QUOTAS = QuotaEngine()
744
737
 
745
738
resources = [
746
739
    ReservableResource('volumes', _sync_volumes, 'quota_volumes'),
747
 
    ReservableResource('gigabytes', _sync_volumes, 'quota_gigabytes'),
748
 
    ]
 
740
    ReservableResource('gigabytes', _sync_volumes, 'quota_gigabytes'), ]
749
741
 
750
742
 
751
743
QUOTAS.register_resources(resources)