summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@yahoo.com>2010-09-10 18:51:22 -0700
committerVishvananda Ishaya <vishvananda@yahoo.com>2010-09-10 18:51:22 -0700
commitee206cd08bd2d82bb5d64b84b6804ba51ab56b37 (patch)
tree8b04ebcd2ebd2a561debbdc07d3d70326bf66dfc /nova/db
parentfc666c244a8de66ac73add034df3af2544a59790 (diff)
downloadnova-ee206cd08bd2d82bb5d64b84b6804ba51ab56b37.tar.gz
nova-ee206cd08bd2d82bb5d64b84b6804ba51ab56b37.tar.xz
nova-ee206cd08bd2d82bb5d64b84b6804ba51ab56b37.zip
moved keypairs to db using the same interface
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py23
-rw-r--r--nova/db/sqlalchemy/api.py32
-rw-r--r--nova/db/sqlalchemy/models.py36
3 files changed, 91 insertions, 0 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index d81673fad..1db978c52 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -254,6 +254,29 @@ def instance_update(context, instance_id, values):
return IMPL.instance_update(context, instance_id, values)
+###################
+
+
+def keypair_create(context, values):
+ """Create a keypair from the values dictionary."""
+ return IMPL.keypair_create(context, values)
+
+
+def keypair_destroy(context, user_id, name):
+ """Destroy the keypair or raise if it does not exist."""
+ return IMPL.keypair_destroy(context, user_id, name)
+
+
+def keypair_get(context, user_id, name):
+ """Get a keypair or raise if it does not exist."""
+ return IMPL.keypair_get(context, user_id, name)
+
+
+def keypair_get_all_by_user(context, user_id):
+ """Get all keypairs by user."""
+ return IMPL.keypair_get_all_by_user(context, user_id)
+
+
####################
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 02ebdd222..b3a307043 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -355,6 +355,38 @@ def instance_update(_context, instance_id, values):
###################
+def keypair_create(_context, values):
+ keypair_ref = models.Keypair()
+ for (key, value) in values.iteritems():
+ keypair_ref[key] = value
+ keypair_ref.save()
+ return keypair_ref
+
+
+def keypair_destroy(_context, user_id, name):
+ session = get_session()
+ with session.begin():
+ keypair_ref = models.Keypair.find_by_args(user_id,
+ name,
+ session=session)
+ keypair_ref.delete(session=session)
+
+
+def keypair_get(_context, user_id, name):
+ return models.Keypair.find_by_args(user_id, name)
+
+
+def keypair_get_all_by_user(_context, user_id):
+ session = get_session()
+ return session.query(models.Keypair
+ ).filter_by(user_id=user_id
+ ).filter_by(deleted=False
+ ).all()
+
+
+###################
+
+
def network_count(_context):
return models.Network.count()
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 6818f838c..81c0a77a8 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -284,6 +284,42 @@ class ExportDevice(BASE, NovaBase):
uselist=False))
+class Keypair(BASE, NovaBase):
+ """Represents a keypair"""
+ __tablename__ = 'keypairs'
+ id = Column(Integer, primary_key=True)
+ name = Column(String(255))
+
+ user_id = Column(String(255))
+
+ fingerprint = Column(String(255))
+ public_key = Column(Text)
+
+ @property
+ def str_id(self):
+ return '%s.%s' % (self.user_id, self.name)
+
+ @classmethod
+ def find_by_str(cls, str_id, session=None, deleted=False):
+ user_id, _sep, name = str_id.partition('.')
+ return cls.find_by_str(user_id, name, session, deleted)
+
+ @classmethod
+ def find_by_args(cls, user_id, name, session=None, deleted=False):
+ if not session:
+ session = get_session()
+ try:
+ return session.query(cls
+ ).filter_by(user_id=user_id
+ ).filter_by(name=name
+ ).filter_by(deleted=deleted
+ ).one()
+ except exc.NoResultFound:
+ new_exc = exception.NotFound("No model for user %s, name %s" %
+ (user_id, name))
+ raise new_exc.__class__, new_exc, sys.exc_info()[2]
+
+
class Network(BASE, NovaBase):
"""Represents a network"""
__tablename__ = 'networks'