from PLC.Debug import profile
from PLC.Table import Row, Table
from PLC.KeyTypes import KeyType, KeyTypes
+from PLC.NovaTable import NovaObject, NovaTable
-class Key(Row):
+class Key(NovaObject):
"""
Representation of a row in the keys table. To use, instantiate with a
dict of values. Update as you would a dict. Commit to the database
primary_key = 'key_id'
join_tables = ['person_key', 'peer_key']
fields = {
- 'key_id': Parameter(int, "Key identifier"),
+ 'key_id': Parameter(str, "Key identifier"),
'key_type': Parameter(str, "Key type"),
'key': Parameter(str, "Key value", max = 4096),
'person_id': Parameter(int, "User to which this key belongs", nullok = True),
if commit:
self.api.db.commit()
-class Keys(Table):
+class Keys(NovaTable):
"""
Representation of row(s) from the keys table in the
database.
"""
def __init__(self, api, key_filter = None, columns = None):
- Table.__init__(self, api, Key, columns)
-
- sql = "SELECT %s FROM view_keys WHERE is_blacklisted IS False" % \
- ", ".join(self.columns)
+ self.api = api
+ keysManager = self.api.client_shell.nova.keypairs
+ keyPairs = []
if key_filter is not None:
if isinstance(key_filter, (list, tuple, set, int, long)):
- key_filter = Filter(Key.fields, {'key_id': key_filter})
+ keyPairs = filter(lambda kp: kp.uuid in key_filter,
+ keysManager.findall())
elif isinstance(key_filter, dict):
- key_filter = Filter(Key.fields, key_filter)
+ keyPairs = keysManager.findall(**key_filter)
+ elif isinstnace(key_filter, StringTypes):
+ keyPairs = keyManagers.findall(uuid = key_filter)
else:
raise PLCInvalidArgument, "Wrong key filter %r"%key_filter
- sql += " AND (%s) %s" % key_filter.sql(api)
- self.selectall(sql)
+ self.extend(keyPairs)
+
keys = Keys(self.api, key_filter, return_fields)
# If we are not admin, make sure to only return our own keys
- if isinstance(self.caller, Person) and \
- 'admin' not in self.caller['roles']:
- keys = filter(lambda key: key['key_id'] in self.caller['key_ids'], keys)
+ #if isinstance(self.caller, Person) and \
+ # 'admin' not in self.caller['roles']:
+ # keys = filter(lambda key: key['key_id'] in self.caller['key_ids'], keys)
return keys