~rackspace-titan/nova/api-profiling

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Sandy Walsh
  • Date: 2011-06-14 21:11:25 UTC
  • mfrom: (1063.8.27 dist-sched-4)
  • Revision ID: tarmac-20110614211125-sbdntqdts9nn0ha9
Phew ... ok, this is the last dist-scheduler merge before we get into serious testing and minor tweaks. The heavy lifting is largely done.

This branch adds an OS API POST /zone/boot command which returns a reservation ID (unlike POST /servers which returns a single instance_id). 

This branch requires v2.5 of python-novaclient

Additionally GET /servers can now take an optional reservation_id parameter, which will return all the instances with that reservation ID across all zones.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from nova import exception
22
22
from nova import flags
23
23
from nova import log as logging
 
24
 
 
25
from nova.compute import api as compute
 
26
from nova.scheduler import api
 
27
 
 
28
from nova.api.openstack import create_instance_helper as helper
24
29
from nova.api.openstack import common
 
30
from nova.api.openstack import faults
25
31
from nova.api.openstack import wsgi
26
 
from nova.scheduler import api
27
32
 
28
33
 
29
34
FLAGS = flags.FLAGS
59
64
 
60
65
 
61
66
class Controller(object):
 
67
    """Controller for Zone resources."""
 
68
 
 
69
    def __init__(self):
 
70
        self.compute_api = compute.API()
 
71
        self.helper = helper.CreateInstanceHelper(self)
62
72
 
63
73
    def index(self, req):
64
74
        """Return all zones in brief"""
93
103
        return dict(zone=_scrub_zone(zone))
94
104
 
95
105
    def delete(self, req, id):
 
106
        """Delete a child zone entry."""
96
107
        zone_id = int(id)
97
108
        api.zone_delete(req.environ['nova.context'], zone_id)
98
109
        return {}
99
110
 
100
111
    def create(self, req, body):
 
112
        """Create a child zone entry."""
101
113
        context = req.environ['nova.context']
102
114
        zone = api.zone_create(context, body["zone"])
103
115
        return dict(zone=_scrub_zone(zone))
104
116
 
105
117
    def update(self, req, id, body):
 
118
        """Update a child zone entry."""
106
119
        context = req.environ['nova.context']
107
120
        zone_id = int(id)
108
121
        zone = api.zone_update(context, zone_id, body["zone"])
109
122
        return dict(zone=_scrub_zone(zone))
110
123
 
 
124
    def boot(self, req, body):
 
125
        """Creates a new server for a given user while being Zone aware.
 
126
 
 
127
        Returns a reservation ID (a UUID).
 
128
        """
 
129
        result = None
 
130
        try:
 
131
            extra_values, result = self.helper.create_instance(req, body,
 
132
                                    self.compute_api.create_all_at_once)
 
133
        except faults.Fault, f:
 
134
            return f
 
135
 
 
136
        reservation_id = result
 
137
        return {'reservation_id': reservation_id}
 
138
 
111
139
    @check_encryption_key
112
140
    def select(self, req, body):
113
141
        """Returns a weighted list of costs to create instances
131
159
                blob=cipher_text))
132
160
        return cooked
133
161
 
134
 
 
135
 
def create_resource():
 
162
    def _image_ref_from_req_data(self, data):
 
163
        return data['server']['imageId']
 
164
 
 
165
    def _flavor_id_from_req_data(self, data):
 
166
        return data['server']['flavorId']
 
167
 
 
168
    def _get_server_admin_password(self, server):
 
169
        """ Determine the admin password for a server on creation """
 
170
        return self.helper._get_server_admin_password_old_style(server)
 
171
 
 
172
 
 
173
class ControllerV11(object):
 
174
    """Controller for 1.1 Zone resources."""
 
175
 
 
176
    def _get_server_admin_password(self, server):
 
177
        """ Determine the admin password for a server on creation """
 
178
        return self.helper._get_server_admin_password_new_style(server)
 
179
 
 
180
    def _image_ref_from_req_data(self, data):
 
181
        return data['server']['imageRef']
 
182
 
 
183
    def _flavor_id_from_req_data(self, data):
 
184
        return data['server']['flavorRef']
 
185
 
 
186
 
 
187
def create_resource(version):
 
188
    controller = {
 
189
        '1.0': Controller,
 
190
        '1.1': ControllerV11,
 
191
    }[version]()
 
192
 
136
193
    metadata = {
137
194
        "attributes": {
138
195
            "zone": ["id", "api_url", "name", "capabilities"],
144
201
                                                  metadata=metadata),
145
202
    }
146
203
 
147
 
    return wsgi.Resource(Controller(), serializers=serializers)
 
204
    deserializers = {
 
205
        'application/xml': helper.ServerXMLDeserializer(),
 
206
    }
 
207
 
 
208
    return wsgi.Resource(controller, serializers=serializers,
 
209
                         deserializers=deserializers)