Skip to content

Commit e3aa17b

Browse files
committed
linstor/volume_modify: allow set property for volumes
also do rest-api version checking based on features
1 parent 3b2b6ff commit e3aa17b

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

linstor-common

Submodule linstor-common updated 2 files

linstor/linstorapi.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def __init__(self, ctrl_host, timeout=300, keep_alive=False):
126126
self._rest_conn = None # type: HTTPConnection
127127
self._connected = False
128128
self._mode_curl = False
129+
self._ctrl_version = None
129130

130131
self._http_headers = {
131132
"User-Agent": "PythonLinstor/{v} (API{a})".format(v=VERSION, a=API_VERSION_MIN),
@@ -164,6 +165,19 @@ def _decode_response_data(cls, response):
164165
return zlib.decompress(data, zlib.MAX_WBITS | 16)
165166
return data
166167

168+
def _require_version(self, required_version):
169+
"""
170+
171+
:param str required_version: semantic version string
172+
:return: True if supported
173+
:raises: LinstorError if server version is lower than required version
174+
"""
175+
if self._ctrl_version and StrictVersion(self._ctrl_version.rest_api_version) < StrictVersion(required_version):
176+
raise LinstorError(
177+
"Volume modify not supported by server, REST-API-VERSION: " + self._ctrl_version.rest_api_version +
178+
"; needed " + required_version
179+
)
180+
167181
def _rest_request(self, apicall, method, path, body=None, reconnect=True):
168182
"""
169183
@@ -341,12 +355,12 @@ def connect(self):
341355
self._rest_conn = HTTPConnection(host=url.hostname, port=port, timeout=self._timeout)
342356
try:
343357
self._rest_conn.connect()
344-
ctrl_version = self.controller_version()
345-
if not ctrl_version.rest_api_version.startswith("1") or \
346-
StrictVersion(API_VERSION_MIN) > StrictVersion(ctrl_version.rest_api_version):
358+
self._ctrl_version = self.controller_version()
359+
if not self._ctrl_version.rest_api_version.startswith("1") or \
360+
StrictVersion(API_VERSION_MIN) > StrictVersion(self._ctrl_version.rest_api_version):
347361
self._rest_conn.close()
348362
raise LinstorApiCallError(
349-
"Client doesn't support Controller rest api version: " + ctrl_version.rest_api_version +
363+
"Client doesn't support Controller rest api version: " + self._ctrl_version.rest_api_version +
350364
"; Minimal version needed: " + API_VERSION_MIN
351365
)
352366
self._connected = True
@@ -1314,6 +1328,34 @@ def volume_list(self, filter_by_nodes=None, filter_by_stor_pools=None, filter_by
13141328

13151329
return result + errors
13161330

1331+
def volume_modify(self, node_name, rsc_name, vlm_nr, property_dict, delete_props=None):
1332+
"""
1333+
Modify properties of a given resource.
1334+
1335+
:param str node_name: Node name where the resource is deployed.
1336+
:param str rsc_name: Name of the resource.
1337+
:param int vlm_nr: Number of the volume
1338+
:param dict[str, str] property_dict: Dict containing key, value pairs for new values.
1339+
:param list[str] delete_props: List of properties to delete
1340+
:return: A list containing ApiCallResponses from the controller.
1341+
:rtype: list[ApiCallResponse]
1342+
"""
1343+
self._require_version("1.0.6")
1344+
1345+
body = {}
1346+
1347+
if property_dict:
1348+
body["override_props"] = property_dict
1349+
1350+
if delete_props:
1351+
body["delete_props"] = delete_props
1352+
1353+
return self._rest_request(
1354+
apiconsts.API_MOD_VLM,
1355+
"PUT", "/v1/resource-definitions/" + rsc_name + "/resources/" + node_name + "/volumes/" + str(vlm_nr),
1356+
body
1357+
)
1358+
13171359
def resource_toggle_disk(
13181360
self,
13191361
node_name,

0 commit comments

Comments
 (0)