summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2011-07-18 16:58:23 -0700
committerVishvananda Ishaya <vishvananda@gmail.com>2011-07-18 16:58:23 -0700
commitb5ceab5a46ffac11cb229de86c49802bba3fa383 (patch)
tree62459fbead53019efe4efc3e762fe1e07e84a450 /nova/db
parent67e5492d6723a00b0ad5d7e8c44f5762a9b0a206 (diff)
parent77db06c908f9c08c80beb11241c0e23247129ad6 (diff)
downloadnova-b5ceab5a46ffac11cb229de86c49802bba3fa383.tar.gz
nova-b5ceab5a46ffac11cb229de86c49802bba3fa383.tar.xz
nova-b5ceab5a46ffac11cb229de86c49802bba3fa383.zip
merged trunk
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py8
-rw-r--r--nova/db/sqlalchemy/api.py41
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/032_add_root_device_name.py47
-rw-r--r--nova/db/sqlalchemy/models.py2
4 files changed, 89 insertions, 9 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index c9d5bc72b..2efbf957d 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -995,10 +995,16 @@ def block_device_mapping_create(context, values):
def block_device_mapping_update(context, bdm_id, values):
- """Create an entry of block device mapping"""
+ """Update an entry of block device mapping"""
return IMPL.block_device_mapping_update(context, bdm_id, values)
+def block_device_mapping_update_or_create(context, values):
+ """Update an entry of block device mapping.
+ If not existed, create a new entry"""
+ return IMPL.block_device_mapping_update_or_create(context, values)
+
+
def block_device_mapping_get_all_by_instance(context, instance_id):
"""Get all block device mapping belonging to a instance"""
return IMPL.block_device_mapping_get_all_by_instance(context, instance_id)
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index a90b61e39..33bdd767a 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -116,8 +116,23 @@ def require_context(f):
return wrapper
+def require_instance_exists(f):
+ """Decorator to require the specified instance to exist.
+
+ Requres the wrapped function to use context and instance_id as
+ their first two arguments.
+ """
+
+ def wrapper(context, instance_id, *args, **kwargs):
+ db.api.instance_get(context, instance_id)
+ return f(context, instance_id, *args, **kwargs)
+ wrapper.__name__ = f.__name__
+ return wrapper
+
+
###################
+
@require_admin_context
def service_destroy(context, service_id):
session = get_session()
@@ -937,6 +952,7 @@ def virtual_interface_get_by_fixed_ip(context, fixed_ip_id):
@require_context
+@require_instance_exists
def virtual_interface_get_by_instance(context, instance_id):
"""Gets all virtual interfaces for instance.
@@ -2229,6 +2245,23 @@ def block_device_mapping_update(context, bdm_id, values):
@require_context
+def block_device_mapping_update_or_create(context, values):
+ session = get_session()
+ with session.begin():
+ result = session.query(models.BlockDeviceMapping).\
+ filter_by(instance_id=values['instance_id']).\
+ filter_by(device_name=values['device_name']).\
+ filter_by(deleted=False).\
+ first()
+ if not result:
+ bdm_ref = models.BlockDeviceMapping()
+ bdm_ref.update(values)
+ bdm_ref.save(session=session)
+ else:
+ result.update(values)
+
+
+@require_context
def block_device_mapping_get_all_by_instance(context, instance_id):
session = get_session()
result = session.query(models.BlockDeviceMapping).\
@@ -3092,14 +3125,6 @@ def zone_get_all(context):
####################
-def require_instance_exists(func):
- def new_func(context, instance_id, *args, **kwargs):
- db.api.instance_get(context, instance_id)
- return func(context, instance_id, *args, **kwargs)
- new_func.__name__ = func.__name__
- return new_func
-
-
@require_context
@require_instance_exists
def instance_metadata_get(context, instance_id):
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/032_add_root_device_name.py b/nova/db/sqlalchemy/migrate_repo/versions/032_add_root_device_name.py
new file mode 100644
index 000000000..6b98b9890
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/032_add_root_device_name.py
@@ -0,0 +1,47 @@
+# Copyright 2011 OpenStack LLC.
+# Copyright 2011 Isaku Yamahata
+#
+# 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.
+
+from sqlalchemy import Column, Integer, MetaData, Table, String
+
+meta = MetaData()
+
+
+# Just for the ForeignKey and column creation to succeed, these are not the
+# actual definitions of instances or services.
+instances = Table('instances', meta,
+ Column('id', Integer(), primary_key=True, nullable=False),
+ )
+
+#
+# New Column
+#
+root_device_name = Column(
+ 'root_device_name',
+ String(length=255, convert_unicode=False, assert_unicode=None,
+ unicode_error=None, _warn_on_bytestring=False),
+ nullable=True)
+
+
+def upgrade(migrate_engine):
+ # Upgrade operations go here. Don't create your own engine;
+ # bind migrate_engine to your metadata
+ meta.bind = migrate_engine
+ instances.create_column(root_device_name)
+
+
+def downgrade(migrate_engine):
+ # Operations to reverse the above upgrade go here.
+ meta.bind = migrate_engine
+ instances.drop_column('root_device_name')
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 639941dc8..e42f605c4 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -236,6 +236,8 @@ class Instance(BASE, NovaBase):
vm_mode = Column(String(255))
uuid = Column(String(36))
+ root_device_name = Column(String(255))
+
# TODO(vish): see Ewan's email about state improvements, probably
# should be in a driver base class or some such
# vmstate_state = running, halted, suspended, paused