~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/api/controllers/v1/__init__.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-03-30 11:14:57 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20150330111457-kr4ju3guf22m4vbz
Tags: 2015.1~b3-0ubuntu1
* New upstream release.
  + d/control: 
    - Align with upstream dependencies.
    - Add dh-python to build-dependencies.
    - Add psmisc as a dependency. (LP: #1358820)
  + d/p/fix-requirements.patch: Rediffed.
  + d/ironic-conductor.init.in: Fixed typos in LSB headers,
    thanks to JJ Asghar. (LP: #1429962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
# edf532db: Add logic to store the config drive passed by Nova
55
55
 
56
56
# v1.1: API at the point in time when microversioning support was added
57
 
MIN_VER = base.Version({base.Version.string: "1.1"})
 
57
MIN_VER_STR = '1.1'
58
58
 
59
59
# v1.2: Renamed NOSTATE ("None") to AVAILABLE ("available")
60
60
# v1.3: Add node.driver_internal_info
61
61
# v1.4: Add MANAGEABLE state
62
 
MAX_VER = base.Version({base.Version.string: "1.4"})
 
62
# v1.5: Add logical node names
 
63
# v1.6: Add INSPECT* states
 
64
MAX_VER_STR = '1.6'
 
65
 
 
66
 
 
67
MIN_VER = base.Version({base.Version.string: MIN_VER_STR},
 
68
                       MIN_VER_STR, MAX_VER_STR)
 
69
MAX_VER = base.Version({base.Version.string: MAX_VER_STR},
 
70
                       MIN_VER_STR, MAX_VER_STR)
63
71
 
64
72
 
65
73
class MediaType(base.APIBase):
108
116
                                        'developer/ironic/dev',
109
117
                                        'api-spec-v1.html',
110
118
                                        bookmark=True, type='text/html')
111
 
                   ]
 
119
                    ]
112
120
        v1.media_types = [MediaType('application/json',
113
121
                          'application/vnd.openstack.ironic.v1+json')]
114
122
        v1.chassis = [link.Link.make_link('self', pecan.request.host_url,
117
125
                                           pecan.request.host_url,
118
126
                                           'chassis', '',
119
127
                                           bookmark=True)
120
 
                     ]
 
128
                      ]
121
129
        v1.nodes = [link.Link.make_link('self', pecan.request.host_url,
122
130
                                        'nodes', ''),
123
131
                    link.Link.make_link('bookmark',
124
132
                                        pecan.request.host_url,
125
133
                                        'nodes', '',
126
134
                                        bookmark=True)
127
 
                   ]
 
135
                    ]
128
136
        v1.ports = [link.Link.make_link('self', pecan.request.host_url,
129
137
                                        'ports', ''),
130
138
                    link.Link.make_link('bookmark',
131
139
                                        pecan.request.host_url,
132
140
                                        'ports', '',
133
141
                                        bookmark=True)
134
 
                   ]
 
142
                    ]
135
143
        v1.drivers = [link.Link.make_link('self', pecan.request.host_url,
136
144
                                          'drivers', ''),
137
145
                      link.Link.make_link('bookmark',
138
146
                                          pecan.request.host_url,
139
147
                                          'drivers', '',
140
148
                                          bookmark=True)
141
 
                     ]
 
149
                      ]
142
150
        return v1
143
151
 
144
152
 
157
165
        #       the request object to make the links.
158
166
        return V1.convert()
159
167
 
160
 
    def _check_version(self, version):
 
168
    def _check_version(self, version, headers=None):
 
169
        if headers is None:
 
170
            headers = {}
161
171
        # ensure that major version in the URL matches the header
162
172
        if version.major != BASE_VERSION:
163
173
            raise exc.HTTPNotAcceptable(_(
164
174
                "Mutually exclusive versions requested. Version %(ver)s "
165
 
                "requested but not supported by this service.")
166
 
                % {'ver': version})
 
175
                "requested but not supported by this service. The supported "
 
176
                "version range is: [%(min)s, %(max)s].") % {'ver': version,
 
177
                'min': MIN_VER_STR, 'max': MAX_VER_STR}, headers=headers)
167
178
        # ensure the minor version is within the supported range
168
179
        if version < MIN_VER or version > MAX_VER:
169
180
            raise exc.HTTPNotAcceptable(_(
170
 
                "Unsupported minor version requested. This API service "
171
 
                "supports the following version range: "
172
 
                "[%(min)s, %(max)s].") % {'min': MIN_VER,
173
 
                                          'max': MAX_VER})
 
181
                "Version %(ver)s was requested but the minor version is not "
 
182
                "supported by this service. The supported version range is: "
 
183
                "[%(min)s, %(max)s].") % {'ver': version, 'min': MIN_VER_STR,
 
184
                                          'max': MAX_VER_STR}, headers=headers)
174
185
 
175
186
    @pecan.expose()
176
187
    def _route(self, args):
177
 
        v = base.Version(pecan.request.headers)
 
188
        v = base.Version(pecan.request.headers, MIN_VER_STR, MAX_VER_STR)
 
189
 
178
190
        # Always set the min and max headers
179
 
        # FIXME: these are not being sent if _check_version raises an exception
180
 
        pecan.response.headers[base.Version.min_string] = str(MIN_VER)
181
 
        pecan.response.headers[base.Version.max_string] = str(MAX_VER)
 
191
        pecan.response.headers[base.Version.min_string] = MIN_VER_STR
 
192
        pecan.response.headers[base.Version.max_string] = MAX_VER_STR
182
193
 
183
194
        # assert that requested version is supported
184
 
        self._check_version(v)
 
195
        self._check_version(v, pecan.response.headers)
185
196
        pecan.response.headers[base.Version.string] = str(v)
186
197
        pecan.request.version = v
187
198