summaryrefslogtreecommitdiffstats
path: root/nova/adminclient.py
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2010-08-18 22:14:24 +0100
committerJustin Santa Barbara <justin@fathomdb.com>2010-08-18 22:14:24 +0100
commitd8f8d121a00173cb3f5fb5e496cc010dc179cf19 (patch)
tree79ae8953421d065a13309ae5052a0faaee94b485 /nova/adminclient.py
parent993563b6cc9db9f24480678cf8b2d0750aee7a92 (diff)
parent2af3bad97be40c135fb73f2e595e7fda86f17900 (diff)
downloadnova-d8f8d121a00173cb3f5fb5e496cc010dc179cf19.tar.gz
nova-d8f8d121a00173cb3f5fb5e496cc010dc179cf19.tar.xz
nova-d8f8d121a00173cb3f5fb5e496cc010dc179cf19.zip
Merged with trunk
Diffstat (limited to 'nova/adminclient.py')
-rw-r--r--nova/adminclient.py48
1 files changed, 47 insertions, 1 deletions
diff --git a/nova/adminclient.py b/nova/adminclient.py
index 25d5e71cb..0ca32b1e5 100644
--- a/nova/adminclient.py
+++ b/nova/adminclient.py
@@ -20,6 +20,7 @@ Nova User API client library.
"""
import base64
+
import boto
from boto.ec2.regioninfo import RegionInfo
@@ -57,6 +58,30 @@ class UserInfo(object):
elif name == 'secretkey':
self.secretkey = str(value)
+
+class UserRole(object):
+ """
+ Information about a Nova user's role, as parsed through SAX.
+ Fields include:
+ role
+ """
+ def __init__(self, connection=None):
+ self.connection = connection
+ self.role = None
+
+ def __repr__(self):
+ return 'UserRole:%s' % self.role
+
+ def startElement(self, name, attrs, connection):
+ return None
+
+ def endElement(self, name, value, connection):
+ if name == 'role':
+ self.role = value
+ else:
+ setattr(self, name, str(value))
+
+
class ProjectInfo(object):
"""
Information about a Nova project, as parsed through SAX
@@ -92,12 +117,14 @@ class ProjectInfo(object):
else:
setattr(self, name, str(value))
+
class ProjectMember(object):
"""
Information about a Nova project member, as parsed through SAX.
Fields include:
memberId
"""
+
def __init__(self, connection=None):
self.connection = connection
self.memberId = None
@@ -113,8 +140,8 @@ class ProjectMember(object):
self.memberId = value
else:
setattr(self, name, str(value))
-
+
class HostInfo(object):
"""
Information about a Nova Host, as parsed through SAX:
@@ -142,6 +169,7 @@ class HostInfo(object):
def endElement(self, name, value, connection):
setattr(self, name, value)
+
class NovaAdminClient(object):
def __init__(self, clc_ip='127.0.0.1', region='nova', access_key='admin',
secret_key='admin', **kwargs):
@@ -196,6 +224,24 @@ class NovaAdminClient(object):
""" deletes a user """
return self.apiconn.get_object('DeregisterUser', {'Name': username}, UserInfo)
+ def get_roles(self, project_roles=True):
+ """Returns a list of available roles."""
+ return self.apiconn.get_list('DescribeRoles',
+ {'ProjectRoles': project_roles},
+ [('item', UserRole)])
+
+ def get_user_roles(self, user, project=None):
+ """Returns a list of roles for the given user.
+ Omitting project will return any global roles that the user has.
+ Specifying project will return only project specific roles.
+ """
+ params = {'User':user}
+ if project:
+ params['Project'] = project
+ return self.apiconn.get_list('DescribeUserRoles',
+ params,
+ [('item', UserRole)])
+
def add_user_role(self, user, role, project=None):
"""
Add a role to a user either globally or for a specific project.