summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorBrian Waldon <brian.waldon@rackspace.com>2011-03-30 15:10:37 +0000
committerTarmac <>2011-03-30 15:10:37 +0000
commitc88f1f58f65c80cec8a19cd6e7d821357e86d0e6 (patch)
tree9f11d1b452128190d2ea1a985678976cf5eb7b41 /nova/api
parenteaeaea0b5fb063124c04e05a30f9160890e8c4f9 (diff)
parenta070b8861ccc01b485b109855f44a36cd6ebdbd6 (diff)
Moving server update adminPass support to be v1.0-specific
OS API servers update tests actually assert and pass now Enforcing server name being a string of length > 0
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/servers.py48
1 files changed, 39 insertions, 9 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 6bd173bb8..f7696d918 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -150,6 +150,15 @@ class Controller(wsgi.Controller):
injected_files = self._get_injected_files(personality)
flavor_id = self._flavor_id_from_req_data(env)
+
+ if not 'name' in env['server']:
+ msg = _("Server name is not defined")
+ return exc.HTTPBadRequest(msg)
+
+ name = env['server']['name']
+ self._validate_server_name(name)
+ name = name.strip()
+
try:
(inst,) = self.compute_api.create(
context,
@@ -157,8 +166,8 @@ class Controller(wsgi.Controller):
image_id,
kernel_id=kernel_id,
ramdisk_id=ramdisk_id,
- display_name=env['server']['name'],
- display_description=env['server']['name'],
+ display_name=name,
+ display_description=name,
key_name=key_name,
key_data=key_data,
metadata=metadata,
@@ -246,20 +255,33 @@ class Controller(wsgi.Controller):
ctxt = req.environ['nova.context']
update_dict = {}
- if 'adminPass' in inst_dict['server']:
- update_dict['admin_pass'] = inst_dict['server']['adminPass']
- try:
- self.compute_api.set_admin_password(ctxt, id)
- except exception.TimeoutException:
- return exc.HTTPRequestTimeout()
+
if 'name' in inst_dict['server']:
- update_dict['display_name'] = inst_dict['server']['name']
+ name = inst_dict['server']['name']
+ self._validate_server_name(name)
+ update_dict['display_name'] = name.strip()
+
+ self._parse_update(ctxt, id, inst_dict, update_dict)
+
try:
self.compute_api.update(ctxt, id, **update_dict)
except exception.NotFound:
return faults.Fault(exc.HTTPNotFound())
+
return exc.HTTPNoContent()
+ def _validate_server_name(self, value):
+ if not isinstance(value, basestring):
+ msg = _("Server name is not a string or unicode")
+ raise exc.HTTPBadRequest(msg)
+
+ if value.strip() == '':
+ msg = _("Server name is an empty string")
+ raise exc.HTTPBadRequest(msg)
+
+ def _parse_update(self, context, id, inst_dict, update_dict):
+ pass
+
@scheduler_api.redirect_handler
def action(self, req, id):
"""Multi-purpose method used to reboot, rebuild, or
@@ -576,6 +598,14 @@ class ControllerV10(Controller):
def _limit_items(self, items, req):
return common.limited(items, req)
+ def _parse_update(self, context, server_id, inst_dict, update_dict):
+ if 'adminPass' in inst_dict['server']:
+ update_dict['admin_pass'] = inst_dict['server']['adminPass']
+ try:
+ self.compute_api.set_admin_password(context, server_id)
+ except exception.TimeoutException:
+ return exc.HTTPRequestTimeout()
+
class ControllerV11(Controller):
def _image_id_from_req_data(self, data):