|
26 | 26 | from oslo_utils import excutils |
27 | 27 | from oslo_utils import strutils |
28 | 28 | from oslo_utils import timeutils |
| 29 | +from oslo_utils import uuidutils |
29 | 30 | from oslo_utils import versionutils |
30 | 31 |
|
31 | 32 | from cinder import action_track |
@@ -298,6 +299,37 @@ def create(self, context, size, name, description, snapshot=None, |
298 | 299 | if CONF.storage_availability_zone: |
299 | 300 | availability_zones.add(CONF.storage_availability_zone) |
300 | 301 |
|
| 302 | + # Validate the scheduler_hints same_host and different_hosts as |
| 303 | + # valid volume UUIDs. |
| 304 | + if scheduler_hints: |
| 305 | + validate_volume_uuids = [] |
| 306 | + if 'same_host' in scheduler_hints: |
| 307 | + if isinstance(scheduler_hints['same_host'], list): |
| 308 | + validate_volume_uuids.extend(scheduler_hints['same_host']) |
| 309 | + else: |
| 310 | + validate_volume_uuids.append(scheduler_hints['same_host']) |
| 311 | + elif 'different_host' in scheduler_hints: |
| 312 | + if isinstance(scheduler_hints['different_host'], list): |
| 313 | + validate_volume_uuids.extend( |
| 314 | + scheduler_hints['different_host']) |
| 315 | + else: |
| 316 | + validate_volume_uuids.append( |
| 317 | + scheduler_hints['different_host']) |
| 318 | + |
| 319 | + for hint_volume_id in validate_volume_uuids: |
| 320 | + if not uuidutils.is_uuid_like(hint_volume_id): |
| 321 | + msg = _("Invalid UUID(s) '%s' provided in scheduler " |
| 322 | + "hints.") % hint_volume_id |
| 323 | + raise exception.InvalidInput(reason=msg) |
| 324 | + |
| 325 | + # Now validate that the uuids are valid volumes that exist in |
| 326 | + # cinder DB. |
| 327 | + for hint_volume_id in validate_volume_uuids: |
| 328 | + # All we have to do here is try and fetch the UUID as volume. |
| 329 | + # If the UUID doesn't exist in the DB, Cinder will throw |
| 330 | + # a VolumeNotFound exception. |
| 331 | + objects.Volume.get_by_id(context, hint_volume_id) |
| 332 | + |
301 | 333 | # Force the scheduler hints into the volume metadata |
302 | 334 | if not metadata: |
303 | 335 | metadata = {} |
|
0 commit comments