[openstack-dev] [Glance] Why are location indices in Glance '1' (and not '0') based?

David Koo kpublicmail at gmail.com
Sat Feb 8 03:25:40 UTC 2014


Hi all,

In api.v2.images.ImagesController._get_locations_op_pos there is a
comment that location indices start from one from the client's
perspective and the code subtracts one from the incoming 'index
position' parameter before proceeding with the subsequent operations.

But I see that json-patch RFCs[1][2] say patch indices for lists must be
zero-based and not one-based.

[1] (which is referred to in the "image service dev guide") says:

    If the currently referenced value is a JSON array, the token MUST
    contain an unsigned base-10 integer value, and the new referenced
    value is the array element with the zero-based index identified by
    the token.

And [2] (which I got from Googling and seems newer than [1]) says:

   o  If the currently referenced value is a JSON array, the reference
      token MUST contain either:

      *  characters comprised of digits (see ABNF below; note that
         leading zeros are not allowed) that represent an unsigned
         base-10 integer value, making the new referenced value the
         array element with the zero-based index identified by the
         token, or

      *  exactly the single character "-", making the new referenced
         value the (nonexistent) member after the last array element.

Indeed, warlock (which glanceclient uses to generate json patches)
generates patches with a zero based index, not one.

So why is the location indexing one-based, have I missed something?

Thanks.

--
Koo

[1] http://tools.ietf.org/html/draft-pbryan-zyp-json-pointer-02
[2] http://tools.ietf.org/html/rfc6901



More information about the OpenStack-dev mailing list