diff options
| author | Vishvananda Ishaya <vishvananda@gmail.com> | 2011-08-31 14:58:55 -0700 |
|---|---|---|
| committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2011-08-31 14:58:55 -0700 |
| commit | 9de8a589b4ee0e007267efe2394b504382e4cdc1 (patch) | |
| tree | 705529950bf29bb856ecbf3394eef0179e1e11aa /nova | |
| parent | c9758dd4832c167562baefad5dcc88f2a1a19b73 (diff) | |
| download | nova-9de8a589b4ee0e007267efe2394b504382e4cdc1.tar.gz nova-9de8a589b4ee0e007267efe2394b504382e4cdc1.tar.xz nova-9de8a589b4ee0e007267efe2394b504382e4cdc1.zip | |
change to use _get_key_name to retrieve the key
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/api/openstack/servers.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index f288f2228..53684fa52 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -144,8 +144,15 @@ class Controller(object): except exception.NotFound: raise exc.HTTPNotFound() + def _get_key_name(self, req, body): + """ Get default keypair if not set """ + raise NotImplementedError() + def create(self, req, body): """ Creates a new server for a given user """ + if 'server' in body: + body['server']['key_name'] = self._get_key_name(req, body) + extra_values = None extra_values, instances = self.helper.create_instance( req, body, self.compute_api.create) @@ -564,17 +571,12 @@ class ControllerV10(Controller): raise exc.HTTPNotFound() return webob.Response(status_int=202) - def create(self, req, body): - """ Creates a new server for a given user """ - # note(ja): v1.0 injects the first keypair for the project for testing - if 'server' in body and not 'key_name' in body['server']: - context = req.environ["nova.context"] - keypairs = db.key_pair_get_all_by_user(context.elevated(), - context.user_id) - if keypairs: - body['server']['key_name'] = keypairs[0]['name'] - - return super(ControllerV10, self).create(req, body) + def _get_key_name(self, req, body): + context = req.environ["nova.context"] + keypairs = db.key_pair_get_all_by_user(context, + context.user_id) + if keypairs: + return keypairs[0]['name'] def _image_ref_from_req_data(self, data): return data['server']['imageId'] @@ -647,6 +649,10 @@ class ControllerV11(Controller): except exception.NotFound: raise exc.HTTPNotFound() + def _get_key_name(self, req, body): + if 'server' in body: + return body['server'].get('key_name') + def _image_ref_from_req_data(self, data): try: return data['server']['imageRef'] |
