Merge "Add combined function get_vol_type_by_name_or_id"
This commit is contained in:
commit
a956bb5ef0
@ -13,7 +13,6 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import uuidutils
|
||||
from webob import exc
|
||||
|
||||
from cinder.api.contrib import resource_common_manage
|
||||
@ -120,13 +119,8 @@ class VolumeManageController(wsgi.Controller):
|
||||
req_volume_type = volume.get('volume_type', None)
|
||||
if req_volume_type:
|
||||
# Not found exception will be handled at the wsgi level
|
||||
if not uuidutils.is_uuid_like(req_volume_type):
|
||||
kwargs['volume_type'] = \
|
||||
volume_types.get_volume_type_by_name(
|
||||
context, req_volume_type)
|
||||
else:
|
||||
kwargs['volume_type'] = volume_types.get_volume_type(
|
||||
context, req_volume_type)
|
||||
kwargs['volume_type'] = (
|
||||
volume_types.get_by_name_or_id(context, req_volume_type))
|
||||
else:
|
||||
kwargs['volume_type'] = {}
|
||||
|
||||
|
@ -226,13 +226,8 @@ class VolumeController(wsgi.Controller):
|
||||
req_volume_type = volume.get('volume_type', None)
|
||||
if req_volume_type:
|
||||
# Not found exception will be handled at the wsgi level
|
||||
if not uuidutils.is_uuid_like(req_volume_type):
|
||||
kwargs['volume_type'] = \
|
||||
volume_types.get_volume_type_by_name(
|
||||
context, req_volume_type)
|
||||
else:
|
||||
kwargs['volume_type'] = volume_types.get_volume_type(
|
||||
context, req_volume_type)
|
||||
kwargs['volume_type'] = (
|
||||
volume_types.get_by_name_or_id(context, req_volume_type))
|
||||
|
||||
kwargs['metadata'] = volume.get('metadata', None)
|
||||
|
||||
|
@ -196,13 +196,8 @@ class VolumeController(wsgi.Controller):
|
||||
req_volume_type = volume.get('volume_type', None)
|
||||
if req_volume_type:
|
||||
# Not found exception will be handled at the wsgi level
|
||||
if not uuidutils.is_uuid_like(req_volume_type):
|
||||
kwargs['volume_type'] = \
|
||||
volume_types.get_volume_type_by_name(
|
||||
context, req_volume_type)
|
||||
else:
|
||||
kwargs['volume_type'] = volume_types.get_volume_type(
|
||||
context, req_volume_type)
|
||||
kwargs['volume_type'] = (
|
||||
volume_types.get_by_name_or_id(context, req_volume_type))
|
||||
|
||||
kwargs['metadata'] = volume.get('metadata', None)
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
"""The volumes V3 api."""
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import uuidutils
|
||||
from webob import exc
|
||||
|
||||
from cinder.api import common
|
||||
@ -154,13 +153,8 @@ class VolumeController(volumes_v2.VolumeController):
|
||||
req_volume_type = volume.get('volume_type', None)
|
||||
if req_volume_type:
|
||||
# Not found exception will be handled at the wsgi level
|
||||
if not uuidutils.is_uuid_like(req_volume_type):
|
||||
kwargs['volume_type'] = (
|
||||
volume_types.get_volume_type_by_name(
|
||||
context, req_volume_type))
|
||||
else:
|
||||
kwargs['volume_type'] = volume_types.get_volume_type(
|
||||
context, req_volume_type)
|
||||
volume_types.get_by_name_or_id(context, req_volume_type))
|
||||
|
||||
kwargs['metadata'] = volume.get('metadata', None)
|
||||
|
||||
|
@ -26,7 +26,6 @@ from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
|
||||
from cinder.api import common
|
||||
@ -1460,12 +1459,8 @@ class API(base.Base):
|
||||
|
||||
# Support specifying volume type by ID or name
|
||||
try:
|
||||
if uuidutils.is_uuid_like(new_type):
|
||||
vol_type = volume_types.get_volume_type(context.elevated(),
|
||||
new_type)
|
||||
else:
|
||||
vol_type = volume_types.get_volume_type_by_name(
|
||||
context.elevated(), new_type)
|
||||
vol_type = (
|
||||
volume_types.get_by_name_or_id(context.elevated(), new_type))
|
||||
except exception.InvalidVolumeType:
|
||||
msg = _('Invalid volume_type passed: %s.') % new_type
|
||||
LOG.error(msg)
|
||||
|
@ -23,6 +23,7 @@
|
||||
from oslo_config import cfg
|
||||
from oslo_db import exception as db_exc
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from cinder import context
|
||||
from cinder import db
|
||||
@ -130,6 +131,13 @@ def get_volume_type(ctxt, id, expected_fields=None):
|
||||
return db.volume_type_get(ctxt, id, expected_fields=expected_fields)
|
||||
|
||||
|
||||
def get_by_name_or_id(context, identity):
|
||||
"""Retrieves volume type by id or name"""
|
||||
if not uuidutils.is_uuid_like(identity):
|
||||
return get_volume_type_by_name(context, identity)
|
||||
return get_volume_type(context, identity)
|
||||
|
||||
|
||||
def get_volume_type_by_name(context, name):
|
||||
"""Retrieves single volume type by name."""
|
||||
if name is None:
|
||||
|
Loading…
Reference in New Issue
Block a user