summaryrefslogtreecommitdiffstats
path: root/openshift-storage-libs
diff options
context:
space:
mode:
Diffstat (limited to 'openshift-storage-libs')
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/heketi_ops.py39
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/openshift_ops.py30
2 files changed, 69 insertions, 0 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py b/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py
index c28c98d..7cb0478 100644
--- a/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py
+++ b/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py
@@ -1739,3 +1739,42 @@ def heketi_db_check(heketi_client_node, heketi_server_url, **kwargs):
cmd = TIMEOUT_PREFIX + cmd
out = heketi_cmd_run(heketi_client_node, cmd)
return json.loads(out)
+
+
+def heketi_volume_endpoint_patch(
+ heketi_client_node, heketi_server_url, volume_id, **kwargs):
+ """Execute heketi volume endpoint patch command.
+
+ Args:
+ heketi_client_node (str): Node on which cmd has to be executed.
+ heketi_server_url (str): Heketi server url
+ volume_id (str): Volume ID
+
+ Kwargs:
+ The keys, values in kwargs are:
+ - secret : (str)|None
+ - user : (str)|None
+
+ Returns:
+ dict: endpoint info on success
+
+ Raises:
+ exceptions.AssertionError: if command fails.
+ """
+ version = heketi_version.get_heketi_version(heketi_client_node)
+ if version < '9.0.0-1':
+ msg = (
+ "heketi-client package %s does not support endpoint patch "
+ "functionality" % version.v_str)
+ g.log.error(msg)
+ raise NotImplementedError(msg)
+
+ heketi_server_url, _, admin_key, user = _set_heketi_global_flags(
+ heketi_server_url, **kwargs)
+
+ cmd = "heketi-cli -s %s volume endpoint patch %s %s %s" % (
+ heketi_server_url, volume_id, admin_key, user)
+ cmd = TIMEOUT_PREFIX + cmd
+ out = heketi_cmd_run(heketi_client_node, cmd)
+
+ return json.loads(out)
diff --git a/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py b/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py
index bee7af4..87dd634 100644
--- a/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py
+++ b/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py
@@ -1842,3 +1842,33 @@ def oc_create_service_monitor(hostname, sm_name="heketi",
})
oc_create(hostname, sm_data, 'stdin')
return sm_name
+
+
+def oc_patch(ocp_node, rtype, rname, changes, raise_on_error=True):
+ """Patch openshift resource with change
+
+ Args:
+ ocp_node (str): Node on which the ocp command will run.
+ rtype (str): Name of the resource type (pod, storageClass, etc).
+ rname (str): Name of the resource to fetch.
+ changes (dict): Changes to be applied through patch.
+ raise_on_error (bool): If set to true a failure to patch
+ resource with changes will raise an error, otherwise
+ an None will be returned.
+ Returns:
+ str : output of oc patch command
+ Raises:
+ exceptions.ExecutionError: Raise when invalid json is provided.
+ AssertionError: Raised when unable to patch resource and
+ 'raise_on_error' is true.
+ """
+ try:
+ changes = json.dumps(changes)
+ except TypeError:
+ raise exceptions.ExecutionError(
+ "Json %s is not serializable to string")
+
+ cmd = ['oc', 'patch', rtype, rname, '-p', '\'%s\'' % changes]
+ out = command.cmd_run(
+ cmd, hostname=ocp_node, raise_on_error=raise_on_error)
+ return out or None