summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Gundlach <michael.gundlach@rackspace.com>2010-12-01 22:14:29 +0000
committerTarmac <>2010-12-01 22:14:29 +0000
commitf8afbcc08b65d4d6764a6dc66c804816573ab3b4 (patch)
tree8dd8b1cb664626932d56e044303535773f0d84bc
parent225fd37fb234740c814410b3e4d3149212cf54c5 (diff)
parent8af2b1c97903f11034a95894a23bb7e77f573aa6 (diff)
Guarantee that the OpenStack API's Server-related responses will always contain a "name" value. And get rid of a redundant field in models.py.
-rw-r--r--nova/api/openstack/servers.py5
-rw-r--r--nova/compute/manager.py6
-rw-r--r--nova/db/sqlalchemy/api.py6
-rw-r--r--nova/db/sqlalchemy/models.py3
-rw-r--r--nova/tests/api/openstack/test_servers.py2
5 files changed, 16 insertions, 6 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 1d8aa2fa4..44e69b82c 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -63,7 +63,7 @@ def _entity_detail(inst):
inst_dict = {}
mapped_keys = dict(status='state', imageId='image_id',
- flavorId='instance_type', name='server_name', id='id')
+ flavorId='instance_type', name='display_name', id='id')
for k, v in mapped_keys.iteritems():
inst_dict[k] = inst[v]
@@ -78,7 +78,7 @@ def _entity_detail(inst):
def _entity_inst(inst):
""" Filters all model attributes save for id and name """
- return dict(server=dict(id=inst['id'], name=inst['server_name']))
+ return dict(server=dict(id=inst['id'], name=inst['display_name']))
class Controller(wsgi.Controller):
@@ -213,7 +213,6 @@ class Controller(wsgi.Controller):
if not image:
raise Exception("Image not found")
- inst['server_name'] = env['server']['name']
inst['image_id'] = image_id
inst['user_id'] = user_id
inst['launch_time'] = ltime
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 50a9d316b..e826bdaa2 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -101,6 +101,12 @@ class ComputeManager(manager.Manager):
"""
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)
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 01b5cf350..fe0a9a921 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -178,8 +178,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)
@@ -212,6 +210,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))
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 8cfc6c45a..530d06760 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -44,7 +44,7 @@ def return_servers(context, user_id=1):
def stub_instance(id, user_id=1):
- return Instance(id=id, state=0, image_id=10, server_name='server%s' % id,
+ return Instance(id=id, state=0, image_id=10, display_name='server%s' % id,
user_id=user_id)