~rlane/nova/lp773690

« back to all changes in this revision

Viewing changes to nova/quota.py

  • Committer: rlane at wikimedia
  • Date: 2011-04-29 22:30:40 UTC
  • mfrom: (382.1.655 nova)
  • Revision ID: rlane@wikimedia.org-20110429223040-i0x3ds9eqwrabyru
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
16
#    License for the specific language governing permissions and limitations
17
17
#    under the License.
18
 
"""
19
 
Quotas for instances, volumes, and floating ips
20
 
"""
 
18
 
 
19
"""Quotas for instances, volumes, and floating ips."""
21
20
 
22
21
from nova import db
23
22
from nova import exception
24
23
from nova import flags
25
24
 
 
25
 
26
26
FLAGS = flags.FLAGS
27
 
 
28
27
flags.DEFINE_integer('quota_instances', 10,
29
28
                     'number of instances allowed per project')
30
29
flags.DEFINE_integer('quota_cores', 20,
64
63
 
65
64
 
66
65
def allowed_instances(context, num_instances, instance_type):
67
 
    """Check quota and return min(num_instances, allowed_instances)"""
 
66
    """Check quota and return min(num_instances, allowed_instances)."""
68
67
    project_id = context.project_id
69
68
    context = context.elevated()
70
69
    used_instances, used_cores = db.instance_data_get_for_project(context,
79
78
 
80
79
 
81
80
def allowed_volumes(context, num_volumes, size):
82
 
    """Check quota and return min(num_volumes, allowed_volumes)"""
 
81
    """Check quota and return min(num_volumes, allowed_volumes)."""
83
82
    project_id = context.project_id
84
83
    context = context.elevated()
85
84
    used_volumes, used_gigabytes = db.volume_data_get_for_project(context,
95
94
 
96
95
 
97
96
def allowed_floating_ips(context, num_floating_ips):
98
 
    """Check quota and return min(num_floating_ips, allowed_floating_ips)"""
 
97
    """Check quota and return min(num_floating_ips, allowed_floating_ips)."""
99
98
    project_id = context.project_id
100
99
    context = context.elevated()
101
100
    used_floating_ips = db.floating_ip_count_by_project(context, project_id)
105
104
 
106
105
 
107
106
def allowed_metadata_items(context, num_metadata_items):
108
 
    """Check quota; return min(num_metadata_items,allowed_metadata_items)"""
 
107
    """Check quota; return min(num_metadata_items,allowed_metadata_items)."""
109
108
    project_id = context.project_id
110
109
    context = context.elevated()
111
110
    quota = get_quota(context, project_id)
114
113
 
115
114
 
116
115
def allowed_injected_files(context):
117
 
    """Return the number of injected files allowed"""
 
116
    """Return the number of injected files allowed."""
118
117
    return FLAGS.quota_max_injected_files
119
118
 
120
119
 
121
120
def allowed_injected_file_content_bytes(context):
122
 
    """Return the number of bytes allowed per injected file content"""
 
121
    """Return the number of bytes allowed per injected file content."""
123
122
    return FLAGS.quota_max_injected_file_content_bytes
124
123
 
125
124
 
126
125
def allowed_injected_file_path_bytes(context):
127
 
    """Return the number of bytes allowed in an injected file path"""
 
126
    """Return the number of bytes allowed in an injected file path."""
128
127
    return FLAGS.quota_max_injected_file_path_bytes
129
128
 
130
129
 
131
130
class QuotaError(exception.ApiError):
132
 
    """Quota Exceeeded"""
 
131
    """Quota Exceeeded."""
133
132
    pass