summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorMichael Gundlach <michael.gundlach@rackspace.com>2010-12-01 15:53:27 -0600
committerMichael Gundlach <michael.gundlach@rackspace.com>2010-12-01 15:53:27 -0600
commitf53f5880c08994d04a552a41ce6f88dfbd867946 (patch)
tree1a6c7bb4a9f187b48909eae576a0f682c739819f /nova
parentfdf0aa30a1127eb8311a599dfdad9653ac699154 (diff)
downloadnova-f53f5880c08994d04a552a41ce6f88dfbd867946.tar.gz
nova-f53f5880c08994d04a552a41ce6f88dfbd867946.tar.xz
nova-f53f5880c08994d04a552a41ce6f88dfbd867946.zip
Oops, internal_id isn't available until after a save. This code saves twice; if I moved it into the DB layer we could do it in one save. However, we're moving to one sqlite db per compute worker, so I'd rather have two saves in order to keep the logic in the right layer.
Diffstat (limited to 'nova')
-rw-r--r--nova/compute/manager.py8
-rw-r--r--nova/db/sqlalchemy/api.py6
2 files changed, 12 insertions, 2 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 0893db9fc..6fc5c5186 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -99,10 +99,14 @@ class ComputeManager(manager.Manager):
that has just been created
"""
- # Set sane defaults if not specified
- kwargs.setdefault('display_name', "Server %s" % kwargs['internal_id'])
instance_ref = self.db.instance_create(context, kwargs)
inst_id = instance_ref['id']
+ # Set sane defaults if not specified
+ if 'display_name' not in kwargs:
+ display_name = "Server %s" % instance_ref['internal_id']
+ instance_ref['display_name'] = display_name
+ self.db.instance_update(context, inst_id,
+ { 'display_name': display_name })
elevated = context.elevated()
if not security_groups:
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index afa55fc03..dd9649054 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -530,6 +530,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)