Lin Yang d61ce6ee59 Add resize function for RSD 2.4 volume
This volume.resize() function accept one parameter "num_bytes". It
will throw an exception when num_bytes is not greater than current
volume size, because RSD POMD only support extend the size right now,
not shrink.

Change-Id: I7037fbe01a1aa901de3d66c851c5466d2501b2ca
2018-12-07 13:13:21 -08:00

59 lines
2.1 KiB
Python

# Copyright 2018 Intel, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from sushy import exceptions
from sushy.resources import base
from rsd_lib.resources.v2_3.storage_service import volume
class Volume(volume.Volume):
def resize(self, num_bytes):
"""Update volume properties
:param num_bytes: size in bytes of new resized volume
"""
if not isinstance(num_bytes, int):
raise exceptions.InvalidParameterValueError(
parameter='num_bytes', value=num_bytes,
valid_values='integer')
if self.capacity_bytes and num_bytes <= self.capacity_bytes:
raise exceptions.InvalidParameterValueError(
parameter='num_bytes', value=num_bytes,
valid_values='> {0}'.format(self.capacity_bytes))
data = {"Capacity": {"Data": {'AllocatedBytes': num_bytes}}}
self._conn.patch(self.path, data=data)
class VolumeCollection(base.ResourceCollectionBase):
@property
def _resource_type(self):
return Volume
def __init__(self, connector, path, redfish_version=None):
"""A class representing a VolumeCollection
:param connector: A Connector instance
:param path: The canonical path to the Volume collection resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(VolumeCollection, self).__init__(connector, path,
redfish_version)