OpenStack Image Management (Glance)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

router.py 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # Copyright 2011 OpenStack Foundation
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. from glance.api.v1 import images
  16. from glance.api.v1 import members
  17. from glance.common import wsgi
  18. class API(wsgi.Router):
  19. """WSGI router for Glance v1 API requests."""
  20. def __init__(self, mapper):
  21. reject_method_resource = wsgi.Resource(wsgi.RejectMethodController())
  22. images_resource = images.create_resource()
  23. mapper.connect("/",
  24. controller=images_resource,
  25. action="index")
  26. mapper.connect("/images",
  27. controller=images_resource,
  28. action='index',
  29. conditions={'method': ['GET']})
  30. mapper.connect("/images",
  31. controller=images_resource,
  32. action='create',
  33. conditions={'method': ['POST']})
  34. mapper.connect("/images",
  35. controller=reject_method_resource,
  36. action='reject',
  37. allowed_methods='GET, POST')
  38. mapper.connect("/images/detail",
  39. controller=images_resource,
  40. action='detail',
  41. conditions={'method': ['GET', 'HEAD']})
  42. mapper.connect("/images/detail",
  43. controller=reject_method_resource,
  44. action='reject',
  45. allowed_methods='GET, HEAD')
  46. mapper.connect("/images/{id}",
  47. controller=images_resource,
  48. action="meta",
  49. conditions=dict(method=["HEAD"]))
  50. mapper.connect("/images/{id}",
  51. controller=images_resource,
  52. action="show",
  53. conditions=dict(method=["GET"]))
  54. mapper.connect("/images/{id}",
  55. controller=images_resource,
  56. action="update",
  57. conditions=dict(method=["PUT"]))
  58. mapper.connect("/images/{id}",
  59. controller=images_resource,
  60. action="delete",
  61. conditions=dict(method=["DELETE"]))
  62. mapper.connect("/images/{id}",
  63. controller=reject_method_resource,
  64. action='reject',
  65. allowed_methods='GET, HEAD, PUT, DELETE')
  66. members_resource = members.create_resource()
  67. mapper.connect("/images/{image_id}/members",
  68. controller=members_resource,
  69. action="index",
  70. conditions={'method': ['GET']})
  71. mapper.connect("/images/{image_id}/members",
  72. controller=members_resource,
  73. action="update_all",
  74. conditions=dict(method=["PUT"]))
  75. mapper.connect("/images/{image_id}/members",
  76. controller=reject_method_resource,
  77. action='reject',
  78. allowed_methods='GET, PUT')
  79. mapper.connect("/images/{image_id}/members/{id}",
  80. controller=members_resource,
  81. action="show",
  82. conditions={'method': ['GET']})
  83. mapper.connect("/images/{image_id}/members/{id}",
  84. controller=members_resource,
  85. action="update",
  86. conditions={'method': ['PUT']})
  87. mapper.connect("/images/{image_id}/members/{id}",
  88. controller=members_resource,
  89. action="delete",
  90. conditions={'method': ['DELETE']})
  91. mapper.connect("/images/{image_id}/members/{id}",
  92. controller=reject_method_resource,
  93. action='reject',
  94. allowed_methods='GET, PUT, DELETE')
  95. mapper.connect("/shared-images/{id}",
  96. controller=members_resource,
  97. action="index_shared_images")
  98. super(API, self).__init__(mapper)