summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2010-12-16 22:52:08 +0000
committerVishvananda Ishaya <vishvananda@gmail.com>2010-12-16 22:52:08 +0000
commit26ebccc8d92aba23efa1663fe9949c141a4cc671 (patch)
treeb5c5724d1f806051ffd30b9a8596c52f6a890351 /nova/db
parentdc29400d104d34c6383132a43e018f7724e85ec3 (diff)
parentcd460a1f661eea7e050891f50a8218fdf24f2c6f (diff)
downloadnova-26ebccc8d92aba23efa1663fe9949c141a4cc671.tar.gz
nova-26ebccc8d92aba23efa1663fe9949c141a4cc671.tar.xz
nova-26ebccc8d92aba23efa1663fe9949c141a4cc671.zip
merged trunk, fixed conflicts and tests
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/base.py36
-rw-r--r--nova/db/sqlalchemy/api.py9
-rw-r--r--nova/db/sqlalchemy/models.py3
3 files changed, 45 insertions, 3 deletions
diff --git a/nova/db/base.py b/nova/db/base.py
new file mode 100644
index 000000000..1d1e80866
--- /dev/null
+++ b/nova/db/base.py
@@ -0,0 +1,36 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""
+Base class for classes that need modular database access.
+"""
+
+from nova import utils
+from nova import flags
+
+FLAGS = flags.FLAGS
+flags.DEFINE_string('db_driver', 'nova.db.api',
+ 'driver to use for database access')
+
+
+class Base(object):
+ """DB driver is injected in the init method"""
+ def __init__(self, db_driver=None):
+ if not db_driver:
+ db_driver = FLAGS.db_driver
+ self.db = utils.import_object(db_driver) # pylint: disable-msg=C0103
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 0a98acf7a..6ecd824e1 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -608,6 +608,12 @@ def fixed_ip_update(context, address, values):
#functions between the two of them as well.
@require_context
def instance_create(context, values):
+ """Create a new Instance record in the database.
+
+ context - request context object
+ values - dict containing column values.
+ 'internal_id' is auto-generated and should not be specified.
+ """
instance_ref = models.Instance()
instance_ref.update(values)
@@ -615,7 +621,7 @@ def instance_create(context, values):
with session.begin():
while instance_ref.internal_id == None:
# Instances have integer internal ids.
- internal_id = random.randint(0, 2 ** 32 - 1)
+ internal_id = random.randint(0, 2 ** 31 - 1)
if not instance_internal_id_exists(context, internal_id,
session=session):
instance_ref.internal_id = internal_id
@@ -816,6 +822,7 @@ def instance_update(context, instance_id, values):
instance_ref = instance_get(context, instance_id, session=session)
instance_ref.update(values)
instance_ref.save(session=session)
+ return instance_ref
def instance_add_security_group(context, instance_id, security_group_id):
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index f8fc7c6c1..d754db90d 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -188,8 +188,6 @@ class Instance(BASE, NovaBase):
kernel_id = Column(String(255))
ramdisk_id = Column(String(255))
- server_name = Column(String(255))
-
# image_id = Column(Integer, ForeignKey('images.id'), nullable=True)
# kernel_id = Column(Integer, ForeignKey('images.id'), nullable=True)
# ramdisk_id = Column(Integer, ForeignKey('images.id'), nullable=True)
@@ -222,6 +220,7 @@ class Instance(BASE, NovaBase):
launched_at = Column(DateTime)
terminated_at = Column(DateTime)
+ # User editable field for display in user-facing UIs
display_name = Column(String(255))
display_description = Column(String(255))