Implements quotas with overrides for instances, volumes, and floating ips.

This commit is contained in:
Vishvananda Ishaya
2010-09-21 13:48:25 +00:00
committed by Tarmac
2 changed files with 27 additions and 11 deletions

View File

@@ -50,7 +50,6 @@
""" """
CLI interface for nova management. CLI interface for nova management.
Connects to the running ADMIN api in the api daemon.
""" """
import os import os
@@ -68,7 +67,9 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
sys.path.insert(0, possible_topdir) sys.path.insert(0, possible_topdir)
from nova import db from nova import db
from nova import exception
from nova import flags from nova import flags
from nova import quota
from nova import utils from nova import utils
from nova.auth import manager from nova.auth import manager
from nova.cloudpipe import pipelib from nova.cloudpipe import pipelib
@@ -186,6 +187,13 @@ class RoleCommands(object):
class UserCommands(object): class UserCommands(object):
"""Class for managing users.""" """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): def __init__(self):
self.manager = manager.AuthManager() self.manager = manager.AuthManager()
@@ -193,13 +201,13 @@ class UserCommands(object):
"""creates a new admin and prints exports """creates a new admin and prints exports
arguments: name [access] [secret]""" arguments: name [access] [secret]"""
user = self.manager.create_user(name, access, secret, True) user = self.manager.create_user(name, access, secret, True)
print_export(user) self._print_export(user)
def create(self, name, access=None, secret=None): def create(self, name, access=None, secret=None):
"""creates a new user and prints exports """creates a new user and prints exports
arguments: name [access] [secret]""" arguments: name [access] [secret]"""
user = self.manager.create_user(name, access, secret, False) user = self.manager.create_user(name, access, secret, False)
print_export(user) self._print_export(user)
def delete(self, name): def delete(self, name):
"""deletes an existing user """deletes an existing user
@@ -211,7 +219,7 @@ class UserCommands(object):
arguments: name""" arguments: name"""
user = self.manager.get_user(name) user = self.manager.get_user(name)
if user: if user:
print_export(user) self._print_export(user)
else: else:
print "User %s doesn't exist" % name print "User %s doesn't exist" % name
@@ -222,12 +230,6 @@ class UserCommands(object):
print user.name 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 ProjectCommands(object):
"""Class for managing projects.""" """Class for managing projects."""
@@ -262,6 +264,19 @@ class ProjectCommands(object):
for project in self.manager.get_projects(): for project in self.manager.get_projects():
print project.name 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): def remove(self, project, user):
"""Removes user from project """Removes user from project
arguments: project user""" arguments: project user"""
@@ -274,6 +289,7 @@ class ProjectCommands(object):
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(zip_file) f.write(zip_file)
class FloatingIpCommands(object): class FloatingIpCommands(object):
"""Class for managing floating ip.""" """Class for managing floating ip."""
@@ -306,6 +322,7 @@ class FloatingIpCommands(object):
floating_ip['address'], floating_ip['address'],
instance) instance)
CATEGORIES = [ CATEGORIES = [
('user', UserCommands), ('user', UserCommands),
('project', ProjectCommands), ('project', ProjectCommands),

View File

@@ -315,7 +315,6 @@ class CloudController(object):
@rbac.allow('projectmanager', 'sysadmin') @rbac.allow('projectmanager', 'sysadmin')
def create_volume(self, context, size, **kwargs): def create_volume(self, context, size, **kwargs):
# check quota # check quota
size = int(size)
if quota.allowed_volumes(context, 1, size) < 1: if quota.allowed_volumes(context, 1, size) < 1:
logging.warn("Quota exceeeded for %s, tried to create %sG volume", logging.warn("Quota exceeeded for %s, tried to create %sG volume",
context.project.id, size) context.project.id, size)