def allowed_datastore_version_volume_types(cls, context, datastore_version_id): """ List all allowed volume types for a given datastore and datastore version. If datastore version metadata is provided, then the valid volume types in that list are allowed. If datastore version metadata is not provided then all volume types known to cinder are allowed. """ metadata = cls.list_datastore_version_volume_type_associations( datastore_version_id) # then get the list of all volume types all_volume_types = volume_type_models.VolumeTypes(context) # if there's metadata: intersect, # else, whatever cinder has. if (metadata.count() != 0): # the volume types from metadata first ds_volume_types = tuple(f.value for f in metadata) # Cinder volume type names are unique, intersect allowed_volume_types = tuple( f for f in all_volume_types if ((f.name in ds_volume_types) or (f.id in ds_volume_types))) else: allowed_volume_types = tuple(all_volume_types) return allowed_volume_types
def test_volume_types(self, mock_client): mock_context = mock.MagicMock() mock_types = [mock.MagicMock(), mock.MagicMock()] mock_client(mock_context).volume_types.list.return_value = mock_types volume_types = models.VolumeTypes(mock_context) for i, volume_type in enumerate(volume_types): self.assertEqual(mock_types[i], volume_type.volume_type, "Volume type {} does not match.".format(i))
def index(self, req, tenant_id): """Return all volume types.""" context = req.environ[wsgi.CONTEXT_KEY] volume_types = models.VolumeTypes(context=context) return wsgi.Result( views.VolumeTypesView(volume_types, req).data(), 200)