Skip to content

Commit

Permalink
linstor/volume_modify: allow set property for volumes
Browse files Browse the repository at this point in the history
also do rest-api version checking based on features
  • Loading branch information
rp- committed Jun 25, 2019
1 parent 3b2b6ff commit e3aa17b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion linstor-common
Submodule linstor-common updated 2 files
+18 −0 consts.json
+43 −7 properties.json
50 changes: 46 additions & 4 deletions linstor/linstorapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def __init__(self, ctrl_host, timeout=300, keep_alive=False):
self._rest_conn = None # type: HTTPConnection
self._connected = False
self._mode_curl = False
self._ctrl_version = None

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

def _require_version(self, required_version):
"""
:param str required_version: semantic version string
:return: True if supported
:raises: LinstorError if server version is lower than required version
"""
if self._ctrl_version and StrictVersion(self._ctrl_version.rest_api_version) < StrictVersion(required_version):
raise LinstorError(
"Volume modify not supported by server, REST-API-VERSION: " + self._ctrl_version.rest_api_version +
"; needed " + required_version
)

def _rest_request(self, apicall, method, path, body=None, reconnect=True):
"""
Expand Down Expand Up @@ -341,12 +355,12 @@ def connect(self):
self._rest_conn = HTTPConnection(host=url.hostname, port=port, timeout=self._timeout)
try:
self._rest_conn.connect()
ctrl_version = self.controller_version()
if not ctrl_version.rest_api_version.startswith("1") or \
StrictVersion(API_VERSION_MIN) > StrictVersion(ctrl_version.rest_api_version):
self._ctrl_version = self.controller_version()
if not self._ctrl_version.rest_api_version.startswith("1") or \
StrictVersion(API_VERSION_MIN) > StrictVersion(self._ctrl_version.rest_api_version):
self._rest_conn.close()
raise LinstorApiCallError(
"Client doesn't support Controller rest api version: " + ctrl_version.rest_api_version +
"Client doesn't support Controller rest api version: " + self._ctrl_version.rest_api_version +
"; Minimal version needed: " + API_VERSION_MIN
)
self._connected = True
Expand Down Expand Up @@ -1314,6 +1328,34 @@ def volume_list(self, filter_by_nodes=None, filter_by_stor_pools=None, filter_by

return result + errors

def volume_modify(self, node_name, rsc_name, vlm_nr, property_dict, delete_props=None):
"""
Modify properties of a given resource.
:param str node_name: Node name where the resource is deployed.
:param str rsc_name: Name of the resource.
:param int vlm_nr: Number of the volume
:param dict[str, str] property_dict: Dict containing key, value pairs for new values.
:param list[str] delete_props: List of properties to delete
:return: A list containing ApiCallResponses from the controller.
:rtype: list[ApiCallResponse]
"""
self._require_version("1.0.6")

body = {}

if property_dict:
body["override_props"] = property_dict

if delete_props:
body["delete_props"] = delete_props

return self._rest_request(
apiconsts.API_MOD_VLM,
"PUT", "/v1/resource-definitions/" + rsc_name + "/resources/" + node_name + "/volumes/" + str(vlm_nr),
body
)

def resource_toggle_disk(
self,
node_name,
Expand Down

0 comments on commit e3aa17b

Please sign in to comment.