summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@yahoo.com>2010-09-21 13:48:25 +0000
committerTarmac <>2010-09-21 13:48:25 +0000
commitce0a9b7b36ba816c347f10a1804aedf337ad35da (patch)
treec9d789f62e15eb59414ece49572da64dd8a0a99d
parent4e727faf450154d89687b1a33dae2159d5b691a0 (diff)
parent435a78e48ca63297af9c15ee826dbe0c6b8e7813 (diff)
downloadnova-ce0a9b7b36ba816c347f10a1804aedf337ad35da.tar.gz
nova-ce0a9b7b36ba816c347f10a1804aedf337ad35da.tar.xz
nova-ce0a9b7b36ba816c347f10a1804aedf337ad35da.zip
Implements quotas with overrides for instances, volumes, and floating ips.
-rwxr-xr-xbin/nova-manage37
-rw-r--r--nova/endpoint/cloud.py1
-rw-r--r--nova/quota.py9
3 files changed, 32 insertions, 15 deletions
diff --git a/bin/nova-manage b/bin/nova-manage
index 325245ac4..824e00ac5 100755
--- a/bin/nova-manage
+++ b/bin/nova-manage
@@ -50,7 +50,6 @@
"""
CLI interface for nova management.
- Connects to the running ADMIN api in the api daemon.
"""
import os
@@ -68,7 +67,9 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
sys.path.insert(0, possible_topdir)
from nova import db
+from nova import exception
from nova import flags
+from nova import quota
from nova import utils
from nova.auth import manager
from nova.cloudpipe import pipelib
@@ -186,6 +187,13 @@ class RoleCommands(object):
class UserCommands(object):
"""Class for managing users."""
+ @staticmethod
+ def _print_export(user):
+ """Print export variables to use with API."""
+ print 'export EC2_ACCESS_KEY=%s' % user.access
+ print 'export EC2_SECRET_KEY=%s' % user.secret
+
+
def __init__(self):
self.manager = manager.AuthManager()
@@ -193,13 +201,13 @@ class UserCommands(object):
"""creates a new admin and prints exports
arguments: name [access] [secret]"""
user = self.manager.create_user(name, access, secret, True)
- print_export(user)
+ self._print_export(user)
def create(self, name, access=None, secret=None):
"""creates a new user and prints exports
arguments: name [access] [secret]"""
user = self.manager.create_user(name, access, secret, False)
- print_export(user)
+ self._print_export(user)
def delete(self, name):
"""deletes an existing user
@@ -211,7 +219,7 @@ class UserCommands(object):
arguments: name"""
user = self.manager.get_user(name)
if user:
- print_export(user)
+ self._print_export(user)
else:
print "User %s doesn't exist" % name
@@ -222,12 +230,6 @@ class UserCommands(object):
print user.name
-def print_export(user):
- """Print export variables to use with API."""
- print 'export EC2_ACCESS_KEY=%s' % user.access
- print 'export EC2_SECRET_KEY=%s' % user.secret
-
-
class ProjectCommands(object):
"""Class for managing projects."""
@@ -262,6 +264,19 @@ class ProjectCommands(object):
for project in self.manager.get_projects():
print project.name
+ def quota(self, project_id, key=None, value=None):
+ """Set or display quotas for project
+ arguments: project_id [key] [value]"""
+ if key:
+ quo = {'project_id': project_id, key: value}
+ try:
+ db.quota_update(None, project_id, quo)
+ except exception.NotFound:
+ db.quota_create(None, quo)
+ project_quota = quota.get_quota(None, project_id)
+ for key, value in project_quota.iteritems():
+ print '%s: %s' % (key, value)
+
def remove(self, project, user):
"""Removes user from project
arguments: project user"""
@@ -274,6 +289,7 @@ class ProjectCommands(object):
with open(filename, 'w') as f:
f.write(zip_file)
+
class FloatingIpCommands(object):
"""Class for managing floating ip."""
@@ -306,6 +322,7 @@ class FloatingIpCommands(object):
floating_ip['address'],
instance)
+
CATEGORIES = [
('user', UserCommands),
('project', ProjectCommands),
diff --git a/nova/endpoint/cloud.py b/nova/endpoint/cloud.py
index 28aee37d2..261e3e001 100644
--- a/nova/endpoint/cloud.py
+++ b/nova/endpoint/cloud.py
@@ -315,7 +315,6 @@ class CloudController(object):
@rbac.allow('projectmanager', 'sysadmin')
def create_volume(self, context, size, **kwargs):
# check quota
- size = int(size)
if quota.allowed_volumes(context, 1, size) < 1:
logging.warn("Quota exceeeded for %s, tried to create %sG volume",
context.project.id, size)
diff --git a/nova/quota.py b/nova/quota.py
index f0e51feeb..edbb83111 100644
--- a/nova/quota.py
+++ b/nova/quota.py
@@ -37,7 +37,7 @@ flags.DEFINE_integer('quota_gigabytes', 1000,
flags.DEFINE_integer('quota_floating_ips', 10,
'number of floating ips allowed per project')
-def _get_quota(context, project_id):
+def get_quota(context, project_id):
rval = {'instances': FLAGS.quota_instances,
'cores': FLAGS.quota_cores,
'volumes': FLAGS.quota_volumes,
@@ -57,7 +57,7 @@ def allowed_instances(context, num_instances, instance_type):
project_id = context.project.id
used_instances, used_cores = db.instance_data_get_for_project(context,
project_id)
- quota = _get_quota(context, project_id)
+ quota = get_quota(context, project_id)
allowed_instances = quota['instances'] - used_instances
allowed_cores = quota['cores'] - used_cores
type_cores = instance_types.INSTANCE_TYPES[instance_type]['vcpus']
@@ -72,9 +72,10 @@ def allowed_volumes(context, num_volumes, size):
project_id = context.project.id
used_volumes, used_gigabytes = db.volume_data_get_for_project(context,
project_id)
- quota = _get_quota(context, project_id)
+ quota = get_quota(context, project_id)
allowed_volumes = quota['volumes'] - used_volumes
allowed_gigabytes = quota['gigabytes'] - used_gigabytes
+ size = int(size)
num_gigabytes = num_volumes * size
allowed_volumes = min(allowed_volumes,
int(allowed_gigabytes // size))
@@ -85,7 +86,7 @@ def allowed_floating_ips(context, num_floating_ips):
"""Check quota and return min(num_floating_ips, allowed_floating_ips)"""
project_id = context.project.id
used_floating_ips = db.floating_ip_count_by_project(context, project_id)
- quota = _get_quota(context, project_id)
+ quota = get_quota(context, project_id)
allowed_floating_ips = quota['floating_ips'] - used_floating_ips
return min(num_floating_ips, allowed_floating_ips)