~soren/nova/lp658257

« back to all changes in this revision

Viewing changes to nova/api/openstack/servers.py

  • Committer: Tarmac
  • Author(s): mdietz
  • Date: 2010-10-08 21:18:37 UTC
  • mfrom: (332.2.4 rs_api_rename)
  • Revision ID: hudson@openstack.org-20101008211837-j9khriwzr28bdd2k
Renames every instance of "rackspace" in the API and test code base. Also includes a minor patch for the API Servers controller to use images correctly in the absence of Glance. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from nova import utils
26
26
from nova import wsgi
27
27
from nova.api import cloud
28
 
from nova.api.rackspace import _id_translator
29
 
from nova.api.rackspace import context
30
 
from nova.api.rackspace import faults
 
28
from nova.api.openstack import context
 
29
from nova.api.openstack import faults
31
30
from nova.compute import instance_types
32
31
from nova.compute import power_state
33
 
import nova.api.rackspace
 
32
import nova.api.openstack
34
33
import nova.image.service
35
34
 
36
35
FLAGS = flags.FLAGS
37
36
 
38
 
def _instance_id_translator():
39
 
    """ Helper method for initializing an id translator for Rackspace instance
40
 
    ids """
41
 
    return _id_translator.RackspaceAPIIdTranslator( "instance", 'nova')
42
 
 
43
 
def _image_service():
44
 
    """ Helper method for initializing the image id translator """
45
 
    service = utils.import_object(FLAGS.image_service)
46
 
    return (service, _id_translator.RackspaceAPIIdTranslator(
47
 
            "image", service.__class__.__name__))
48
 
 
49
37
def _filter_params(inst_dict):
50
38
    """ Extracts all updatable parameters for a server update request """
51
39
    keys = dict(name='name', admin_pass='adminPass')
60
48
    return dict(servers=entities)
61
49
 
62
50
def _entity_detail(inst):
63
 
    """ Maps everything to Rackspace-like attributes for return"""
 
51
    """ Maps everything to valid attributes for return"""
64
52
    power_mapping = { 
65
53
        power_state.NOSTATE:  'build', 
66
54
        power_state.RUNNING:  'active',
90
78
    return dict(server=dict(id=inst['id'], name=inst['server_name']))
91
79
 
92
80
class Controller(wsgi.Controller):
93
 
    """ The Server API controller for the Openstack API """
 
81
    """ The Server API controller for the OpenStack API """
94
82
 
95
83
    _serialization_metadata = {
96
84
        'application/xml': {
122
110
        """
123
111
        user_id = req.environ['nova.context']['user']['id']
124
112
        instance_list = self.db_driver.instance_get_all_by_user(None, user_id)
125
 
        limited_list = nova.api.rackspace.limited(instance_list, req)
 
113
        limited_list = nova.api.openstack.limited(instance_list, req)
126
114
        res = [entity_maker(inst)['server'] for inst in limited_list]
127
115
        return _entity_list(res)
128
116
 
182
170
    def action(self, req, id):
183
171
        """ multi-purpose method used to reboot, rebuild, and 
184
172
        resize a server """
 
173
        user_id = req.environ['nova.context']['user']['id']
185
174
        input_dict = self._deserialize(req.body, req)
186
175
        try:
187
176
            reboot_type = input_dict['reboot']['type']
188
177
        except Exception:
189
178
            raise faults.Fault(webob.exc.HTTPNotImplemented())
190
 
        opaque_id = _instance_id_translator().from_rs_id(int(id))
191
 
        cloud.reboot(opaque_id)
 
179
        inst_ref = self.db.instance_get_by_internal_id(None, int(id))
 
180
        if not inst_ref or (inst_ref and not inst_ref.user_id == user_id):
 
181
            return faults.Fault(exc.HTTPUnprocessableEntity())
 
182
        cloud.reboot(id)
192
183
 
193
184
    def _build_server_instance(self, req, env):
194
185
        """Build instance data structure and save it to the data store."""
205
196
 
206
197
        image_id = env['server']['imageId']
207
198
        
208
 
        img_service, image_id_trans = _image_service()
 
199
        img_service = utils.import_object(FLAGS.image_service)
209
200
 
210
 
        opaque_image_id = image_id_trans.to_rs_id(image_id)        
211
 
        image = img_service.show(opaque_image_id)
 
201
        image = img_service.show(image_id)
212
202
 
213
203
        if not image: 
214
204
            raise Exception, "Image not found"
215
205
 
216
206
        inst['server_name'] = env['server']['name']
217
 
        inst['image_id'] = opaque_image_id
 
207
        inst['image_id'] = image_id
218
208
        inst['user_id'] = user_id
219
209
        inst['launch_time'] = ltime
220
210
        inst['mac_address'] = utils.generate_mac()