[openstack-dev] [nova] Future of the Nova API
Alex Xu
xuhj at linux.vnet.ibm.com
Fri Feb 28 08:21:43 UTC 2014
On 2014?02?28? 13:40, Chris Friesen wrote:
> On 02/27/2014 06:00 PM, Alex Xu wrote:
>
>> Does mean our code looks like as below?
>> if client_version > 2:
>> ....
>> elif client_version > 3
>> ...
>> elif client_version > 4:
>> ...
>> elif client_version > 5:
>> ...
>> elif client_version > 6:
>> ..
>>
>> And we need test each version... That looks bad...
>
> I don't think the code would look like that
>
> Each part of the API could look at the version separately. And each
> part of the API only needs to check the client version if it has made
> a backwards-incompatible change.
>
> So a part of the API that only made one backwards-incompatible change
> at version 3 would only need one check.
>
> if client_version >= 3
> do_newer_something()
> else
> do_something()
>
>
>
> Maybe some other part of the API made a change at v6 (assuming global
> versioning). That part of the API would also only need one check.
>
>
> if client version >= 6
> do_newer_something()
> else
> do_something()
>
Yes, I know it. But it still looks bad :(
In api code, it will be looks like as below:
def do_something(self, body):
if client_version == 2:
args = body['SomeArguments']
elif client_version == 3:
args = body['some_arguments']
try:
ret = self.compute_api.do_something(args)
except exception.SomeException:
if client_version == 2:
raise exception.HTTPBadRequest()
elif client_version == 4:
raise exception.HTTPConflictRequest()
if client_version == 2:
return {'some_arguments': ret}
elif client_version == 3:
return {'SomeArguments': ret}
>
> Chris
>
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20140228/8b7daeb0/attachment.html>
More information about the OpenStack-dev
mailing list