Merge "Return volume_type extra specs based on policy"
This commit is contained in:
commit
c8a7e93ebe
@ -21,11 +21,14 @@ from webob import exc
|
|||||||
from cinder.api.openstack import wsgi
|
from cinder.api.openstack import wsgi
|
||||||
from cinder.api.v2.views import types as views_types
|
from cinder.api.v2.views import types as views_types
|
||||||
from cinder.api import xmlutil
|
from cinder.api import xmlutil
|
||||||
|
from cinder import context as ctx
|
||||||
from cinder import exception
|
from cinder import exception
|
||||||
from cinder.i18n import _
|
from cinder.i18n import _
|
||||||
from cinder import utils
|
from cinder import utils
|
||||||
from cinder.volume import volume_types
|
from cinder.volume import volume_types
|
||||||
|
|
||||||
|
import cinder.policy
|
||||||
|
|
||||||
|
|
||||||
def make_voltype(elem):
|
def make_voltype(elem):
|
||||||
elem.set('id')
|
elem.set('id')
|
||||||
@ -57,6 +60,18 @@ class VolumeTypesController(wsgi.Controller):
|
|||||||
|
|
||||||
_view_builder_class = views_types.ViewBuilder
|
_view_builder_class = views_types.ViewBuilder
|
||||||
|
|
||||||
|
def _validate_policy(self, context):
|
||||||
|
target = {
|
||||||
|
'project_id': context.project_id,
|
||||||
|
'user_id': context.user_id,
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
action = 'volume_extension:access_types_extra_specs'
|
||||||
|
cinder.policy.enforce(context, action, target)
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
@wsgi.serializers(xml=VolumeTypesTemplate)
|
@wsgi.serializers(xml=VolumeTypesTemplate)
|
||||||
def index(self, req):
|
def index(self, req):
|
||||||
"""Returns the list of volume types."""
|
"""Returns the list of volume types."""
|
||||||
@ -69,6 +84,9 @@ class VolumeTypesController(wsgi.Controller):
|
|||||||
"""Return a single volume type item."""
|
"""Return a single volume type item."""
|
||||||
context = req.environ['cinder.context']
|
context = req.environ['cinder.context']
|
||||||
|
|
||||||
|
if not context.is_admin and self._validate_policy(context):
|
||||||
|
context = ctx.get_admin_context()
|
||||||
|
|
||||||
# get default volume type
|
# get default volume type
|
||||||
if id is not None and id == 'default':
|
if id is not None and id == 'default':
|
||||||
vol_type = volume_types.get_default_volume_type()
|
vol_type = volume_types.get_default_volume_type()
|
||||||
@ -109,6 +127,8 @@ class VolumeTypesController(wsgi.Controller):
|
|||||||
"""Helper function that returns a list of type dicts."""
|
"""Helper function that returns a list of type dicts."""
|
||||||
filters = {}
|
filters = {}
|
||||||
context = req.environ['cinder.context']
|
context = req.environ['cinder.context']
|
||||||
|
if not context.is_admin and self._validate_policy(context):
|
||||||
|
context = ctx.get_admin_context()
|
||||||
if context.is_admin:
|
if context.is_admin:
|
||||||
# Only admin has query access to all volume types
|
# Only admin has query access to all volume types
|
||||||
filters['is_public'] = self._parse_is_public(
|
filters['is_public'] = self._parse_is_public(
|
||||||
|
@ -25,10 +25,10 @@ class ViewBuilder(common.ViewBuilder):
|
|||||||
trimmed = dict(id=volume_type.get('id'),
|
trimmed = dict(id=volume_type.get('id'),
|
||||||
name=volume_type.get('name'),
|
name=volume_type.get('name'),
|
||||||
is_public=volume_type.get('is_public'),
|
is_public=volume_type.get('is_public'),
|
||||||
extra_specs=volume_type.get('extra_specs'),
|
|
||||||
description=volume_type.get('description'))
|
description=volume_type.get('description'))
|
||||||
if context.is_admin:
|
if context.is_admin:
|
||||||
trimmed['qos_specs_id'] = volume_type.get('qos_specs_id')
|
trimmed['qos_specs_id'] = volume_type.get('qos_specs_id')
|
||||||
|
trimmed['extra_specs'] = volume_type.get('extra_specs')
|
||||||
return trimmed if brief else dict(volume_type=trimmed)
|
return trimmed if brief else dict(volume_type=trimmed)
|
||||||
|
|
||||||
def index(self, request, volume_types):
|
def index(self, request, volume_types):
|
||||||
|
@ -85,7 +85,7 @@ class VolumeTypesApiTest(test.TestCase):
|
|||||||
self.stubs.Set(volume_types, 'get_all_types',
|
self.stubs.Set(volume_types, 'get_all_types',
|
||||||
return_volume_types_get_all_types)
|
return_volume_types_get_all_types)
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank('/v2/fake/types')
|
req = fakes.HTTPRequest.blank('/v2/fake/types', use_admin_context=True)
|
||||||
res_dict = self.controller.index(req)
|
res_dict = self.controller.index(req)
|
||||||
|
|
||||||
self.assertEqual(3, len(res_dict['volume_types']))
|
self.assertEqual(3, len(res_dict['volume_types']))
|
||||||
@ -171,7 +171,6 @@ class VolumeTypesApiTest(test.TestCase):
|
|||||||
name='new_type',
|
name='new_type',
|
||||||
description='new_type_desc',
|
description='new_type_desc',
|
||||||
is_public=True,
|
is_public=True,
|
||||||
extra_specs={},
|
|
||||||
id=42,
|
id=42,
|
||||||
)
|
)
|
||||||
self.assertDictMatch(output['volume_type'], expected_volume_type)
|
self.assertDictMatch(output['volume_type'], expected_volume_type)
|
||||||
@ -237,7 +236,6 @@ class VolumeTypesApiTest(test.TestCase):
|
|||||||
name='new_type',
|
name='new_type',
|
||||||
description='new_type_desc',
|
description='new_type_desc',
|
||||||
is_public=True,
|
is_public=True,
|
||||||
extra_specs={},
|
|
||||||
id=42 + i
|
id=42 + i
|
||||||
)
|
)
|
||||||
self.assertDictMatch(output['volume_types'][i],
|
self.assertDictMatch(output['volume_types'][i],
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
"volume_extension:types_manage": "rule:admin_api",
|
"volume_extension:types_manage": "rule:admin_api",
|
||||||
"volume_extension:types_extra_specs": "rule:admin_api",
|
"volume_extension:types_extra_specs": "rule:admin_api",
|
||||||
|
"volume_extension:access_types_extra_specs": "rule:admin_api",
|
||||||
"volume_extension:volume_type_access": "rule:admin_or_owner",
|
"volume_extension:volume_type_access": "rule:admin_or_owner",
|
||||||
"volume_extension:volume_type_access:addProjectAccess": "rule:admin_api",
|
"volume_extension:volume_type_access:addProjectAccess": "rule:admin_api",
|
||||||
"volume_extension:volume_type_access:removeProjectAccess": "rule:admin_api",
|
"volume_extension:volume_type_access:removeProjectAccess": "rule:admin_api",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user