Use REST API for volume type_access and volume create
Change-Id: Ibf3e16d7e2faab3ed9afe7e2b69216b59aceecdf Signed-off-by: Rosario Di Somma <rosario.disomma@dreamhost.com>
This commit is contained in:
parent
d7be843574
commit
be92751781
|
@ -212,33 +212,6 @@ class NovaImageList(task_manager.Task):
|
|||
return client.nova_client.images.list()
|
||||
|
||||
|
||||
class VolumeTypeList(task_manager.Task):
|
||||
def main(self, client):
|
||||
return client.cinder_client.volume_types.list()
|
||||
|
||||
|
||||
class VolumeTypeAccessList(task_manager.Task):
|
||||
def main(self, client):
|
||||
return client.cinder_client.volume_type_access.list(**self.args)
|
||||
|
||||
|
||||
class VolumeTypeAccessAdd(task_manager.Task):
|
||||
def main(self, client):
|
||||
return client.cinder_client.volume_type_access.add_project_access(
|
||||
**self.args)
|
||||
|
||||
|
||||
class VolumeTypeAccessRemove(task_manager.Task):
|
||||
def main(self, client):
|
||||
return client.cinder_client.volume_type_access.remove_project_access(
|
||||
**self.args)
|
||||
|
||||
|
||||
class VolumeCreate(task_manager.Task):
|
||||
def main(self, client):
|
||||
return client.cinder_client.volumes.create(**self.args)
|
||||
|
||||
|
||||
class VolumeDelete(task_manager.Task):
|
||||
def main(self, client):
|
||||
client.cinder_client.volumes.delete(**self.args)
|
||||
|
|
|
@ -1727,7 +1727,8 @@ class OpenStackCloud(_normalize.Normalizer):
|
|||
"""
|
||||
with _utils.shade_exceptions("Error fetching volume_type list"):
|
||||
return self._normalize_volume_types(
|
||||
self.manager.submit_task(_tasks.VolumeTypeList()))
|
||||
self._volume_client.get(
|
||||
'/types', params=dict(is_public='None')))
|
||||
|
||||
@_utils.cache_on_arguments()
|
||||
def list_availability_zone_names(self, unavailable=False):
|
||||
|
@ -3863,7 +3864,6 @@ class OpenStackCloud(_normalize.Normalizer):
|
|||
:raises: OpenStackCloudTimeout if wait time exceeded.
|
||||
:raises: OpenStackCloudException on operation error.
|
||||
"""
|
||||
|
||||
if image:
|
||||
image_obj = self.get_image(image)
|
||||
if not image_obj:
|
||||
|
@ -3873,9 +3873,10 @@ class OpenStackCloud(_normalize.Normalizer):
|
|||
image=image))
|
||||
kwargs['imageRef'] = image_obj['id']
|
||||
kwargs = self._get_volume_kwargs(kwargs)
|
||||
kwargs['size'] = size
|
||||
with _utils.shade_exceptions("Error in creating volume"):
|
||||
volume = self.manager.submit_task(_tasks.VolumeCreate(
|
||||
size=size, **kwargs))
|
||||
volume = self._volume_client.post(
|
||||
'/volumes', json=dict(volume=kwargs))
|
||||
self.list_volumes.invalidate(self)
|
||||
|
||||
if volume['status'] == 'error':
|
||||
|
|
|
@ -2014,9 +2014,9 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
|
|||
"Unable to get volume type access {name}".format(
|
||||
name=name_or_id)):
|
||||
return self._normalize_volume_type_accesses(
|
||||
self.manager.submit_task(
|
||||
_tasks.VolumeTypeAccessList(volume_type=volume_type))
|
||||
)
|
||||
self._volume_client.get(
|
||||
'/types/{id}/os-volume-type-access'.format(
|
||||
id=volume_type.id)))
|
||||
|
||||
def add_volume_type_access(self, name_or_id, project_id):
|
||||
"""Grant access on a volume_type to a project.
|
||||
|
@ -2032,14 +2032,14 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
|
|||
if not volume_type:
|
||||
raise OpenStackCloudException(
|
||||
"VolumeType not found: %s" % name_or_id)
|
||||
with _utils.shade_exceptions(
|
||||
"Unable to authorize {project} "
|
||||
with _utils.shade_exceptions():
|
||||
payload = {'project': project_id}
|
||||
self._volume_client.post(
|
||||
'/types/{id}/action'.format(id=volume_type.id),
|
||||
json=dict(addProjectAccess=payload),
|
||||
error_message="Unable to authorize {project} "
|
||||
"to use volume type {name}".format(
|
||||
name=name_or_id, project=project_id
|
||||
)):
|
||||
self.manager.submit_task(
|
||||
_tasks.VolumeTypeAccessAdd(
|
||||
volume_type=volume_type, project=project_id))
|
||||
name=name_or_id, project=project_id))
|
||||
|
||||
def remove_volume_type_access(self, name_or_id, project_id):
|
||||
"""Revoke access on a volume_type to a project.
|
||||
|
@ -2053,14 +2053,14 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
|
|||
if not volume_type:
|
||||
raise OpenStackCloudException(
|
||||
"VolumeType not found: %s" % name_or_id)
|
||||
with _utils.shade_exceptions(
|
||||
"Unable to revoke {project} "
|
||||
with _utils.shade_exceptions():
|
||||
payload = {'project': project_id}
|
||||
self._volume_client.post(
|
||||
'/types/{id}/action'.format(id=volume_type.id),
|
||||
json=dict(removeProjectAccess=payload),
|
||||
error_message="Unable to revoke {project} "
|
||||
"to use volume type {name}".format(
|
||||
name=name_or_id, project=project_id
|
||||
)):
|
||||
self.manager.submit_task(
|
||||
_tasks.VolumeTypeAccessRemove(
|
||||
volume_type=volume_type, project=project_id))
|
||||
name=name_or_id, project=project_id))
|
||||
|
||||
def set_compute_quotas(self, name_or_id, **kwargs):
|
||||
""" Set a quota in a project
|
||||
|
|
|
@ -19,7 +19,7 @@ test_volume
|
|||
Functional tests for `shade` block storage methods.
|
||||
"""
|
||||
import testtools
|
||||
from shade.exc import OpenStackCloudException
|
||||
from shade import exc
|
||||
from shade.tests.functional import base
|
||||
|
||||
|
||||
|
@ -79,7 +79,7 @@ class TestVolumeType(base.BaseFunctionalTestCase):
|
|||
|
||||
def test_add_volume_type_access_missing_volume(self):
|
||||
with testtools.ExpectedException(
|
||||
OpenStackCloudException,
|
||||
exc.OpenStackCloudException,
|
||||
"VolumeType not found.*"
|
||||
):
|
||||
self.operator_cloud.add_volume_type_access(
|
||||
|
@ -88,7 +88,7 @@ class TestVolumeType(base.BaseFunctionalTestCase):
|
|||
|
||||
def test_remove_volume_type_access_missing_volume(self):
|
||||
with testtools.ExpectedException(
|
||||
OpenStackCloudException,
|
||||
exc.OpenStackCloudException,
|
||||
"VolumeType not found.*"
|
||||
):
|
||||
self.operator_cloud.remove_volume_type_access(
|
||||
|
@ -97,7 +97,7 @@ class TestVolumeType(base.BaseFunctionalTestCase):
|
|||
|
||||
def test_add_volume_type_access_bad_project(self):
|
||||
with testtools.ExpectedException(
|
||||
OpenStackCloudException,
|
||||
exc.OpenStackCloudBadRequest,
|
||||
"Unable to authorize.*"
|
||||
):
|
||||
self.operator_cloud.add_volume_type_access(
|
||||
|
@ -106,7 +106,7 @@ class TestVolumeType(base.BaseFunctionalTestCase):
|
|||
|
||||
def test_remove_volume_type_access_missing_project(self):
|
||||
with testtools.ExpectedException(
|
||||
OpenStackCloudException,
|
||||
exc.OpenStackCloudURINotFound,
|
||||
"Unable to revoke.*"
|
||||
):
|
||||
self.operator_cloud.remove_volume_type_access(
|
||||
|
|
|
@ -268,10 +268,6 @@ class TestMemoryCache(base.RequestsMockTestCase):
|
|||
uri=self.get_mock_url(
|
||||
'volumev2', 'public', append=['volumes']),
|
||||
json={'volume': fake_vol_creating}),
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(
|
||||
'volumev2', 'public', append=['volumes', _id]),
|
||||
json={'volume': [fake_volb4, fake_vol_creating]}),
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(
|
||||
'volumev2', 'public', append=['volumes', 'detail']),
|
||||
|
|
Loading…
Reference in New Issue